dlzn-ui 1.15.0 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.mjs +2 -1
- package/utils/tree.d.ts +26 -0
- package/utils/tree.mjs +36 -0
package/package.json
CHANGED
package/utils/index.d.ts
CHANGED
package/utils/index.mjs
CHANGED
|
@@ -2,4 +2,5 @@ import { isFalsy as e, isValidNumberString as t } from "./boolean.mjs";
|
|
|
2
2
|
import { formatNumber as n, formatSecondsToChinese as r } from "./number.mjs";
|
|
3
3
|
import { getFilenameFromUrl as i, queryStringToObject as a, stringDisplay as o } from "./string.mjs";
|
|
4
4
|
import { aesDecrypt as s, aesEncrypt as c, saveAs as l } from "./tool.mjs";
|
|
5
|
-
|
|
5
|
+
import { flatArrToTree as u, treeToFlatArr as d } from "./tree.mjs";
|
|
6
|
+
export { s as aesDecrypt, c as aesEncrypt, u as flatArrToTree, n as formatNumber, r as formatSecondsToChinese, i as getFilenameFromUrl, e as isFalsy, t as isValidNumberString, a as queryStringToObject, l as saveAs, o as stringDisplay, d as treeToFlatArr };
|
package/utils/tree.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
interface TreeNode {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
children?: TreeNode[];
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 将扁平数组转换为树形结构
|
|
7
|
+
* @param data 扁平数据数组
|
|
8
|
+
* @param options 配置选项
|
|
9
|
+
* @param options.childrenKey 子节点键名
|
|
10
|
+
* @param options.idKey 节点ID键名
|
|
11
|
+
* @param options.parentKey 节点父ID键名
|
|
12
|
+
* @param options.rootParentId 根节点ID键名
|
|
13
|
+
* @returns 树形结构数组
|
|
14
|
+
*/
|
|
15
|
+
export declare function flatArrToTree(data: Record<string, any>[], options?: {
|
|
16
|
+
childrenKey?: string;
|
|
17
|
+
idKey?: string;
|
|
18
|
+
parentKey?: string;
|
|
19
|
+
rootParentId?: null | string;
|
|
20
|
+
}): TreeNode[];
|
|
21
|
+
export declare function treeToFlatArr(tree: TreeNode[], options?: {
|
|
22
|
+
idKey?: string;
|
|
23
|
+
includeLevel?: boolean;
|
|
24
|
+
includeParent?: boolean;
|
|
25
|
+
}): Record<string, any>[];
|
|
26
|
+
export {};
|
package/utils/tree.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/utils/tree.ts
|
|
2
|
+
function e(e, t = {}) {
|
|
3
|
+
let { childrenKey: n = "children", idKey: r = "id", parentKey: i = "parentId", rootParentId: a = null } = t;
|
|
4
|
+
if (!Array.isArray(e)) throw TypeError("flatArrToTree: 输入参数 data 必须是数组");
|
|
5
|
+
if (e.length === 0) return [];
|
|
6
|
+
let o = [], s = /* @__PURE__ */ new Map();
|
|
7
|
+
for (let t of e) {
|
|
8
|
+
let e = t[r];
|
|
9
|
+
if (e == null) {
|
|
10
|
+
console.warn(`flatArrToTree: 数据项缺少 ${r} 属性`, t);
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
let n = {
|
|
14
|
+
...t,
|
|
15
|
+
children: []
|
|
16
|
+
};
|
|
17
|
+
s.has(e) && console.warn(`flatArrToTree: 检测到重复的 ${r}: ${e}`), s.set(e, n);
|
|
18
|
+
}
|
|
19
|
+
for (let [e, t] of s) {
|
|
20
|
+
let e = t[i];
|
|
21
|
+
e == null || e === a || !s.has(e) ? o.push(t) : s.get(e)[n].push(t);
|
|
22
|
+
}
|
|
23
|
+
return o;
|
|
24
|
+
}
|
|
25
|
+
function t(e, t) {
|
|
26
|
+
let { idKey: n = "id", includeLevel: r = !1, includeParent: i = !1 } = t ?? {}, a = [];
|
|
27
|
+
function o(e, t = 0, s = null) {
|
|
28
|
+
Array.isArray(e) && e.forEach((e) => {
|
|
29
|
+
let { children: c, ...l } = e;
|
|
30
|
+
r && (l.level = t), i && (l.parentId = s), a.push(l), Array.isArray(c) && o(c, t + 1, e[n]);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return o(e), a;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { e as flatArrToTree, t as treeToFlatArr };
|