mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2025-12-14 06:42:51 +00:00
优化
This commit is contained in:
parent
8e4992055a
commit
ddd9408878
@ -200,13 +200,16 @@ export function deepPaths(paths: string[], splitor?: string) {
|
||||
}
|
||||
|
||||
// 列表转树形
|
||||
export function deepTree(list: any[], order?: "asc" | "desc"): any[] {
|
||||
export function deepTree(list: any[], sort?: "desc" | "asc"): any[] {
|
||||
const newList: any[] = [];
|
||||
const map: any = {};
|
||||
|
||||
list.forEach((e) => (map[e.id] = e));
|
||||
|
||||
list.forEach((e) => {
|
||||
orderBy(list, "orderNum", sort)
|
||||
.map((e) => {
|
||||
map[e.id] = e;
|
||||
return e;
|
||||
})
|
||||
.forEach((e) => {
|
||||
const parent = map[e.parentId];
|
||||
|
||||
if (parent) {
|
||||
@ -216,18 +219,7 @@ export function deepTree(list: any[], order?: "asc" | "desc"): any[] {
|
||||
}
|
||||
});
|
||||
|
||||
const fn = (list: Array<any>) => {
|
||||
list.map((e) => {
|
||||
if (isArray(e.children)) {
|
||||
e.children = orderBy(e.children, "orderNum", order);
|
||||
fn(e.children);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
fn(newList);
|
||||
|
||||
return orderBy(newList, "orderNum", order);
|
||||
return newList;
|
||||
}
|
||||
|
||||
// 树形转列表
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user