From 3ba1a0be7bcf0ef6b178ce2c9d74b8b290cf8040 Mon Sep 17 00:00:00 2001 From: zhangzhanwei Date: Fri, 17 Oct 2025 11:37:01 +0800 Subject: [PATCH] feat: Tree-structured data query --- .../component/PermissionTable.vue | 78 +++++++++++++++++-- .../system/resource-authorization/index.vue | 4 - 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/ui/src/views/system/resource-authorization/component/PermissionTable.vue b/ui/src/views/system/resource-authorization/component/PermissionTable.vue index 67ded4ac0..a89b52de7 100644 --- a/ui/src/views/system/resource-authorization/component/PermissionTable.vue +++ b/ui/src/views/system/resource-authorization/component/PermissionTable.vue @@ -29,7 +29,6 @@ () const emit = defineEmits(['submitPermissions']) -const defaultExpandKeys = computed(() => (props.data?.length > 0 ? [props.data[0]?.id] : [])) +const defaultExpandKeys = computed(() => { + const searchName = searchForm.value.name || '' + const searchPermissions = searchForm.value.permission ?? [] + if (!searchName && (!searchPermissions || searchPermissions.length === 0)) { + return (props.data?.length > 0 ? [props.data[0]?.id] : []) + } + const expandIds: string[] = [] + // 传入过滤后的数据 + const collectExpandIds = (nodes: any[]) => { + nodes.forEach( + node => { + if (node.children && node.children.length > 0) { + expandIds.push(node.id) + collectExpandIds(node.children) + } + }) + } + collectExpandIds(filteredData.value) + return expandIds +} + ) + const permissionOptionMap = computed(() => { return { rootFolder: getPermissionOptions(true, true), @@ -240,12 +259,61 @@ const search_type_change = () => { searchForm.value = { name: '', permission: undefined } } -function searchHandle() { +const paginationConfig = reactive({ + current_page: 1, + page_size: 20, + total: 0, +}) + +function handleSizeChange() { + paginationConfig.current_page = 1 if (props.getData) { props.getData() } } +const filterTreeData = () => { + const searchName = searchForm.value.name || '' + const searchPermissions = searchForm.value.permission ?? [] + + if (!searchName && (!searchPermissions || searchPermissions.length === 0)) { + return props.data + } + + const filterNodes = (treeData: any[], name: string, permissions: any[]): any[] => { + if (!treeData || treeData.length === 0) return [] + + const result: any[] = [] + + for (const node of treeData) { + const cloneNode = { ...node } + + let isMatch = false + if (searchType.value === 'name') { + isMatch = node.name.toLowerCase().includes(name.toLowerCase()) + } else if (searchType.value === 'permission') { + isMatch = node.permission && permissions.includes(node.permission) + } + + let filteredChildren: any[] = [] + if (node.children && node.children.length > 0) { + filteredChildren = filterNodes(node.children, name, permissions) + } + if (isMatch || filteredChildren.length > 0) { + cloneNode.children = filteredChildren + result.push(cloneNode) + } + } + return result + } + return filterNodes(props.data, searchName, searchPermissions) +} + +const filteredData = computed(() => { + return filterTreeData() +}) + + const multipleSelection = ref([]) const handleSelectionChange = (val: any[]) => { diff --git a/ui/src/views/system/resource-authorization/index.vue b/ui/src/views/system/resource-authorization/index.vue index 19177248a..44cfcac43 100644 --- a/ui/src/views/system/resource-authorization/index.vue +++ b/ui/src/views/system/resource-authorization/index.vue @@ -156,10 +156,6 @@ const PermissionTableRef = ref() const getPermissionList = () => { const workspaceId = currentWorkspaceId.value || user.getWorkspaceId() || 'default' const params: any = {} - if (PermissionTableRef.value.searchForm[PermissionTableRef.value.searchType]) { - params[PermissionTableRef.value.searchType] = - PermissionTableRef.value.searchForm[PermissionTableRef.value.searchType] - } AuthorizationApi.getResourceAuthorization( workspaceId, currentUser.value,