Commit ddd1893b113e13786037522341abb2e75f8f9d5b
1 parent
e8eefd1b
fix(tree): fix `checkAll` effects `disabled` node
Showing
3 changed files
with
21 additions
and
1 deletions
CHANGELOG.zh_CN.md
@@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
9 | - **ImgRotateDragVerify** 修复组件`resume`方法无法调用的问题 | 9 | - **ImgRotateDragVerify** 修复组件`resume`方法无法调用的问题 |
10 | - **TableAction** 修复 stopButtonPropagation 属性某些情况下不起作用的问题 | 10 | - **TableAction** 修复 stopButtonPropagation 属性某些情况下不起作用的问题 |
11 | - **PageWrapper** 修复`class`属性无效的问题 | 11 | - **PageWrapper** 修复`class`属性无效的问题 |
12 | +- **BasicTree** 修复`checkAll`方法会影响到`disabled`状态节点的问题 | ||
12 | - **BasicTable** | 13 | - **BasicTable** |
13 | - 修复可编辑单元格不支持`ellipsis`配置的问题 | 14 | - 修复可编辑单元格不支持`ellipsis`配置的问题 |
14 | - 修复全屏模式下看不到子组件弹出层(popconfirm 以及 select、treeSelect 等编辑组件)的问题 | 15 | - 修复全屏模式下看不到子组件弹出层(popconfirm 以及 select、treeSelect 等编辑组件)的问题 |
src/components/Tree/src/Tree.vue
@@ -127,6 +127,7 @@ | @@ -127,6 +127,7 @@ | ||
127 | updateNodeByKey, | 127 | updateNodeByKey, |
128 | getAllKeys, | 128 | getAllKeys, |
129 | getChildrenKeys, | 129 | getChildrenKeys, |
130 | + getEnabledKeys, | ||
130 | } = useTree(treeDataRef, getReplaceFields); | 131 | } = useTree(treeDataRef, getReplaceFields); |
131 | 132 | ||
132 | function getIcon(params: Recordable, icon?: string) { | 133 | function getIcon(params: Recordable, icon?: string) { |
@@ -180,7 +181,7 @@ | @@ -180,7 +181,7 @@ | ||
180 | } | 181 | } |
181 | 182 | ||
182 | function checkAll(checkAll: boolean) { | 183 | function checkAll(checkAll: boolean) { |
183 | - state.checkedKeys = checkAll ? getAllKeys() : ([] as Keys); | 184 | + state.checkedKeys = checkAll ? getEnabledKeys() : ([] as Keys); |
184 | } | 185 | } |
185 | 186 | ||
186 | function expandAll(expandAll: boolean) { | 187 | function expandAll(expandAll: boolean) { |
src/components/Tree/src/useTree.ts
@@ -26,6 +26,23 @@ export function useTree( | @@ -26,6 +26,23 @@ export function useTree( | ||
26 | } | 26 | } |
27 | return keys as Keys; | 27 | return keys as Keys; |
28 | } | 28 | } |
29 | + // get keys that can be checked and selected | ||
30 | + function getEnabledKeys(list?: TreeDataItem[]) { | ||
31 | + const keys: string[] = []; | ||
32 | + const treeData = list || unref(treeDataRef); | ||
33 | + const { key: keyField, children: childrenField } = unref(getReplaceFields); | ||
34 | + if (!childrenField || !keyField) return keys; | ||
35 | + | ||
36 | + for (let index = 0; index < treeData.length; index++) { | ||
37 | + const node = treeData[index]; | ||
38 | + node.disabled !== true && node.selectable !== false && keys.push(node[keyField]!); | ||
39 | + const children = node[childrenField]; | ||
40 | + if (children && children.length) { | ||
41 | + keys.push(...(getEnabledKeys(children) as string[])); | ||
42 | + } | ||
43 | + } | ||
44 | + return keys as Keys; | ||
45 | + } | ||
29 | 46 | ||
30 | function getChildrenKeys(nodeKey: string | number, list?: TreeDataItem[]): Keys { | 47 | function getChildrenKeys(nodeKey: string | number, list?: TreeDataItem[]): Keys { |
31 | const keys: Keys = []; | 48 | const keys: Keys = []; |
@@ -169,5 +186,6 @@ export function useTree( | @@ -169,5 +186,6 @@ export function useTree( | ||
169 | updateNodeByKey, | 186 | updateNodeByKey, |
170 | getAllKeys, | 187 | getAllKeys, |
171 | getChildrenKeys, | 188 | getChildrenKeys, |
189 | + getEnabledKeys, | ||
172 | }; | 190 | }; |
173 | } | 191 | } |