Skip to content

Commit 3ba1a0b

Browse files
committed
feat: Tree-structured data query
1 parent 087f707 commit 3ba1a0b

File tree

2 files changed

+73
-9
lines changed

2 files changed

+73
-9
lines changed

ui/src/views/system/resource-authorization/component/PermissionTable.vue

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@
2929
<el-input
3030
v-if="searchType === 'name'"
3131
v-model="searchForm.name"
32-
@change="searchHandle"
3332
:placeholder="$t('common.searchBar.placeholder')"
3433
style="width: 220px"
3534
clearable
3635
/>
3736
<el-select
3837
v-else-if="searchType === 'permission'"
3938
v-model="searchForm.permission"
40-
@change="searchHandle"
4139
filterable
4240
clearable
4341
multiple
@@ -55,7 +53,7 @@
5553
<app-table
5654
ref="multipleTableRef"
5755
class="mt-16"
58-
:data="props.data"
56+
:data="filteredData"
5957
@selection-change="handleSelectionChange"
6058
:maxTableHeight="260"
6159
:row-key="(row: any) => row.id"
@@ -158,7 +156,28 @@ const props = defineProps<{
158156
}>()
159157
const emit = defineEmits(['submitPermissions'])
160158
161-
const defaultExpandKeys = computed(() => (props.data?.length > 0 ? [props.data[0]?.id] : []))
159+
const defaultExpandKeys = computed(() => {
160+
const searchName = searchForm.value.name || ''
161+
const searchPermissions = searchForm.value.permission ?? []
162+
if (!searchName && (!searchPermissions || searchPermissions.length === 0)) {
163+
return (props.data?.length > 0 ? [props.data[0]?.id] : [])
164+
}
165+
const expandIds: string[] = []
166+
// 传入过滤后的数据
167+
const collectExpandIds = (nodes: any[]) => {
168+
nodes.forEach(
169+
node => {
170+
if (node.children && node.children.length > 0) {
171+
expandIds.push(node.id)
172+
collectExpandIds(node.children)
173+
}
174+
})
175+
}
176+
collectExpandIds(filteredData.value)
177+
return expandIds
178+
}
179+
)
180+
162181
const permissionOptionMap = computed(() => {
163182
return {
164183
rootFolder: getPermissionOptions(true, true),
@@ -240,12 +259,61 @@ const search_type_change = () => {
240259
searchForm.value = { name: '', permission: undefined }
241260
}
242261
243-
function searchHandle() {
262+
const paginationConfig = reactive({
263+
current_page: 1,
264+
page_size: 20,
265+
total: 0,
266+
})
267+
268+
function handleSizeChange() {
269+
paginationConfig.current_page = 1
244270
if (props.getData) {
245271
props.getData()
246272
}
247273
}
248274
275+
const filterTreeData = () => {
276+
const searchName = searchForm.value.name || ''
277+
const searchPermissions = searchForm.value.permission ?? []
278+
279+
if (!searchName && (!searchPermissions || searchPermissions.length === 0)) {
280+
return props.data
281+
}
282+
283+
const filterNodes = (treeData: any[], name: string, permissions: any[]): any[] => {
284+
if (!treeData || treeData.length === 0) return []
285+
286+
const result: any[] = []
287+
288+
for (const node of treeData) {
289+
const cloneNode = { ...node }
290+
291+
let isMatch = false
292+
if (searchType.value === 'name') {
293+
isMatch = node.name.toLowerCase().includes(name.toLowerCase())
294+
} else if (searchType.value === 'permission') {
295+
isMatch = node.permission && permissions.includes(node.permission)
296+
}
297+
298+
let filteredChildren: any[] = []
299+
if (node.children && node.children.length > 0) {
300+
filteredChildren = filterNodes(node.children, name, permissions)
301+
}
302+
if (isMatch || filteredChildren.length > 0) {
303+
cloneNode.children = filteredChildren
304+
result.push(cloneNode)
305+
}
306+
}
307+
return result
308+
}
309+
return filterNodes(props.data, searchName, searchPermissions)
310+
}
311+
312+
const filteredData = computed(() => {
313+
return filterTreeData()
314+
})
315+
316+
249317
const multipleSelection = ref<any[]>([])
250318
251319
const handleSelectionChange = (val: any[]) => {

ui/src/views/system/resource-authorization/index.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ const PermissionTableRef = ref()
156156
const getPermissionList = () => {
157157
const workspaceId = currentWorkspaceId.value || user.getWorkspaceId() || 'default'
158158
const params: any = {}
159-
if (PermissionTableRef.value.searchForm[PermissionTableRef.value.searchType]) {
160-
params[PermissionTableRef.value.searchType] =
161-
PermissionTableRef.value.searchForm[PermissionTableRef.value.searchType]
162-
}
163159
AuthorizationApi.getResourceAuthorization(
164160
workspaceId,
165161
currentUser.value,

0 commit comments

Comments
 (0)