fix: 系统设置更换主页页面选择死循环问题
This commit is contained in:
@@ -6,14 +6,15 @@ import { listMenu } from '@/api/system/menu';
|
||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||
import { getConfigKey, changeValue } from '@/api/system/config';
|
||||
import { parseDataToTree } from '@/utils/parse-tree-utils';
|
||||
import { MENU_TYPE_BUTTON } from '@/constants/menu-constants';
|
||||
const { t } = useI18n();
|
||||
|
||||
type StateType = {
|
||||
edite: boolean;
|
||||
loading: boolean;
|
||||
open: boolean;
|
||||
default: any;
|
||||
options: any;
|
||||
default: string;
|
||||
options: any[];
|
||||
};
|
||||
|
||||
let state: StateType = reactive({
|
||||
@@ -57,22 +58,42 @@ function fnEdit(v: boolean) {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
listMenu(toRaw({ status: 1 })).then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
state.options = parseDataToTree(res.data, 'menuId');
|
||||
const setDisabledAndComponent = (item:any) => {
|
||||
if (!item.component) {
|
||||
item.disabled = true;
|
||||
item.component = 'Null' + item.menuId;
|
||||
listMenu(toRaw({ statusFlag: '1', visibleFlag: '0' })).then(res => {
|
||||
if (res.code === RESULT_CODE_SUCCESS) {
|
||||
const data: any[] = [];
|
||||
const randD = (item: any) => {
|
||||
if (item.menuType == MENU_TYPE_BUTTON) {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
const tmp: any = {
|
||||
label: item.menuName,
|
||||
value: item.component || item.menuPath,
|
||||
disabled: !item.component,
|
||||
};
|
||||
|
||||
state.options.forEach((item:any) => {
|
||||
setDisabledAndComponent(item); // 处理父菜单
|
||||
if (item.children && Array.isArray(item.children)) {
|
||||
item.children.forEach(setDisabledAndComponent); // 处理子菜单
|
||||
const children: any = [];
|
||||
if (Array.isArray(item.children) && item.children.length > 0) {
|
||||
for (const child of item.children) {
|
||||
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
|
||||
style="width: 240px"
|
||||
: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' }"
|
||||
:placeholder="t('common.selectPlease')"
|
||||
></a-tree-select>
|
||||
@@ -120,17 +134,8 @@ onMounted(() => {
|
||||
<a-tree-select
|
||||
v-model:value="state.default"
|
||||
:disabled="true"
|
||||
show-search
|
||||
style="width: 240px"
|
||||
: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' }"
|
||||
:placeholder="t('common.selectPlease')"
|
||||
></a-tree-select>
|
||||
|
||||
Reference in New Issue
Block a user