作者 RuoYi

优化前端树结构性能问题

1 -  
2 -  
3 /** 1 /**
4 * 通用js方法封装处理 2 * 通用js方法封装处理
5 * Copyright (c) 2019 ruoyi 3 * Copyright (c) 2019 ruoyi
@@ -165,37 +163,19 @@ export function handleTree(data, id, parentId, children) { @@ -165,37 +163,19 @@ export function handleTree(data, id, parentId, children) {
165 }; 163 };
166 164
167 var childrenListMap = {}; 165 var childrenListMap = {};
168 - var nodeIds = {};  
169 var tree = []; 166 var tree = [];
170 -  
171 for (let d of data) { 167 for (let d of data) {
172 - let parentId = d[config.parentId];  
173 - if (childrenListMap[parentId] == null) {  
174 - childrenListMap[parentId] = [];  
175 - }  
176 - nodeIds[d[config.id]] = d;  
177 - childrenListMap[parentId].push(d); 168 + let id = d[config.id];
  169 + childrenListMap[id] = d;
178 } 170 }
179 171
180 for (let d of data) { 172 for (let d of data) {
181 - let parentId = d[config.parentId];  
182 - if (nodeIds[parentId] == null) { 173 + let parentId = d[config.parentId]
  174 + let parentObj = childrenListMap[parentId]
  175 + if (!parentObj) {
183 tree.push(d); 176 tree.push(d);
184 - }  
185 - }  
186 -  
187 - for (let t of tree) {  
188 - adaptToChildrenList(t);  
189 - }  
190 -  
191 - function adaptToChildrenList(o) {  
192 - if (childrenListMap[o[config.id]] !== null) {  
193 - o[config.childrenList] = childrenListMap[o[config.id]];  
194 - }  
195 - if (o[config.childrenList]) {  
196 - for (let c of o[config.childrenList]) {  
197 - adaptToChildrenList(c);  
198 - } 177 + } else {
  178 + parentObj[config.childrenList].push(d)
199 } 179 }
200 } 180 }
201 return tree; 181 return tree;
@@ -227,6 +207,18 @@ export function tansParams(params) { @@ -227,6 +207,18 @@ export function tansParams(params) {
227 return result 207 return result
228 } 208 }
229 209
  210 +// 返回项目路径
  211 +export function getNormalPath(p) {
  212 + if (p.length === 0 || !p || p == 'undefined') {
  213 + return p
  214 + };
  215 + let res = p.replace('//', '/')
  216 + if (res[res.length - 1] === '/') {
  217 + return res.slice(0, res.length - 1)
  218 + }
  219 + return res;
  220 +}
  221 +
230 // 验证是否为blob格式 222 // 验证是否为blob格式
231 export function blobValidate(data) { 223 export function blobValidate(data) {
232 return data.type !== 'application/json' 224 return data.type !== 'application/json'