fix: 系统设置更换主页页面选择死循环问题

This commit is contained in:
TsMask
2025-02-26 17:48:42 +08:00
parent dd54b10f4d
commit d88a3e7e25

View File

@@ -6,14 +6,15 @@ import { listMenu } from '@/api/system/menu';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import { getConfigKey, changeValue } from '@/api/system/config'; import { getConfigKey, changeValue } from '@/api/system/config';
import { parseDataToTree } from '@/utils/parse-tree-utils'; import { parseDataToTree } from '@/utils/parse-tree-utils';
import { MENU_TYPE_BUTTON } from '@/constants/menu-constants';
const { t } = useI18n(); const { t } = useI18n();
type StateType = { type StateType = {
edite: boolean; edite: boolean;
loading: boolean; loading: boolean;
open: boolean; open: boolean;
default: any; default: string;
options: any; options: any[];
}; };
let state: StateType = reactive({ let state: StateType = reactive({
@@ -57,22 +58,42 @@ function fnEdit(v: boolean) {
} }
onMounted(() => { onMounted(() => {
listMenu(toRaw({ status: 1 })).then(res => { listMenu(toRaw({ statusFlag: '1', visibleFlag: '0' })).then(res => {
if (res.code === RESULT_CODE_SUCCESS) { if (res.code === RESULT_CODE_SUCCESS) {
state.options = parseDataToTree(res.data, 'menuId'); const data: any[] = [];
const setDisabledAndComponent = (item:any) => { const randD = (item: any) => {
if (!item.component) { if (item.menuType == MENU_TYPE_BUTTON) {
item.disabled = true; return undefined;
item.component = 'Null' + item.menuId;
} }
}; const tmp: any = {
label: item.menuName,
value: item.component || item.menuPath,
disabled: !item.component,
};
state.options.forEach((item:any) => { const children: any = [];
setDisabledAndComponent(item); // 处理父菜单 if (Array.isArray(item.children) && item.children.length > 0) {
if (item.children && Array.isArray(item.children)) { for (const child of item.children) {
item.children.forEach(setDisabledAndComponent); // 处理子菜单 const v = randD(child);
if (v) {
children.push(v);
}
}
} }
}); if (children.length > 0) {
tmp.children = children;
}
return tmp;
};
const arr = parseDataToTree(res.data, 'menuId');
for (const v of arr) {
const item = randD(v);
if (item) {
data.push(item);
}
}
Object.assign(state.options, data);
} }
}); });
@@ -95,14 +116,7 @@ onMounted(() => {
show-search show-search
style="width: 240px" style="width: 240px"
:tree-data="state.options" :tree-data="state.options"
:field-names="{
children: 'children',
label: 'menuName',
value: 'component',
}"
tree-default-expand-all tree-default-expand-all
tree-node-label-prop="menuName"
tree-node-filter-prop="menuName"
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }" :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
:placeholder="t('common.selectPlease')" :placeholder="t('common.selectPlease')"
></a-tree-select> ></a-tree-select>
@@ -120,17 +134,8 @@ onMounted(() => {
<a-tree-select <a-tree-select
v-model:value="state.default" v-model:value="state.default"
:disabled="true" :disabled="true"
show-search
style="width: 240px" style="width: 240px"
:tree-data="state.options" :tree-data="state.options"
:field-names="{
children: 'children',
label: 'menuName',
value: 'component',
}"
tree-default-expand-all
tree-node-label-prop="menuName"
tree-node-filter-prop="menuName"
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }" :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
:placeholder="t('common.selectPlease')" :placeholder="t('common.selectPlease')"
></a-tree-select> ></a-tree-select>