|
|
|
@ -169,52 +169,36 @@ export function handleTree(data, id, parentId, children) {
|
|
|
|
* 路由数据遍历
|
|
|
|
* 路由数据遍历
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function formatRoutes(routerArr){
|
|
|
|
export function formatRoutes(routerArr) {
|
|
|
|
let arr = [],obj = {};
|
|
|
|
/**
|
|
|
|
routerArr.forEach(tmp => {
|
|
|
|
* 递归处理单个路由项
|
|
|
|
obj = {
|
|
|
|
* @param {Object} routeItem 路由项
|
|
|
|
id:tmp.id,
|
|
|
|
* @param {String} parentPath 父级路径,用于构建完整路径
|
|
|
|
pid:tmp.pid,
|
|
|
|
* @returns {Object} 格式化后的路由对象
|
|
|
|
name:tmp.name,
|
|
|
|
*/
|
|
|
|
url:tmp.component,
|
|
|
|
function formatRouteItem(routeItem, parentPath = '') {
|
|
|
|
path:'/' + tmp.pid + '/',
|
|
|
|
const currentPath = parentPath ? `${parentPath}${routeItem.pid}/` : `/${routeItem.pid}/`;
|
|
|
|
perms:tmp.perms,
|
|
|
|
|
|
|
|
child:tmp.childList.length ? tmp.childList.map(item=>{
|
|
|
|
const formattedRoute = {
|
|
|
|
return {
|
|
|
|
id: routeItem.id,
|
|
|
|
id:item.id,
|
|
|
|
pid: routeItem.pid,
|
|
|
|
pid:item.pid,
|
|
|
|
name: routeItem.name,
|
|
|
|
name:item.name,
|
|
|
|
url: routeItem.component,
|
|
|
|
url:item.component,
|
|
|
|
path: currentPath,
|
|
|
|
path:'/' + tmp.pid + '/' + item.pid + '/',
|
|
|
|
perms: routeItem.perms,
|
|
|
|
perms:item.perms,
|
|
|
|
child: [],
|
|
|
|
extra:item.icon,
|
|
|
|
extra: routeItem.icon
|
|
|
|
child:item.childList.length ? item.childList.map(item1=>{
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
|
|
|
|
id:item1.id,
|
|
|
|
// 递归处理子路由
|
|
|
|
pid:item1.pid,
|
|
|
|
if (routeItem.childList && routeItem.childList.length > 0) {
|
|
|
|
name:item1.name,
|
|
|
|
formattedRoute.child = routeItem.childList.map(child =>
|
|
|
|
url:item1.component,
|
|
|
|
formatRouteItem(child, currentPath)
|
|
|
|
path:'/' + tmp.pid + '/' + item.pid + '/' + item1.pid + '/',
|
|
|
|
);
|
|
|
|
perms:item1.perms,
|
|
|
|
|
|
|
|
extra:item1.icon,
|
|
|
|
|
|
|
|
child:item1.childList.length ? item1.childList.map(item2=>{
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
id:item2.id,
|
|
|
|
|
|
|
|
pid:item2.pid,
|
|
|
|
|
|
|
|
name:item2.name,
|
|
|
|
|
|
|
|
url:item2.component,
|
|
|
|
|
|
|
|
path:'/' + tmp.pid + '/' + item.pid + '/' + item1.pid + '/' + item2.pid + '/',
|
|
|
|
|
|
|
|
perms:item2.perms,
|
|
|
|
|
|
|
|
extra:item2.icon,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}) : []
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}) : []
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}) : [],
|
|
|
|
|
|
|
|
extra:tmp.icon,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arr.push(obj);
|
|
|
|
|
|
|
|
})
|
|
|
|
return formattedRoute;
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return routerArr.map(item => formatRouteItem(item));
|
|
|
|
|
|
|
|
}
|