Files
certd/packages/ui/certd-client/src/views/sys/settings/tabs/base.vue
T

147 lines
4.9 KiB
Vue
Raw Normal View History

2024-11-28 17:36:45 +08:00
<template>
<div class="sys-settings-form sys-settings-base">
2025-03-11 22:25:14 +08:00
<a-form :model="formState" name="basic" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" autocomplete="off" @finish="onFinish" @finish-failed="onFinishFailed">
2024-11-28 17:36:45 +08:00
<a-form-item label="ICP备案号" :name="['public', 'icpNo']">
<a-input v-model:value="formState.public.icpNo" placeholder="粤ICP备xxxxxxx号" />
</a-form-item>
2025-05-10 21:31:32 +08:00
<a-form-item label="网安备案号" :name="['public', 'mpsNo']">
<a-input v-model:value="formState.public.mpsNo" placeholder="京公网安备xxxxxxx号" />
</a-form-item>
2025-05-15 23:06:22 +08:00
<a-form-item label="开启小助手" :name="['public', 'aiChatEnabled']">
<a-switch v-model:checked="formState.public.aiChatEnabled" />
</a-form-item>
<a-form-item label="允许爬虫" :name="['public', 'robots']">
<a-switch v-model:checked="formState.public.robots" />
</a-form-item>
2024-11-28 17:36:45 +08:00
<a-form-item label="HTTP代理" :name="['private', 'httpProxy']" :rules="urlRules">
<a-input v-model:value="formState.private.httpProxy" placeholder="http://192.168.1.2:18010/" />
<div class="helper">当某些网站被墙时可以配置</div>
</a-form-item>
<a-form-item label="HTTPS代理" :name="['private', 'httpsProxy']" :rules="urlRules">
<div class="flex">
<a-input v-model:value="formState.private.httpsProxy" placeholder="http://192.168.1.2:18010/" />
<a-button class="ml-5" type="primary" :loading="testProxyLoading" title="保存后,再点击测试" @click="testProxy">测试</a-button>
</div>
<div class="helper">一般这两个代理填一样的保存后再测试</div>
</a-form-item>
<a-form-item label="双栈网络" :name="['private', 'dnsResultOrder']">
<a-select v-model:value="formState.private.dnsResultOrder">
<a-select-option value="verbatim">默认</a-select-option>
<a-select-option value="ipv4first">IPV4优先</a-select-option>
<a-select-option value="ipv6first">IPV6优先</a-select-option>
</a-select>
<div class="helper">如果选择IPv6优先需要在docker-compose.yaml中启用ipv6</div>
</a-form-item>
<a-form-item label="启用公共CNAME服务" :name="['private', 'commonCnameEnabled']">
<a-switch v-model:checked="formState.private.commonCnameEnabled" />
2025-03-11 22:25:14 +08:00
<div class="helper">是否可以使用公共CNAME服务如果禁用且没有设置<router-link to="/sys/cname/provider">自定义CNAME服务</router-link>则无法使用CNAME代理方式申请证书</div>
2024-11-28 17:36:45 +08:00
</a-form-item>
2025-03-11 22:25:14 +08:00
<a-form-item label=" " :colon="false" :wrapper-col="{ span: 8 }">
2024-11-28 17:36:45 +08:00
<a-button :loading="saveLoading" type="primary" html-type="submit">保存</a-button>
</a-form-item>
</a-form>
</div>
</template>
<script setup lang="tsx">
import { reactive, ref } from "vue";
import { SysSettings } from "/@/views/sys/settings/api";
import * as api from "/@/views/sys/settings/api";
import { merge } from "lodash-es";
2025-04-12 23:59:03 +08:00
import { useSettingStore } from "/@/store/settings";
2024-11-28 17:36:45 +08:00
import { notification } from "ant-design-vue";
import { util } from "/@/utils";
defineOptions({
2025-05-10 21:31:32 +08:00
name: "SettingBase",
2024-11-28 17:36:45 +08:00
});
const formState = reactive<Partial<SysSettings>>({
public: {
2025-05-10 21:31:32 +08:00
icpNo: "",
mpsNo: "",
2024-11-28 17:36:45 +08:00
},
2025-05-10 21:31:32 +08:00
private: {},
2024-11-28 17:36:45 +08:00
});
const urlRules = ref({
type: "url",
2025-05-10 21:31:32 +08:00
message: "请输入正确的URL",
2024-11-28 17:36:45 +08:00
});
async function loadSysSettings() {
const data: any = await api.SysSettingsGet();
merge(formState, data);
}
const saveLoading = ref(false);
loadSysSettings();
const settingsStore = useSettingStore();
const onFinish = async (form: any) => {
try {
saveLoading.value = true;
await api.SysSettingsSave(form);
await settingsStore.loadSysSettings();
notification.success({
2025-05-10 21:31:32 +08:00
message: "保存成功",
2024-11-28 17:36:45 +08:00
});
} finally {
saveLoading.value = false;
}
};
const onFinishFailed = (errorInfo: any) => {
// console.log("Failed:", errorInfo);
};
async function stopOtherUserTimer() {
await api.stopOtherUserTimer();
notification.success({
2025-05-10 21:31:32 +08:00
message: "停止成功",
2024-11-28 17:36:45 +08:00
});
}
const testProxyLoading = ref(false);
async function testProxy() {
testProxyLoading.value = true;
try {
const res = await api.TestProxy();
let success = true;
if (res.google !== true || res.baidu !== true) {
success = false;
}
const content = () => {
return (
<div>
<div>Google: {res.google === true ? "成功" : util.maxLength(res.google)}</div>
<div>Baidu: {res.baidu === true ? "成功" : util.maxLength(res.google)}</div>
</div>
);
};
if (!success) {
notification.error({
message: "测试失败",
2025-05-10 21:31:32 +08:00
description: content,
2024-11-28 17:36:45 +08:00
});
return;
}
notification.success({
message: "测试完成",
2025-05-10 21:31:32 +08:00
description: content,
2024-11-28 17:36:45 +08:00
});
} finally {
testProxyLoading.value = false;
}
}
</script>
<style lang="less">
.sys-settings-base {
}
</style>