From 98f285506947109bf985492baeaa176a8f223abf Mon Sep 17 00:00:00 2001 From: K <1175047471@qq.com> Date: Tue, 19 Mar 2024 13:43:33 +0800 Subject: [PATCH] refactor: use load instead of onExpand --- src/api/system/dept/types.ts | 2 +- src/views/system/dept/index.vue | 26 ++++++++++++-------------- src/views/system/role/index.vue | 13 ++++--------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/api/system/dept/types.ts b/src/api/system/dept/types.ts index 48de5c6a..a0ed3c46 100644 --- a/src/api/system/dept/types.ts +++ b/src/api/system/dept/types.ts @@ -5,7 +5,7 @@ export interface Department { deptName: string parentName: string deptTypeName: string - children: Department[] + children?: Department[] hasChildren: boolean } diff --git a/src/views/system/dept/index.vue b/src/views/system/dept/index.vue index 9ec9fbad..5ebf588a 100644 --- a/src/views/system/dept/index.vue +++ b/src/views/system/dept/index.vue @@ -19,22 +19,21 @@ const [registerModal, { openModal }] = useModal() const { hasPermission } = usePermission() -const [register, { reload }] = useTable({ +const [register, { reload }] = useTable({ 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 { - 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, formConfig: { @@ -43,7 +42,6 @@ const [register, { reload }] = useTable({ }, bordered: true, canResize: false, - isTreeTable: true, useSearchForm: true, pagination: false, actionColumn: { diff --git a/src/views/system/role/index.vue b/src/views/system/role/index.vue index e065dfd9..b07b980f 100644 --- a/src/views/system/role/index.vue +++ b/src/views/system/role/index.vue @@ -18,7 +18,7 @@ const [registerMenuModal, { openModal: openMenuModal }] = useModal() const { hasPermission } = usePermission() -const [registerTable, { reload }] = useTable({ +const [registerTable, { reload }] = useTable({ async api(params) { try { const list = await lazyGetRoleList(params) @@ -31,14 +31,8 @@ const [registerTable, { reload }] = useTable({ return [] } }, - async onExpand(isExpand, data: Role) { - if (!isExpand || data.children?.length) - return - - try { - data.children = await lazyGetRoleList({ parentId: data.id }) - } - catch {} + load(record) { + return lazyGetRoleList({ parentId: record.id }) }, columns, formConfig: { @@ -49,6 +43,7 @@ const [registerTable, { reload }] = useTable({ bordered: true, canResize: false, useSearchForm: true, + pagination: false, actionColumn: { width: 140, title: '操作',