duyufeng
3 months ago
10 changed files with 262 additions and 41 deletions
@ -0,0 +1,44 @@ |
|||
const sessionStoreRoute = sessionStorage.getItem("dynamicRouteList"); |
|||
let getDynamicRouteList = sessionStoreRoute?JSON.parse(sessionStoreRoute):[]; |
|||
let dynamicRoute:any = []; |
|||
// getDynamicRouteList.map(itemRouter => {
|
|||
// if(itemRouter.children && itemRouter.children.length > 0){
|
|||
// itemRouter.children.map(childRoute => {
|
|||
// let modulePath0 = childRoute.component;
|
|||
// childRoute.component = () => new Function(`return import('/nerv-lib/saas/view/${modulePath0}')`)();///nerv-lib/saas/view/
|
|||
// if(childRoute.children && childRoute.children.length > 0){
|
|||
// childRoute.children.map(child2=>{
|
|||
// let modulePath = child2.component;
|
|||
// child2.component = () => new Function(`return import('/@/view/${modulePath}')`)();///@/view/
|
|||
// })
|
|||
// }else{//如没有下一级菜单代表是一级,重新处理一级菜单路由
|
|||
// childRoute.component = () => new Function(`return import('/@/view/${modulePath0}')`)();
|
|||
// }
|
|||
// })
|
|||
// }
|
|||
// dynamicRoute.push(itemRouter)
|
|||
// })
|
|||
getDynamicRouteList.forEach(itemRouter => { |
|||
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}')`)(); |
|||
} |
|||
}); |
|||
} |
|||
dynamicRoute.push(itemRouter); |
|||
}); |
|||
export default dynamicRoute; |
@ -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;
|
|||
// }
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,25 @@ |
|||
//处理路由compontent路径
|
|||
export const replyDynamRoutesPath = (data:any) => { |
|||
return data.map(item => { |
|||
if(item.children && item.children.length > 0){ |
|||
item.children.map(itemChild => { |
|||
if(itemChild.component){ |
|||
const modulePath0 = itemChild.component; |
|||
itemChild.component = () => new Function(`return import('/nerv-lib/saas/view/${modulePath0}')`)(); |
|||
if(itemChild.children && itemChild.children.length > 0){ |
|||
itemChild.children.map(itemChildChild => { |
|||
if(itemChildChild.component){ |
|||
const modulePath1 = itemChildChild.component; |
|||
itemChildChild.component = () => new Function(`return import('/@/view/${modulePath1}')`)(); |
|||
} |
|||
}) |
|||
}else{ |
|||
itemChild.component = () => new Function(`return import('/@/view/${modulePath0}')`)(); |
|||
} |
|||
} |
|||
}) |
|||
} |
|||
return item; |
|||
}) |
|||
} |
|||
|
Loading…
Reference in new issue