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

@ -30,15 +30,15 @@ export const routerGenerator = (routerMap): any[] => {
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 = ''
target: item.target == 2 ? true : false,
};
let components = '';
if (item.parentId == 0 && (item.children.length == 0 || item.children.length > 0)) {
components ='LAYOUT'
components = 'LAYOUT';
} else if (item.target == 0) {
components = item.component
components = item.component;
} else if (item.target == 1) {
components ='IFRAME'
components = 'IFRAME';
}
const currentRouter: any = {
path: item.target == 2 ? '' : item.path,
@ -65,8 +65,8 @@ export const routerGenerator = (routerMap): any[] => {
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))){
currentRouter.children = [];
if (item.target == 1 && /http(s)?:/.test(item.component)) {
currentRouter.children.push({
path: item.path,
name: names,
@ -77,7 +77,7 @@ export const routerGenerator = (routerMap): any[] => {
hidden: item.hide ? true : false,
},
component: 'IFRAME',
})
});
} else {
currentRouter.children.push({
path: item.path,
@ -90,7 +90,7 @@ export const routerGenerator = (routerMap): any[] => {
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);
})
@ -173,5 +172,5 @@ export const dynamicImport = (
*
* */
export const findFirstRoutePath = (routes) => {
return routes.length > 0?(routes[0].redirect?routes[0].redirect:routes[0].path):''
}
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,62 +145,14 @@
const data = await getRoleMenuList(props.roleId);
menuTree.value = buildTree(data);
menuArray.value = data;
checkedKeys.value = [];
menuArray.value.map((item) => {
allMenuIds.value.push(item.id);
if (item.checked) {
checkedKeys.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);
}
}
});
return { checkedIds, halfCheckedIds };
}
/**
* 钩子函数
*/

View File

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