This commit is contained in:
陈红丽 2024-11-21 13:50:26 +08:00
parent 78158d97d1
commit b0b71128b9
3 changed files with 44 additions and 89 deletions

View File

@ -20,28 +20,28 @@ LayoutMap.set('IFRAME', Iframe);
*/
export const routerGenerator = (routerMap): any[] => {
return routerMap.map((item) => {
const names = item.target == 2 ? item.component : item.path.replaceAll('/', '');
const names = item.target == 2 ? item.component : item.path.replaceAll('/', '');
item.meta = {
title:item.parentId==0 && item.children.length==0?'':item.name,
icon:constantRouterIcon[item.icon2]|| null,
sort:item.sort,
permissions:item.permission,
hidden: item.hide?true:false,
isRoot:item.parentId==0 && item.children.length==0?true:false,
alwaysShow: item.parentId==0 && item.children.length==0?true:false,
frameSrc: item.target==1?item.component:'',
target:item.target==2?true:false
}
let components = ''
if(item.parentId==0 && (item.children.length==0 || item.children.length>0) ) {
components ='LAYOUT'
} else if(item.target==0) {
components = item.component
} else if(item.target==1) {
components ='IFRAME'
title: item.parentId == 0 && item.children.length == 0 ? '' : item.name,
icon: constantRouterIcon[item.icon2] || null,
sort: item.sort,
permissions: item.permission,
hidden: item.hide ? true : false,
isRoot: item.parentId == 0 && item.children.length == 0 ? true : false,
alwaysShow: item.parentId == 0 && item.children.length == 0 ? true : false,
frameSrc: item.target == 1 ? item.component : '',
target: item.target == 2 ? true : false,
};
let components = '';
if (item.parentId == 0 && (item.children.length == 0 || item.children.length > 0)) {
components = 'LAYOUT';
} else if (item.target == 0) {
components = item.component;
} else if (item.target == 1) {
components = 'IFRAME';
}
const currentRouter: any = {
path:item.target==2?'':item.path,
path: item.target == 2 ? '' : item.path,
// 路由名称,建议唯一
name: names,
// 该路由对应页面的 组件
@ -64,33 +64,33 @@ export const routerGenerator = (routerMap): any[] => {
// Recursion
currentRouter.children = routerGenerator(item.children, currentRouter);
} else {
if(item.parentId==0 && item.children.length==0) {
currentRouter.children =[]
if(item.target==1 && (/http(s)?:/.test(item.component))){
if (item.parentId == 0 && item.children.length == 0) {
currentRouter.children = [];
if (item.target == 1 && /http(s)?:/.test(item.component)) {
currentRouter.children.push({
path: item.path,
name: names,
meta: {
title: item.name,
frameSrc: item.component,
icon:constantRouterIcon[item.icon2],
hidden: item.hide?true:false,
icon: constantRouterIcon[item.icon2],
hidden: item.hide ? true : false,
},
component: 'IFRAME',
})
});
} else {
currentRouter.children.push({
path: item.path,
name: names,
meta: {
title: item.name,
icon:constantRouterIcon[item.icon2],
icon: constantRouterIcon[item.icon2],
activeMenu: names,
target:item.target==2?true:false,
hidden: item.hide?true:false,
target: item.target == 2 ? true : false,
hidden: item.hide ? true : false,
},
component: item.component,
})
});
}
}
}
@ -106,8 +106,7 @@ export const generatorDynamicRouter = (): Promise<RouteRecordRaw[]> => {
return new Promise((resolve, reject) => {
adminMenus()
.then((result) => {
const routeList = routerGenerator(result)
console.log(routeList)
const routeList = routerGenerator(result);
asyncImportRoute(routeList);
resolve(routeList);
})
@ -172,6 +171,6 @@ export const dynamicImport = (
/**
*
* */
export const findFirstRoutePath = (routes)=>{
return routes.length > 0?(routes[0].redirect?routes[0].redirect:routes[0].path):''
}
export const findFirstRoutePath = (routes) => {
return routes.length > 0 ? (routes[0].redirect ? routes[0].redirect : routes[0].path) : '';
};

View File

@ -8,8 +8,12 @@
>
<template #default>
<div>
<n-checkbox v-model:checked="expandFlag" @change="handleExpand">展开/折叠</n-checkbox>
<n-checkbox v-model:checked="checkedFlag" @change="handleSelectAll">全选/不全选</n-checkbox>
<n-checkbox v-model:checked="expandFlag" @update:checked="handleExpand"
>展开/折叠</n-checkbox
>
<n-checkbox v-model:checked="checkedFlag" @update:checked="handleSelectAll"
>全选/不全选</n-checkbox
>
<div>
<n-tree
:data="menuTree"
@ -141,61 +145,13 @@
const data = await getRoleMenuList(props.roleId);
menuTree.value = buildTree(data);
menuArray.value = data;
checkedKeys.value = [];
menuArray.value.map((item) => {
allMenuIds.value.push(item.id);
});
const keys = checkTree(menuTree.value, 0, [], []);
checkedKeys.value = { checked: keys.checkedIds, halfChecked: keys.halfCheckedIds };
};
/**
* 选中树结构
* @param nodes 节点
* @param parentId 上级ID
* @param checkedIds 选中ID集合
* @param halfCheckedIds
*/
function checkTree(nodes, parentId = null, checkedIds, halfCheckedIds) {
nodes.forEach((node) => {
let allChildrenChecked = true;
let someChildrenChecked = false;
//
if (node.children && node.children.length > 0) {
checkTree(node.children, node.id, checkedIds, halfCheckedIds); //
//
node.children.forEach((child) => {
if (child.checked) {
someChildrenChecked = true;
// IDcheckedIds
// checked
halfCheckedIds.push(child.id); //
} else {
allChildrenChecked = false;
}
});
//
if (allChildrenChecked) {
//
checkedIds.push(node.id);
} else if (someChildrenChecked) {
//
halfCheckedIds.push(parentId || node.id); // parentId
}
//
// 使
//
} else {
// checked
if (node.checked) {
checkedIds.push(node.id);
}
if (item.checked) {
checkedKeys.value.push(item.id);
}
});
return { checkedIds, halfCheckedIds };
}
};
/**
* 钩子函数

View File

@ -94,7 +94,7 @@
});
const actionColumn = reactive({
width: 200,
width: 250,
title: '操作',
align: 'center',
key: 'action',