fetch(modify):修改bug
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 5m20s

This commit is contained in:
sexygoat
2026-01-31 16:33:21 +08:00
parent 16d53709ef
commit ecb79dae43
20 changed files with 1369 additions and 649 deletions

View File

@@ -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)