fetch(modify):修改bug
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 5m20s
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 5m20s
This commit is contained in:
@@ -312,12 +312,51 @@
|
||||
}
|
||||
])
|
||||
|
||||
// 将扁平数据转换为树形结构
|
||||
const buildTreeData = (flatData: Permission[]): Permission[] => {
|
||||
const map = new Map<number, Permission>()
|
||||
const result: Permission[] = []
|
||||
|
||||
// 先创建所有节点的映射
|
||||
flatData.forEach((item) => {
|
||||
map.set(item.ID, { ...item, children: [] })
|
||||
})
|
||||
|
||||
// 构建树形结构
|
||||
map.forEach((item) => {
|
||||
if (item.parent_id && map.has(item.parent_id)) {
|
||||
const parent = map.get(item.parent_id)!
|
||||
if (!parent.children) {
|
||||
parent.children = []
|
||||
}
|
||||
parent.children.push(item)
|
||||
} else {
|
||||
// 没有父节点的是根节点
|
||||
result.push(item)
|
||||
}
|
||||
})
|
||||
|
||||
// 递归排序
|
||||
const sortTree = (nodes: Permission[]): Permission[] => {
|
||||
return nodes
|
||||
.sort((a, b) => (a.sort || 0) - (b.sort || 0))
|
||||
.map((node) => ({
|
||||
...node,
|
||||
children: node.children && node.children.length > 0 ? sortTree(node.children) : undefined
|
||||
}))
|
||||
}
|
||||
|
||||
return sortTree(result)
|
||||
}
|
||||
|
||||
// 获取权限列表
|
||||
const getPermissionList = async () => {
|
||||
try {
|
||||
const response = await PermissionService.getPermissions(searchForm)
|
||||
if (response.code === 0) {
|
||||
permissionList.value = response.data.items || []
|
||||
const flatData = response.data.items || []
|
||||
// 将扁平数据转换为树形结构
|
||||
permissionList.value = buildTreeData(flatData)
|
||||
// 构建权限树选项
|
||||
buildPermissionTreeOptions()
|
||||
}
|
||||
@@ -332,7 +371,7 @@
|
||||
return list.map((item) => ({
|
||||
value: item.ID,
|
||||
label: item.perm_name,
|
||||
children: item.children ? buildTree(item.children) : undefined
|
||||
children: item.children && item.children.length > 0 ? buildTree(item.children) : undefined
|
||||
}))
|
||||
}
|
||||
permissionTreeOptions.value = buildTree(permissionList.value)
|
||||
|
||||
Reference in New Issue
Block a user