From 301008d876615f94f23d0f68d1a05671c7638815 Mon Sep 17 00:00:00 2001 From: zhou <95430589@qq.com> Date: Thu, 24 Mar 2022 16:56:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E8=8F=9C=E5=8D=95=E6=97=B6,?= =?UTF-8?q?=E5=AD=90=E8=8F=9C=E5=8D=95=E5=92=8C=E6=8C=89=E9=92=AE=E7=9A=84?= =?UTF-8?q?=E4=B8=8A=E7=BA=A7=E8=8F=9C=E5=8D=95=E4=B8=8D=E8=83=BD=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E8=87=AA=E8=BA=AB=E5=8F=8A=E5=85=B6=E5=AD=90=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/tree.ts | 14 ++++++++++++++ src/views/system/menu/MenuDrawer.vue | 13 +++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/utils/tree.ts diff --git a/src/utils/tree.ts b/src/utils/tree.ts new file mode 100644 index 0000000..86bc254 --- /dev/null +++ b/src/utils/tree.ts @@ -0,0 +1,14 @@ +export function filterTree(tree: T[], iterate: (item: T, index: number) => boolean): T[] { + function filter(tree: T[]): T[] { + return tree.filter((item, index) => { + if (!iterate(item, index)) { + return false; + } + if (item.children && item.children.length > 0) { + item.children = filter(item.children); + } + return true; + }) + } + return filter(tree); +} diff --git a/src/views/system/menu/MenuDrawer.vue b/src/views/system/menu/MenuDrawer.vue index 4e47529..411e3da 100644 --- a/src/views/system/menu/MenuDrawer.vue +++ b/src/views/system/menu/MenuDrawer.vue @@ -10,6 +10,8 @@ import {BasicDrawer, useDrawerInner} from '/@/components/Drawer'; import {list, saveOrUpdateMenu} from './menu.api'; import { useAdapt } from '/@/hooks/system/useAutoAdapt.ts'; + import { filterTree } from '/@/utils/tree'; + // 声明Emits const emit = defineEmits(['success', 'register']); const {width}= useAdapt(); @@ -36,8 +38,15 @@ isUpdate.value = !!data?.isUpdate; menuType.value = data?.record?.menuType; - //获取下拉树信息 - const treeData = await list(); + // 获取当前 record 的 id + const currentId = data?.record?.id; + + //获取下拉树信息 + let treeData = await list(); + if (currentId) { + treeData = filterTree(treeData, (item: any) => item.id !== currentId); + } + updateSchema([{ field: 'parentId', componentProps: {treeData},