菜单动态路由及头部角色切换修改
This commit is contained in:
98
hx-ai-intelligent/src/util/dynamicRoutes.ts
Normal file
98
hx-ai-intelligent/src/util/dynamicRoutes.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
/***公共方法==>处理动态路由数据 将“按钮”部分的数据追加到meta中*/
|
||||
//处理路由按钮,存放在meta中
|
||||
export const replyRoutesButton = (data:any) => {
|
||||
if(!data) return;
|
||||
return data.map(item => {
|
||||
if(item.children && item.children.length > 0){
|
||||
item.meta.operates = [];
|
||||
item.children.map(itemChild => {
|
||||
if(itemChild.type=="3"){
|
||||
let operateObj = {title:'',code:''};
|
||||
operateObj.title = itemChild.meta.title;
|
||||
operateObj.code = itemChild.name;
|
||||
item.meta.operates.push(operateObj);
|
||||
item.children = item.children.filter(its => its.name != itemChild.name);
|
||||
}
|
||||
})
|
||||
if(item.meta.operates.length == 0){
|
||||
delete item.meta.operates;
|
||||
}
|
||||
return {
|
||||
...item,
|
||||
children: replyRoutesButton(item.children),
|
||||
};
|
||||
}
|
||||
|
||||
return item;
|
||||
});
|
||||
};
|
||||
// //处理路由compontent路径
|
||||
// export const replyRoutesPath = (itemRouter:any) => {
|
||||
// if (itemRouter.children && itemRouter.children.length > 0) {
|
||||
// itemRouter.children.forEach(childRoute => {
|
||||
// const modulePath0 = childRoute.component;
|
||||
// // 修改 component 属性
|
||||
// // childRoute.component = () => import(`/nerv-lib/saas/view/${modulePath0}`).then(mod => mod.default);
|
||||
// childRoute.component = () => new Function(`return import('/nerv-lib/saas/view/${modulePath0}')`)();
|
||||
|
||||
// if (childRoute.children && childRoute.children.length > 0) {
|
||||
// childRoute.children.forEach(child2 => {
|
||||
// const modulePath = child2.component;
|
||||
// // 修改 component 属性
|
||||
// // child2.component = /* @vite-ignore */ () => import(`/@/view/${modulePath}`).then(mod => mod.default);
|
||||
// child2.component = () => new Function(`return import('/@/view/${modulePath}')`)();
|
||||
// });
|
||||
// } else { // 如果没有下一级菜单代表是一级,重新处理一级菜单路由
|
||||
// // childRoute.component = /* @vite-ignore */ () => import(`/@/view/${modulePath0}`).then(mod => mod.default);
|
||||
// childRoute.component = () => new Function(`return import('/@/view/${modulePath0}')`)();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// return itemRouter;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user