首页菜单选择框为树状选择框
This commit is contained in:
@@ -5,6 +5,7 @@ import useI18n from '@/hooks/useI18n';
|
|||||||
import { listMenu } from '@/api/system/menu';
|
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';
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
type StateType = {
|
type StateType = {
|
||||||
@@ -59,14 +60,21 @@ onMounted(() => {
|
|||||||
listMenu(toRaw({ status: 1 })).then(res => {
|
listMenu(toRaw({ status: 1 })).then(res => {
|
||||||
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
|
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
|
||||||
// 过滤旧前端菜单以及不是菜单类型以及路径为空
|
// 过滤旧前端菜单以及不是菜单类型以及路径为空
|
||||||
res.data = res.data
|
res.data = res.data.filter(i => i.perms !== 'page' && i.menuType !== 'B');
|
||||||
.filter(i => i.perms !== 'page' && i.menuType === 'M' && i.component)
|
state.options = parseDataToTree(res.data, 'menuId');
|
||||||
.map((item: any) => {
|
const setDisabledAndComponent = (item:any) => {
|
||||||
state.options.push({
|
if (!item.component) {
|
||||||
label: item.menuName,
|
item.disabled = true;
|
||||||
value: item.component,
|
item.component = 'Null' + item.menuId;
|
||||||
});
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
state.options.forEach((item:any) => {
|
||||||
|
setDisabledAndComponent(item); // 处理父菜单
|
||||||
|
if (item.children && Array.isArray(item.children)) {
|
||||||
|
item.children.forEach(setDisabledAndComponent); // 处理子菜单
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -84,13 +92,22 @@ onMounted(() => {
|
|||||||
<a-col :lg="12" :md="12" :xs="24" style="margin-bottom: 30px">
|
<a-col :lg="12" :md="12" :xs="24" style="margin-bottom: 30px">
|
||||||
<template v-if="state.edite">
|
<template v-if="state.edite">
|
||||||
<a-form-item :label="t('views.system.setting.home')">
|
<a-form-item :label="t('views.system.setting.home')">
|
||||||
<a-select
|
<a-tree-select
|
||||||
ref="select"
|
|
||||||
v-model:value="state.default"
|
v-model:value="state.default"
|
||||||
|
show-search
|
||||||
style="width: 240px"
|
style="width: 240px"
|
||||||
:disabled="false"
|
:tree-data="state.options"
|
||||||
:options="state.options"
|
:field-names="{
|
||||||
></a-select>
|
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>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-button type="primary" @click="fnSave">
|
<a-button type="primary" @click="fnSave">
|
||||||
@@ -102,13 +119,23 @@ onMounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<a-form-item :label="t('views.system.setting.home')">
|
<a-form-item :label="t('views.system.setting.home')">
|
||||||
<a-select
|
<a-tree-select
|
||||||
ref="select"
|
|
||||||
v-model:value="state.default"
|
v-model:value="state.default"
|
||||||
style="width: 240px"
|
|
||||||
:disabled="true"
|
:disabled="true"
|
||||||
:options="state.options"
|
show-search
|
||||||
></a-select>
|
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>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-button type="dashed" @click="fnEdit(true)">
|
<a-button type="dashed" @click="fnEdit(true)">
|
||||||
|
|||||||
Reference in New Issue
Block a user