arms-app 1.0.83 → 1.0.84
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/public/3.d +38 -0
- package/public/1.d +0 -29
package/package.json
CHANGED
package/public/3.d
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue2 树形结构中,根据 id 数组修改 disabled(使用 this.$set)
|
|
3
|
+
* @param {Array} tree - 树形数据(原数组)
|
|
4
|
+
* @param {Array<string|number>} ids - 命中的 id 数组
|
|
5
|
+
* @param {boolean} disabledValue - 要设置的 disabled 值
|
|
6
|
+
* @param {string} idKey - id 字段名,默认 'id'
|
|
7
|
+
* @param {string} childrenKey - children 字段名,默认 'children'
|
|
8
|
+
*/
|
|
9
|
+
function setDisabledInTreeVue2(
|
|
10
|
+
tree,
|
|
11
|
+
ids,
|
|
12
|
+
disabledValue = true,
|
|
13
|
+
idKey = 'id',
|
|
14
|
+
childrenKey = 'children'
|
|
15
|
+
) {
|
|
16
|
+
const idSet = new Set(ids);
|
|
17
|
+
|
|
18
|
+
const dfs = (nodes, vm) => {
|
|
19
|
+
if (!Array.isArray(nodes)) return;
|
|
20
|
+
|
|
21
|
+
nodes.forEach((node) => {
|
|
22
|
+
if (!node || typeof node !== 'object') return;
|
|
23
|
+
|
|
24
|
+
// 命中 id,用 $set 保证响应式
|
|
25
|
+
if (idSet.has(node[idKey])) {
|
|
26
|
+
vm.$set(node, 'disabled', disabledValue);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 递归 children
|
|
30
|
+
const children = node[childrenKey];
|
|
31
|
+
if (Array.isArray(children)) {
|
|
32
|
+
dfs(children, vm);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
dfs(tree, this);
|
|
38
|
+
}
|
package/public/1.d
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
}
|
|
21
|
-
|
|
22
|
-
const children = node[childrenKey];
|
|
23
|
-
if (Array.isArray(children)) {
|
|
24
|
-
for (let i = 0; i < children.length; i++) stack.push(children[i]);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return tree;
|
|
29
|
-
}
|