From 232e578a6ba7ec8a2d6227ea5b616059111459d7 Mon Sep 17 00:00:00 2001 From: yxh Date: Thu, 13 Apr 2023 21:16:09 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E6=A0=91=E5=BD=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E8=BD=AC=E6=8D=A2=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/gfast.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/utils/gfast.ts b/src/utils/gfast.ts index 7902b71..b3b0636 100644 --- a/src/utils/gfast.ts +++ b/src/utils/gfast.ts @@ -29,7 +29,7 @@ export function getUpFileUrl(url:string){ * @param {*} children 孩子节点字段 默认 'children' * @param {*} rootId 根Id 默认 0 */ -export function handleTree(data:any[], id:string, parentId:string, children:string, rootId:number):any[] { +export function handleTree(data:any[], id:string, parentId:string, children:string, rootId:any):any[] { id = id || 'id' parentId = parentId || 'parentId' children = children || 'children' @@ -44,7 +44,16 @@ export function handleTree(data:any[], id:string, parentId:string, children:stri }); branchArr.length > 0 ? father[children] = branchArr : ''; //返回第一层 - return father[parentId] === rootId; + switch (typeof father[parentId]){ + case 'string': + if(father[parentId]===''&&rootId===0){ + return true + } + return father[parentId]===rootId.toString(); + case 'number': + return father[parentId] === rootId; + } + return false; }); return treeData != '' ? treeData : data; }