fix:将部门管理中的树形结构改为受控的模式,不在是点一个而全部展开或者收缩

This commit is contained in:
Maple 2025-07-28 15:12:10 +08:00
parent 8c202c45dc
commit 9741192bee
3 changed files with 22 additions and 5 deletions

View File

@ -70,6 +70,6 @@ declare global {
// for type re-export // for type re-export
declare global { declare global {
// @ts-ignore // @ts-ignore
export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue' export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
import('vue') import('vue')
} }

View File

@ -9,13 +9,15 @@
<GiTable <GiTable
v-show="viewType === 'table'" v-show="viewType === 'table'"
ref="tableRef" ref="tableRef"
row-key="id" row-key="deptId"
:data="dataList" :data="dataList"
:columns="columns" :columns="columns"
:loading="loading" :loading="loading"
:scroll="{ x: '100%', y: '100%', minWidth: 1000 }" :scroll="{ x: '100%', y: '100%', minWidth: 1000 }"
:pagination="false" :pagination="false"
:disabled-column-keys="['name']" :disabled-column-keys="['name']"
:expanded-keys="expandedKeys"
@expand="onExpand"
@refresh="search" @refresh="search"
> >
<template #expand-icon="{ expanded }"> <template #expand-icon="{ expanded }">
@ -109,9 +111,10 @@ const {
} = useTable<DeptResp>(() => getDeptTree(queryForm), { } = useTable<DeptResp>(() => getDeptTree(queryForm), {
immediate: true, immediate: true,
onSuccess: () => { onSuccess: () => {
nextTick(() => { // nextTick(() => {
tableRef.value?.tableRef?.expandAll(true) // tableRef.value?.tableRef?.expandAll(true)
}) // })
//
}, },
}) })
// //
@ -124,6 +127,8 @@ const menus = [
] ]
// //
const nodeExpandAll = ref<boolean>(true) const nodeExpandAll = ref<boolean>(true)
//
const expandedKeys = ref<string[]>([])
// //
const searchData = (name: string) => { const searchData = (name: string) => {
const loop = (data: DeptResp[]) => { const loop = (data: DeptResp[]) => {
@ -204,6 +209,17 @@ const handleAdd = (record: DeptResp) => {
const onUpdate = (record: DeptResp) => { const onUpdate = (record: DeptResp) => {
DeptAddModalRef.value?.onUpdate(record.deptId) DeptAddModalRef.value?.onUpdate(record.deptId)
} }
const onExpand = (expanded: boolean, record: DeptResp) => {
const key = record.deptId
if (expanded) {
if (!expandedKeys.value.includes(key)) {
expandedKeys.value.push(key)
}
} else {
expandedKeys.value = expandedKeys.value.filter(k => k !== key)
}
}
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

View File

@ -1,4 +1,5 @@
<template> <template>
<h1>这个暂时写不了角色管理采用菜单权限的设置</h1>
<GiPageLayout :header-style="{ padding: 0, borderBottom: 'none' }"> <GiPageLayout :header-style="{ padding: 0, borderBottom: 'none' }">
<template #left> <template #left>
<RoleTree @node-click="handleSelectRole" /> <RoleTree @node-click="handleSelectRole" />