From 7be0723c315606aff0e62163448c8d971c5a6e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Mon, 3 Mar 2025 13:41:33 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=89=8D=E7=AB=AF=E6=A0=91=E7=BB=93=E6=9E=84=E6=8B=BC?= =?UTF-8?q?=E6=8E=A5=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/ruoyi.ts | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/utils/ruoyi.ts b/src/utils/ruoyi.ts index 8efd12c..07a4a6b 100644 --- a/src/utils/ruoyi.ts +++ b/src/utils/ruoyi.ts @@ -167,39 +167,21 @@ export const handleTree = (data: any[], id?: string, parentId?: string, child }; const childrenListMap: any = {}; - const nodeIds: any = {}; const tree: T[] = []; - for (const d of data) { - const parentId = d[config.parentId]; - if (childrenListMap[parentId] == null) { - childrenListMap[parentId] = []; - } - nodeIds[d[config.id]] = d; - childrenListMap[parentId].push(d); + const id = d[config.id]; + childrenListMap[id] = d; } for (const d of data) { const parentId = d[config.parentId]; - if (nodeIds[parentId] == null) { + const parentObj = childrenListMap[parentId] + if (!parentObj) { tree.push(d); + } else { + parentObj[config.childrenList].push(d) } } - const adaptToChildrenList = (o: any) => { - if (childrenListMap[o[config.id]] !== null) { - o[config.childrenList] = childrenListMap[o[config.id]]; - } - if (o[config.childrenList]) { - for (const c of o[config.childrenList]) { - adaptToChildrenList(c); - } - } - }; - - for (const t of tree) { - adaptToChildrenList(t); - } - return tree; };