From 537fc97695717b3db452ed52b1d4f7b475b393be Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sat, 1 Mar 2025 14:54:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AF=E6=A0=91?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E6=80=A7=E8=83=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/ruoyi.js | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/src/utils/ruoyi.js b/src/utils/ruoyi.js index 2714962..2bc6db0 100644 --- a/src/utils/ruoyi.js +++ b/src/utils/ruoyi.js @@ -1,5 +1,3 @@ - - /** * 通用js方法封装处理 * Copyright (c) 2019 ruoyi @@ -86,7 +84,7 @@ export function selectDictLabel(datas, value) { return actions.join(''); } -// 回显数据字典(字符串数组) +// 回显数据字典(字符串、数组) export function selectDictLabels(datas, value, separator) { if (value === undefined || value.length ===0) { return ""; @@ -165,37 +163,19 @@ export function handleTree(data, id, parentId, children) { }; var childrenListMap = {}; - var nodeIds = {}; var tree = []; - for (let d of data) { - let parentId = d[config.parentId]; - if (childrenListMap[parentId] == null) { - childrenListMap[parentId] = []; - } - nodeIds[d[config.id]] = d; - childrenListMap[parentId].push(d); + let id = d[config.id]; + childrenListMap[id] = d; } for (let d of data) { - let parentId = d[config.parentId]; - if (nodeIds[parentId] == null) { + let parentId = d[config.parentId] + let parentObj = childrenListMap[parentId] + if (!parentObj) { tree.push(d); - } - } - - for (let t of tree) { - adaptToChildrenList(t); - } - - function adaptToChildrenList(o) { - if (childrenListMap[o[config.id]] !== null) { - o[config.childrenList] = childrenListMap[o[config.id]]; - } - if (o[config.childrenList]) { - for (let c of o[config.childrenList]) { - adaptToChildrenList(c); - } + } else { + parentObj[config.childrenList].push(d) } } return tree; @@ -227,7 +207,6 @@ export function tansParams(params) { return result } - // 返回项目路径 export function getNormalPath(p) { if (p.length === 0 || !p || p == 'undefined') {