修改
This commit is contained in:
parent
78158d97d1
commit
b0b71128b9
@ -30,15 +30,15 @@ export const routerGenerator = (routerMap): any[] => {
|
|||||||
isRoot: item.parentId == 0 && item.children.length == 0 ? true : false,
|
isRoot: item.parentId == 0 && item.children.length == 0 ? true : false,
|
||||||
alwaysShow: 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 : '',
|
frameSrc: item.target == 1 ? item.component : '',
|
||||||
target:item.target==2?true:false
|
target: item.target == 2 ? true : false,
|
||||||
}
|
};
|
||||||
let components = ''
|
let components = '';
|
||||||
if (item.parentId == 0 && (item.children.length == 0 || item.children.length > 0)) {
|
if (item.parentId == 0 && (item.children.length == 0 || item.children.length > 0)) {
|
||||||
components ='LAYOUT'
|
components = 'LAYOUT';
|
||||||
} else if (item.target == 0) {
|
} else if (item.target == 0) {
|
||||||
components = item.component
|
components = item.component;
|
||||||
} else if (item.target == 1) {
|
} else if (item.target == 1) {
|
||||||
components ='IFRAME'
|
components = 'IFRAME';
|
||||||
}
|
}
|
||||||
const currentRouter: any = {
|
const currentRouter: any = {
|
||||||
path: item.target == 2 ? '' : item.path,
|
path: item.target == 2 ? '' : item.path,
|
||||||
@ -65,8 +65,8 @@ export const routerGenerator = (routerMap): any[] => {
|
|||||||
currentRouter.children = routerGenerator(item.children, currentRouter);
|
currentRouter.children = routerGenerator(item.children, currentRouter);
|
||||||
} else {
|
} else {
|
||||||
if (item.parentId == 0 && item.children.length == 0) {
|
if (item.parentId == 0 && item.children.length == 0) {
|
||||||
currentRouter.children =[]
|
currentRouter.children = [];
|
||||||
if(item.target==1 && (/http(s)?:/.test(item.component))){
|
if (item.target == 1 && /http(s)?:/.test(item.component)) {
|
||||||
currentRouter.children.push({
|
currentRouter.children.push({
|
||||||
path: item.path,
|
path: item.path,
|
||||||
name: names,
|
name: names,
|
||||||
@ -77,7 +77,7 @@ export const routerGenerator = (routerMap): any[] => {
|
|||||||
hidden: item.hide ? true : false,
|
hidden: item.hide ? true : false,
|
||||||
},
|
},
|
||||||
component: 'IFRAME',
|
component: 'IFRAME',
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
currentRouter.children.push({
|
currentRouter.children.push({
|
||||||
path: item.path,
|
path: item.path,
|
||||||
@ -90,7 +90,7 @@ export const routerGenerator = (routerMap): any[] => {
|
|||||||
hidden: item.hide ? true : false,
|
hidden: item.hide ? true : false,
|
||||||
},
|
},
|
||||||
component: item.component,
|
component: item.component,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,8 +106,7 @@ export const generatorDynamicRouter = (): Promise<RouteRecordRaw[]> => {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
adminMenus()
|
adminMenus()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
const routeList = routerGenerator(result)
|
const routeList = routerGenerator(result);
|
||||||
console.log(routeList)
|
|
||||||
asyncImportRoute(routeList);
|
asyncImportRoute(routeList);
|
||||||
resolve(routeList);
|
resolve(routeList);
|
||||||
})
|
})
|
||||||
@ -173,5 +172,5 @@ export const dynamicImport = (
|
|||||||
* 查找第一个路由
|
* 查找第一个路由
|
||||||
* */
|
* */
|
||||||
export const findFirstRoutePath = (routes) => {
|
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) : '';
|
||||||
}
|
};
|
||||||
|
@ -8,8 +8,12 @@
|
|||||||
>
|
>
|
||||||
<template #default>
|
<template #default>
|
||||||
<div>
|
<div>
|
||||||
<n-checkbox v-model:checked="expandFlag" @change="handleExpand">展开/折叠</n-checkbox>
|
<n-checkbox v-model:checked="expandFlag" @update:checked="handleExpand"
|
||||||
<n-checkbox v-model:checked="checkedFlag" @change="handleSelectAll">全选/不全选</n-checkbox>
|
>展开/折叠</n-checkbox
|
||||||
|
>
|
||||||
|
<n-checkbox v-model:checked="checkedFlag" @update:checked="handleSelectAll"
|
||||||
|
>全选/不全选</n-checkbox
|
||||||
|
>
|
||||||
<div>
|
<div>
|
||||||
<n-tree
|
<n-tree
|
||||||
:data="menuTree"
|
:data="menuTree"
|
||||||
@ -141,62 +145,14 @@
|
|||||||
const data = await getRoleMenuList(props.roleId);
|
const data = await getRoleMenuList(props.roleId);
|
||||||
menuTree.value = buildTree(data);
|
menuTree.value = buildTree(data);
|
||||||
menuArray.value = data;
|
menuArray.value = data;
|
||||||
|
checkedKeys.value = [];
|
||||||
menuArray.value.map((item) => {
|
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;
|
|
||||||
// 如果子节点被选中,可能需要将子节点的ID也加入checkedIds(取决于需求)
|
|
||||||
// 但通常我们只关心父节点和叶子节点的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 };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 钩子函数
|
* 钩子函数
|
||||||
*/
|
*/
|
||||||
|
@ -94,7 +94,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
const actionColumn = reactive({
|
const actionColumn = reactive({
|
||||||
width: 200,
|
width: 250,
|
||||||
title: '操作',
|
title: '操作',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
|
Loading…
Reference in New Issue
Block a user