Files
fe.ems.vue3/src/views/system/setting/components/change-home-index.vue
2024-10-16 14:50:47 +08:00

105 lines
2.8 KiB
Vue

<script lang="ts" setup>
import { Modal, message } from 'ant-design-vue/lib';
import { onMounted, reactive, toRaw } from 'vue';
import useAppStore from '@/store/modules/app';
import useI18n from '@/hooks/useI18n';
import { listMenu } from '@/api/system/menu';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import { getConfig, getConfigKey, changeValue } from '@/api/system/config';
const appStore = useAppStore();
const { t, optionsLocale } = useI18n();
type StateType = {
edite: boolean;
loading: boolean;
open: boolean;
default: any;
options: any;
};
let state: StateType = reactive({
edite: false,
loading: false,
open: false,
default: '',
options: [],
});
/**提交保存 */
function fnSave() {
Modal.confirm({
title: t('common.tipTitle'),
content: t('views.system.setting.homeTip'),
onOk() {
// 发送请求
const hide = message.loading(t('common.loading'), 0);
state.loading = true;
changeValue({ key: 'sys.homePage', value: state.default })
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success(t('views.system.setting.saveSuccess'), 3);
} else {
message.error(res.msg, 3);
}
})
.finally(() => {
state.loading = false;
hide();
});
},
});
}
onMounted(() => {
listMenu(toRaw({ status: 1 })).then(res => {
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
// 过滤旧前端菜单以及不是菜单类型以及路径为空
res.data = res.data
.filter(i => i.perms !== 'page' && i.menuType === 'M' && i.component)
.map((item: any) => {
state.options.push({
label: item.menuName,
value: item.component,
});
});
}
});
//获取当前系统设置的首页路径 111为configID
getConfigKey('sys.homePage').then(res => {
if (res.code === RESULT_CODE_SUCCESS && res.data) {
state.default = res.data;
}
});
});
</script>
<template>
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24" style="margin-bottom: 30px">
<a-form-item :label="t('views.system.setting.home')">
<a-select
ref="select"
v-model:value="state.default"
style="width: 240px"
:options="state.options"
></a-select>
</a-form-item>
<a-button type="primary" @click="fnSave">
{{ t('views.system.setting.saveSubmit') }}
</a-button>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-typography>
<a-typography-paragraph>
{{ t('views.system.setting.homeInstruction') }}
</a-typography-paragraph>
</a-typography>
</a-col>
</a-row>
</template>
<style lang="less" scoped></style>