From efa7770c1d3bc96e66a72d3ef22d34fbe1b6fd94 Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Mon, 7 Oct 2024 11:14:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=8C=E5=87=BB=E5=B1=95=E5=BC=80/?= =?UTF-8?q?=E6=8A=98=E5=8F=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/views/system/dept/index.vue | 51 +++++++++++++----- apps/web-antd/src/views/system/menu/index.vue | 54 +++++++++++++------ 2 files changed, 76 insertions(+), 29 deletions(-) diff --git a/apps/web-antd/src/views/system/dept/index.vue b/apps/web-antd/src/views/system/dept/index.vue index c8983b28..5826267e 100644 --- a/apps/web-antd/src/views/system/dept/index.vue +++ b/apps/web-antd/src/views/system/dept/index.vue @@ -4,9 +4,10 @@ import type { Recordable } from '@vben/types'; import { nextTick } from 'vue'; import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui'; -import { listToTree } from '@vben/utils'; +import { eachTree, listToTree, removeEmptyChildren } from '@vben/utils'; -import { Popconfirm, Space } from 'ant-design-vue'; +import { QuestionCircleOutlined } from '@ant-design/icons-vue'; +import { Popconfirm, Space, Tooltip } from 'ant-design-vue'; import { useVbenVxeGrid, type VxeGridProps } from '#/adapter'; import { deptList, deptRemove } from '#/api/system/dept'; @@ -40,12 +41,16 @@ const gridOptions: VxeGridProps = { pid: 'parentId', children: 'children', }); + removeEmptyChildren(treeData); return { rows: treeData }; }, // 默认请求接口后展开全部 不需要可以删除这段 querySuccess: () => { + // 默认展开 需要加上标记 + // eslint-disable-next-line no-use-before-define + eachTree(tableApi.grid.getData(), (item) => (item.expand = true)); nextTick(() => { - expandAll(); + setExpandOrCollapse(true); }); }, }, @@ -64,7 +69,21 @@ const gridOptions: VxeGridProps = { }, }; -const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions }); +const [BasicTable, tableApi] = useVbenVxeGrid({ + formOptions, + gridOptions, + gridEvents: { + cellDblclick: (e: any) => { + const { row = {} } = e; + if (!row?.children) { + return; + } + const isExpanded = row?.expand; + tableApi.grid.setTreeExpand(row, !isExpanded); + row.expand = !isExpanded; + }, + }, +}); const [DeptDrawer, drawerApi] = useVbenDrawer({ connectedComponent: deptDrawer, }); @@ -84,12 +103,13 @@ async function handleDelete(row: Recordable) { await tableApi.query(); } -function expandAll() { - tableApi.grid?.setAllTreeExpand(true); -} - -function collapseAll() { - tableApi.grid?.setAllTreeExpand(false); +/** + * 全部展开/折叠 + * @param expand 是否展开 + */ +function setExpandOrCollapse(expand: boolean) { + eachTree(tableApi.grid.getData(), (item) => (item.expand = expand)); + tableApi.grid?.setAllTreeExpand(expand); } @@ -97,14 +117,19 @@ function collapseAll() {