arms-app 1.0.81 → 1.0.83

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/1.d +23 -37
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arms-app",
3
- "version": "1.0.81",
3
+ "version": "1.0.83",
4
4
  "description": "一个基于 Express 的 Web 应用1",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/public/1.d CHANGED
@@ -1,43 +1,29 @@
1
- function listToTree(list) {
2
- const map = new Map();
3
- const tree = [];
4
-
5
- // 1. 初始化 map
6
- list.forEach(item => {
7
- map.set(item.id, { ...item, children: [] });
8
- });
9
-
10
- // 2. 组装父子关系
11
- list.forEach(item => {
12
- const node = map.get(item.id);
13
- const parentId = item.parentId;
14
-
15
- // parentId null / undefined / 不存在于 map → 根节点
16
- if (parentId == null || !map.has(parentId)) {
17
- tree.push(node);
18
- } else {
19
- map.get(parentId).children.push(node);
1
+ /**
2
+ * 原地修改树:把 id 命中的节点 disabled 设置为指定值
3
+ * @param {Array} tree
4
+ * @param {Array<string|number>} ids
5
+ * @param {boolean} disabledValue
6
+ * @param {string} idKey
7
+ * @param {string} childrenKey
8
+ * @returns {Array} tree(同一个引用)
9
+ */
10
+ function setDisabledInTreeMutate(tree, ids, disabledValue = true, idKey = 'id', childrenKey = 'children') {
11
+ const idSet = new Set(ids);
12
+
13
+ const stack = Array.isArray(tree) ? [...tree] : [];
14
+ while (stack.length) {
15
+ const node = stack.pop();
16
+ if (!node || typeof node !== 'object') continue;
17
+
18
+ if (idSet.has(node[idKey])) {
19
+ node.disabled = disabledValue;
20
20
  }
21
- });
22
-
23
- return tree;
24
- }
25
- function treeToList(tree) {
26
- const result = [];
27
-
28
- function traverse(node, parentId = null) {
29
- const { children, ...rest } = node;
30
21
 
31
- result.push({
32
- ...rest,
33
- parentId
34
- });
35
-
36
- if (children && children.length) {
37
- children.forEach(child => traverse(child, node.id));
22
+ const children = node[childrenKey];
23
+ if (Array.isArray(children)) {
24
+ for (let i = 0; i < children.length; i++) stack.push(children[i]);
38
25
  }
39
26
  }
40
27
 
41
- tree.forEach(root => traverse(root, null));
42
- return result;
28
+ return tree;
43
29
  }