Browse Source

refactor: use load instead of onExpand

main
刘凯 1 year ago
parent
commit
98f2855069
  1. 2
      src/api/system/dept/types.ts
  2. 26
      src/views/system/dept/index.vue
  3. 13
      src/views/system/role/index.vue

2
src/api/system/dept/types.ts

@ -5,7 +5,7 @@ export interface Department {
deptName: string deptName: string
parentName: string parentName: string
deptTypeName: string deptTypeName: string
children: Department[] children?: Department[]
hasChildren: boolean hasChildren: boolean
} }

26
src/views/system/dept/index.vue

@ -19,22 +19,21 @@ const [registerModal, { openModal }] = useModal<Department>()
const { hasPermission } = usePermission() const { hasPermission } = usePermission()
const [register, { reload }] = useTable({ const [register, { reload }] = useTable<Department>({
async api(params) { async api(params) {
const list = await lazyGetDeptList(params)
return list.map(item => ({
...item,
children: item.hasChildren ? [] : undefined,
}))
},
async onExpand(isExpand, data: Department) {
if (!isExpand || data.children.length)
return
try { try {
data.children = await lazyGetDeptList({ parentId: data.id }) const list = await lazyGetDeptList(params)
return list.map(item => ({
...item,
children: item.hasChildren ? [] : undefined,
}))
} }
catch {} catch {
return []
}
},
load(record) {
return lazyGetDeptList({ parentId: record.id })
}, },
columns, columns,
formConfig: { formConfig: {
@ -43,7 +42,6 @@ const [register, { reload }] = useTable({
}, },
bordered: true, bordered: true,
canResize: false, canResize: false,
isTreeTable: true,
useSearchForm: true, useSearchForm: true,
pagination: false, pagination: false,
actionColumn: { actionColumn: {

13
src/views/system/role/index.vue

@ -18,7 +18,7 @@ const [registerMenuModal, { openModal: openMenuModal }] = useModal<string>()
const { hasPermission } = usePermission() const { hasPermission } = usePermission()
const [registerTable, { reload }] = useTable({ const [registerTable, { reload }] = useTable<Role>({
async api(params) { async api(params) {
try { try {
const list = await lazyGetRoleList(params) const list = await lazyGetRoleList(params)
@ -31,14 +31,8 @@ const [registerTable, { reload }] = useTable({
return [] return []
} }
}, },
async onExpand(isExpand, data: Role) { load(record) {
if (!isExpand || data.children?.length) return lazyGetRoleList({ parentId: record.id })
return
try {
data.children = await lazyGetRoleList({ parentId: data.id })
}
catch {}
}, },
columns, columns,
formConfig: { formConfig: {
@ -49,6 +43,7 @@ const [registerTable, { reload }] = useTable({
bordered: true, bordered: true,
canResize: false, canResize: false,
useSearchForm: true, useSearchForm: true,
pagination: false,
actionColumn: { actionColumn: {
width: 140, width: 140,
title: '操作', title: '操作',

Loading…
Cancel
Save