Commit d8ff30d9ece53e006e5e58894461adeeb3b273e0
Committed by
GitHub
1 parent
3ef5087b
fix(tree): onCheck event lose origin param (#636)
修复Tree的onCheck事件缺少节点参数的问题
Showing
3 changed files
with
18 additions
and
5 deletions
src/components/Tree/src/index.vue
... | ... | @@ -30,6 +30,8 @@ |
30 | 30 | import { basicProps } from './props'; |
31 | 31 | import { CreateContextOptions } from '/@/components/ContextMenu'; |
32 | 32 | |
33 | + import { CheckEvent } from './types'; | |
34 | + | |
33 | 35 | interface State { |
34 | 36 | expandedKeys: Keys; |
35 | 37 | selectedKeys: Keys; |
... | ... | @@ -87,11 +89,11 @@ |
87 | 89 | state.selectedKeys = v; |
88 | 90 | emit('update:selectedKeys', v); |
89 | 91 | }, |
90 | - onCheck: (v: CheckKeys) => { | |
92 | + onCheck: (v: CheckKeys, e: CheckEvent) => { | |
91 | 93 | state.checkedKeys = v; |
92 | 94 | const rawVal = toRaw(v); |
93 | 95 | emit('update:value', rawVal); |
94 | - emit('check', rawVal); | |
96 | + emit('check', rawVal, e); | |
95 | 97 | }, |
96 | 98 | onRightClick: handleRightClick, |
97 | 99 | }; | ... | ... |
src/components/Tree/src/types.ts
1 | -import type { TreeDataItem } from 'ant-design-vue/es/tree/Tree'; | |
1 | +import type { TreeDataItem, CheckEvent as CheckEventOrigin } from 'ant-design-vue/es/tree/Tree'; | |
2 | 2 | import { ContextMenuItem } from '/@/hooks/web/useContextMenu'; |
3 | 3 | export interface ActionItem { |
4 | 4 | render: (record: Recordable) => any; |
... | ... | @@ -47,3 +47,5 @@ export interface ContextMenuOptions { |
47 | 47 | styles?: any; |
48 | 48 | items?: ContextMenuItem[]; |
49 | 49 | } |
50 | + | |
51 | +export type CheckEvent = CheckEventOrigin; | ... | ... |
src/views/demo/tree/index.vue
... | ... | @@ -3,7 +3,13 @@ |
3 | 3 | <div class="flex"> |
4 | 4 | <BasicTree :treeData="treeData" title="基础示例" class="w-1/3" /> |
5 | 5 | |
6 | - <BasicTree :treeData="treeData" title="可勾选" :checkable="true" class="w-1/3 mx-4" /> | |
6 | + <BasicTree | |
7 | + :treeData="treeData" | |
8 | + title="可勾选" | |
9 | + :checkable="true" | |
10 | + class="w-1/3 mx-4" | |
11 | + @check="handleCheck" | |
12 | + /> | |
7 | 13 | |
8 | 14 | <BasicTree |
9 | 15 | title="默认展开/勾选示例" |
... | ... | @@ -25,7 +31,10 @@ |
25 | 31 | export default defineComponent({ |
26 | 32 | components: { BasicTree, PageWrapper }, |
27 | 33 | setup() { |
28 | - return { treeData }; | |
34 | + function handleCheck(checkedKeys, e) { | |
35 | + console.log('onChecked', checkedKeys, e); | |
36 | + } | |
37 | + return { treeData, handleCheck }; | |
29 | 38 | }, |
30 | 39 | }); |
31 | 40 | </script> | ... | ... |