2022-09-15 10:44:43 +08:00
|
|
|
<template>
|
|
|
|
<div class="demo-collapse">
|
|
|
|
<el-card class="topCard">
|
|
|
|
<el-radio-group v-model="activeNames">
|
|
|
|
<el-radio-button class="topButton" size="large" label="all">全部</el-radio-button>
|
2022-09-09 17:17:02 +08:00
|
|
|
<el-radio-button class="topButton" size="large" label="panel">面板</el-radio-button>
|
|
|
|
<el-radio-button class="topButton" size="large" label="safe">安全</el-radio-button>
|
|
|
|
<el-radio-button class="topButton" size="large" label="backup">备份</el-radio-button>
|
|
|
|
<el-radio-button class="topButton" size="large" label="monitor">监控</el-radio-button>
|
2022-09-15 10:44:43 +08:00
|
|
|
<el-radio-button class="topButton" size="large" label="about">关于</el-radio-button>
|
|
|
|
</el-radio-group>
|
|
|
|
</el-card>
|
2022-09-16 16:00:49 +08:00
|
|
|
<Panel v-if="activeNames === 'all' || activeNames === 'panel'" :settingInfo="form" @on-save="SaveSetting" />
|
|
|
|
<Safe v-if="activeNames === 'all' || activeNames === 'safe'" :settingInfo="form" @on-save="SaveSetting" />
|
|
|
|
<Backup v-if="activeNames === 'all' || activeNames === 'backup'" :settingInfo="form" @on-save="SaveSetting" />
|
|
|
|
<Monitor v-if="activeNames === 'all' || activeNames === 'monitor'" :settingInfo="form" @on-save="SaveSetting" />
|
2022-09-15 10:44:43 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2022-09-16 16:00:49 +08:00
|
|
|
import { ref, onMounted, computed } from 'vue';
|
|
|
|
import { getSettingInfo, updateSetting } from '@/api/modules/setting';
|
2022-09-15 10:44:43 +08:00
|
|
|
import { Setting } from '@/api/interface/setting';
|
2022-09-09 17:17:02 +08:00
|
|
|
import Panel from '@/views/setting/tabs/panel.vue';
|
|
|
|
import Safe from '@/views/setting/tabs/safe.vue';
|
|
|
|
import Backup from '@/views/setting/tabs/backup.vue';
|
|
|
|
import Monitor from '@/views/setting/tabs/monitor.vue';
|
2022-09-16 16:00:49 +08:00
|
|
|
import { GlobalStore } from '@/store';
|
|
|
|
import { useTheme } from '@/hooks/use-theme';
|
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
import { ElMessage, FormInstance } from 'element-plus';
|
|
|
|
|
|
|
|
const i18n = useI18n();
|
|
|
|
const globalStore = GlobalStore();
|
|
|
|
const themeConfig = computed(() => globalStore.themeConfig);
|
2022-09-15 10:44:43 +08:00
|
|
|
|
|
|
|
const activeNames = ref('all');
|
2022-09-09 17:17:02 +08:00
|
|
|
let form = ref<Setting.SettingInfo>({
|
2022-09-15 10:44:43 +08:00
|
|
|
userName: '',
|
|
|
|
password: '',
|
|
|
|
email: '',
|
2022-09-16 16:00:49 +08:00
|
|
|
sessionTimeout: 86400,
|
2022-09-09 17:17:02 +08:00
|
|
|
localTime: '',
|
2022-09-15 10:44:43 +08:00
|
|
|
panelName: '',
|
|
|
|
theme: '',
|
|
|
|
language: '',
|
2022-09-16 16:00:49 +08:00
|
|
|
serverPort: 8888,
|
2022-09-15 10:44:43 +08:00
|
|
|
securityEntrance: '',
|
2022-09-09 17:17:02 +08:00
|
|
|
passwordTimeOut: '',
|
2022-09-15 10:44:43 +08:00
|
|
|
complexityVerification: '',
|
|
|
|
mfaStatus: '',
|
2022-09-16 16:00:49 +08:00
|
|
|
mfaSecret: '',
|
2022-09-15 10:44:43 +08:00
|
|
|
monitorStatus: '',
|
2022-09-16 16:00:49 +08:00
|
|
|
monitorStoreDays: 30,
|
2022-09-15 10:44:43 +08:00
|
|
|
messageType: '',
|
|
|
|
emailVars: '',
|
|
|
|
weChatVars: '',
|
|
|
|
dingVars: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
const search = async () => {
|
|
|
|
const res = await getSettingInfo();
|
2022-09-09 17:17:02 +08:00
|
|
|
form.value = res.data;
|
|
|
|
form.value.password = '******';
|
2022-09-15 10:44:43 +08:00
|
|
|
};
|
2022-09-09 17:17:02 +08:00
|
|
|
|
2022-09-16 16:00:49 +08:00
|
|
|
const { switchDark } = useTheme();
|
|
|
|
|
|
|
|
const SaveSetting = async (formEl: FormInstance | undefined, key: string, val: any) => {
|
|
|
|
if (!formEl) return;
|
|
|
|
const result = await formEl.validateField('settingInfo.' + key.replace(key[0], key[0].toLowerCase()), callback);
|
|
|
|
if (!result) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (val === '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (key) {
|
|
|
|
case 'Language':
|
|
|
|
i18n.locale.value = val;
|
|
|
|
globalStore.updateLanguage(val);
|
|
|
|
break;
|
|
|
|
case 'Theme':
|
|
|
|
globalStore.setThemeConfig({ ...themeConfig.value, theme: val });
|
|
|
|
switchDark();
|
|
|
|
break;
|
|
|
|
case 'PanelName':
|
|
|
|
globalStore.setThemeConfig({ ...themeConfig.value, panelName: val });
|
|
|
|
break;
|
|
|
|
case 'SessionTimeout':
|
|
|
|
case 'MonitorStoreDays':
|
|
|
|
case 'ServerPort':
|
|
|
|
val = val + '';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
let param = {
|
|
|
|
key: key,
|
|
|
|
value: val,
|
|
|
|
};
|
|
|
|
await updateSetting(param);
|
|
|
|
ElMessage.success(i18n.t('commons.msg.operationSuccess'));
|
|
|
|
search();
|
|
|
|
};
|
|
|
|
|
|
|
|
function callback(error: any) {
|
|
|
|
if (error) {
|
|
|
|
return error.message;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-15 10:44:43 +08:00
|
|
|
onMounted(() => {
|
|
|
|
search();
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.topCard {
|
|
|
|
--el-card-border-color: var(--el-border-color-light);
|
|
|
|
--el-card-border-radius: 4px;
|
|
|
|
--el-card-padding: 0px;
|
|
|
|
--el-card-bg-color: var(--el-fill-color-blank);
|
|
|
|
}
|
|
|
|
.topButton .el-radio-button__inner {
|
|
|
|
display: inline-block;
|
|
|
|
line-height: 1;
|
|
|
|
white-space: nowrap;
|
|
|
|
vertical-align: middle;
|
|
|
|
background: var(--el-button-bg-color, var(--el-fill-color-blank));
|
|
|
|
border: 0;
|
|
|
|
font-weight: 350;
|
|
|
|
border-left: 0;
|
|
|
|
color: var(--el-button-text-color, var(--el-text-color-regular));
|
|
|
|
text-align: center;
|
|
|
|
box-sizing: border-box;
|
|
|
|
outline: 0;
|
|
|
|
margin: 0;
|
|
|
|
position: relative;
|
|
|
|
cursor: pointer;
|
|
|
|
transition: var(--el-transition-all);
|
|
|
|
-webkit-user-select: none;
|
|
|
|
user-select: none;
|
|
|
|
padding: 8px 15px;
|
|
|
|
font-size: var(--el-font-size-base);
|
|
|
|
border-radius: 0;
|
|
|
|
}
|
|
|
|
</style>
|