优化多级菜单,路由注册
parent
63867b31a9
commit
23c0a4437e
|
|
@ -168,6 +168,53 @@ export const usePermissionStore = defineStore({
|
||||||
}
|
}
|
||||||
return newPath;
|
return newPath;
|
||||||
};
|
};
|
||||||
|
const childRoute = (childData) => {
|
||||||
|
const modules = import.meta.glob('../../views/**/**/**/index.vue');
|
||||||
|
childData.forEach((element) => {
|
||||||
|
// 菜单里配置带参数,但没有单独的主路由,先注册主路由
|
||||||
|
if (element.item.status == 1 && element.item.url.indexOf('@') > 0) {
|
||||||
|
const path = element.item.url.substring(0, element.item.url.indexOf('@'));
|
||||||
|
router.addRoute('Root', {
|
||||||
|
path: path,
|
||||||
|
name: element.item.code,
|
||||||
|
meta: {
|
||||||
|
title: element.item.name,
|
||||||
|
icon: element.item.iconName,
|
||||||
|
hideChildrenInMenu: true,
|
||||||
|
elements: element.item.elements,
|
||||||
|
},
|
||||||
|
component: LAYOUT,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: path + '/:id',
|
||||||
|
name: element.item.url.replaceAll('/', ''),
|
||||||
|
meta: {
|
||||||
|
title: element.item.name,
|
||||||
|
icon: element.item.iconName,
|
||||||
|
elements: element.item.elements,
|
||||||
|
},
|
||||||
|
component: modules['../../views/demo' + path + '/index.vue'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
} else if (element.item.code && element.item.status == 1) {
|
||||||
|
router.addRoute(element.item.code, {
|
||||||
|
path: element.item.url,
|
||||||
|
name: element.item.url.replaceAll('/', ''),
|
||||||
|
meta: {
|
||||||
|
title: element.item.name,
|
||||||
|
icon: element.item.iconName,
|
||||||
|
elements: element.item.elements,
|
||||||
|
},
|
||||||
|
// component: () => import('../../views/demo' + element.item.url + '/index.vue')
|
||||||
|
component: modules['../../views/demo' + element.item.url + '/index.vue'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (element.children && element.children.length > 0) {
|
||||||
|
childRoute(element.children);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
// 注册路由
|
// 注册路由
|
||||||
const registeredRoute = (data) => {
|
const registeredRoute = (data) => {
|
||||||
const modules = import.meta.glob('../../views/**/**/**/index.vue');
|
const modules = import.meta.glob('../../views/**/**/**/index.vue');
|
||||||
|
|
@ -185,7 +232,7 @@ export const usePermissionStore = defineStore({
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 正常菜单
|
// 正常菜单
|
||||||
if (data.children.length == 0 && data.item.parentId == 0 && data.item.status == 1) {
|
if (data.children.length == 0 && data.item.status == 1) {
|
||||||
// 没有子菜单
|
// 没有子菜单
|
||||||
if (data.item.url.indexOf('@') > 0) {
|
if (data.item.url.indexOf('@') > 0) {
|
||||||
//给带参数的路由先注册主路由
|
//给带参数的路由先注册主路由
|
||||||
|
|
@ -257,51 +304,11 @@ export const usePermissionStore = defineStore({
|
||||||
: modules['../../views/demo' + data.item.url + '/index.vue'],
|
: modules['../../views/demo' + data.item.url + '/index.vue'],
|
||||||
});
|
});
|
||||||
if (data.children && data.children.length > 0) {
|
if (data.children && data.children.length > 0) {
|
||||||
data.children.forEach((element) => {
|
childRoute(data.children);
|
||||||
// 菜单里配置带参数,但没有单独的主路由,先注册主路由
|
|
||||||
if (element.item.status == 1 && element.item.url.indexOf('@') > 0) {
|
|
||||||
const path = element.item.url.substring(0, element.item.url.indexOf('@'));
|
|
||||||
router.addRoute('Root', {
|
|
||||||
path: path,
|
|
||||||
name: element.item.code,
|
|
||||||
meta: {
|
|
||||||
title: element.item.name,
|
|
||||||
icon: element.item.iconName,
|
|
||||||
hideChildrenInMenu: true,
|
|
||||||
elements: element.item.elements,
|
|
||||||
},
|
|
||||||
component: LAYOUT,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: path + '/:id',
|
|
||||||
name: element.item.url.replaceAll('/', ''),
|
|
||||||
meta: {
|
|
||||||
title: element.item.name,
|
|
||||||
icon: element.item.iconName,
|
|
||||||
elements: element.item.elements,
|
|
||||||
},
|
|
||||||
component: modules['../../views/demo' + path + '/index.vue'],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
} else if (element.item.code && element.item.status == 1) {
|
|
||||||
router.addRoute(element.item.code, {
|
|
||||||
path: element.item.url,
|
|
||||||
name: element.item.url.replaceAll('/', ''),
|
|
||||||
meta: {
|
|
||||||
title: element.item.name,
|
|
||||||
icon: element.item.iconName,
|
|
||||||
elements: element.item.elements,
|
|
||||||
},
|
|
||||||
// component: () => import('../../views/demo' + element.item.url + '/index.vue')
|
|
||||||
component: modules['../../views/demo' + element.item.url + '/index.vue'],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.log(router.getRoutes())
|
// console.log(router.getRoutes());
|
||||||
};
|
};
|
||||||
|
|
||||||
//通过后端获取菜单
|
//通过后端获取菜单
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@
|
||||||
const processId = ref('');
|
const processId = ref('');
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
// searchInfo.category = route.query.category;
|
// searchInfo.category = route.query.category;
|
||||||
searchInfo.category = route.params?.id;
|
searchInfo.category = route.params?.id == 'all' ? '' : route.params?.id;
|
||||||
|
|
||||||
const [registerTable, { reload }] = useTable({
|
const [registerTable, { reload }] = useTable({
|
||||||
api: getLoadMyCompletedPage,
|
api: getLoadMyCompletedPage,
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@
|
||||||
const childRecord = ref();
|
const childRecord = ref();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
// searchInfo.category = route.query.category;
|
// searchInfo.category = route.query.category;
|
||||||
searchInfo.category = route.params?.id;
|
searchInfo.category = route.params?.id == 'all' ? '' : route.params?.id;
|
||||||
const [registerTable, { reload }] = useTable({
|
const [registerTable, { reload }] = useTable({
|
||||||
api: getLoadMyUncompletedPage,
|
api: getLoadMyUncompletedPage,
|
||||||
columns: [
|
columns: [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue