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

152 lines
4.4 KiB
Vue
Raw Normal View History

<template>
<fs-page class="page-sys-settings">
<template #header>
<div class="title">系统设置</div>
</template>
<div class="sys-settings-form settings-form">
<a-form
:model="formState"
name="basic"
:label-col="{ span: 8 }"
:wrapper-col="{ span: 16 }"
autocomplete="off"
@finish="onFinish"
@finish-failed="onFinishFailed"
>
2024-10-12 16:49:49 +08:00
<a-form-item label="开启自助注册" :name="['public', 'registerEnabled']">
<a-switch v-model:checked="formState.public.registerEnabled" />
</a-form-item>
2024-10-26 23:54:49 +08:00
<a-form-item label="限制用户流水线数量" :name="['public', 'limitUserPipelineCount']">
<a-input-number v-model:value="formState.public.limitUserPipelineCount" />
<div class="helper">0为不限制</div>
</a-form-item>
2024-10-12 16:49:49 +08:00
<a-form-item label="管理其他用户流水线" :name="['public', 'managerOtherUserPipeline']">
<a-switch v-model:checked="formState.public.managerOtherUserPipeline" />
</a-form-item>
2024-10-12 16:49:49 +08:00
<a-form-item label="ICP备案号" :name="['public', 'icpNo']">
<a-input v-model:value="formState.public.icpNo" placeholder="粤ICP备xxxxxxx号" />
</a-form-item>
<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/" />
2024-10-26 23:56:13 +08:00
<div class="helper">当某些网站被墙时可以配置</div>
2024-10-12 16:49:49 +08:00
</a-form-item>
<a-form-item label="HTTPS代理" :name="['private', 'httpsProxy']" :rules="urlRules">
2024-10-12 18:30:40 +08:00
<div class="flex">
<a-input v-model:value="formState.private.httpsProxy" placeholder="http://192.168.1.2:18010/" />
2024-10-26 23:54:49 +08:00
<a-button class="ml-5" type="primary" :loading="testProxyLoading" title="保存后,再点击测试" @click="testProxy">测试</a-button>
2024-10-12 18:30:40 +08:00
</div>
2024-10-12 16:49:49 +08:00
<div class="helper">一般这两个代理填一样的</div>
</a-form-item>
<a-form-item :wrapper-col="{ offset: 8, span: 16 }">
2024-10-05 01:46:25 +08:00
<a-button :loading="saveLoading" type="primary" html-type="submit">保存</a-button>
</a-form-item>
</a-form>
</div>
</fs-page>
</template>
2024-11-13 22:42:11 +08:00
<script setup lang="tsx">
2024-10-05 01:46:25 +08:00
import { reactive, ref } from "vue";
import * as api from "./api";
2024-10-12 16:49:49 +08:00
import { SysSettings } from "./api";
import { notification } from "ant-design-vue";
import { useSettingStore } from "/@/store/modules/settings";
2024-10-12 16:49:49 +08:00
import { merge } from "lodash-es";
2024-11-13 22:42:11 +08:00
import { util } from "/@/utils";
defineOptions({
name: "SysSettings"
});
2024-10-12 16:49:49 +08:00
const formState = reactive<Partial<SysSettings>>({
public: {
registerEnabled: false,
2024-10-26 23:54:49 +08:00
limitUserPipelineCount: 0,
2024-10-12 16:49:49 +08:00
managerOtherUserPipeline: false,
icpNo: ""
},
private: {}
});
2024-10-12 16:49:49 +08:00
const urlRules = ref({
type: "url",
message: "请输入正确的URL"
});
2024-10-12 16:49:49 +08:00
async function loadSysSettings() {
const data: any = await api.SysSettingsGet();
merge(formState, data);
}
2024-10-05 01:46:25 +08:00
const saveLoading = ref(false);
2024-10-12 16:49:49 +08:00
loadSysSettings();
const settingsStore = useSettingStore();
const onFinish = async (form: any) => {
2024-10-05 01:46:25 +08:00
try {
saveLoading.value = true;
2024-10-12 16:49:49 +08:00
await api.SysSettingsSave(form);
2024-10-05 01:46:25 +08:00
await settingsStore.loadSysSettings();
notification.success({
message: "保存成功"
});
} finally {
saveLoading.value = false;
}
};
const onFinishFailed = (errorInfo: any) => {
// console.log("Failed:", errorInfo);
};
async function stopOtherUserTimer() {
await api.stopOtherUserTimer();
notification.success({
message: "停止成功"
});
}
2024-10-12 18:30:40 +08:00
2024-10-26 23:54:49 +08:00
const testProxyLoading = ref(false);
2024-10-12 18:30:40 +08:00
async function testProxy() {
2024-10-26 23:54:49 +08:00
testProxyLoading.value = true;
try {
const res = await api.TestProxy();
2024-11-13 22:42:11 +08:00
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: "测试失败",
description: content
});
return;
}
2024-10-26 23:54:49 +08:00
notification.success({
message: "测试完成",
description: content
});
} finally {
testProxyLoading.value = false;
}
2024-10-12 18:30:40 +08:00
}
</script>
<style lang="less">
.page-sys-settings {
.sys-settings-form {
width: 500px;
margin: 20px;
}
}
</style>