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,6 +30,8 @@ | ||
30 | import { basicProps } from './props'; | 30 | import { basicProps } from './props'; |
31 | import { CreateContextOptions } from '/@/components/ContextMenu'; | 31 | import { CreateContextOptions } from '/@/components/ContextMenu'; |
32 | 32 | ||
33 | + import { CheckEvent } from './types'; | ||
34 | + | ||
33 | interface State { | 35 | interface State { |
34 | expandedKeys: Keys; | 36 | expandedKeys: Keys; |
35 | selectedKeys: Keys; | 37 | selectedKeys: Keys; |
@@ -87,11 +89,11 @@ | @@ -87,11 +89,11 @@ | ||
87 | state.selectedKeys = v; | 89 | state.selectedKeys = v; |
88 | emit('update:selectedKeys', v); | 90 | emit('update:selectedKeys', v); |
89 | }, | 91 | }, |
90 | - onCheck: (v: CheckKeys) => { | 92 | + onCheck: (v: CheckKeys, e: CheckEvent) => { |
91 | state.checkedKeys = v; | 93 | state.checkedKeys = v; |
92 | const rawVal = toRaw(v); | 94 | const rawVal = toRaw(v); |
93 | emit('update:value', rawVal); | 95 | emit('update:value', rawVal); |
94 | - emit('check', rawVal); | 96 | + emit('check', rawVal, e); |
95 | }, | 97 | }, |
96 | onRightClick: handleRightClick, | 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 | import { ContextMenuItem } from '/@/hooks/web/useContextMenu'; | 2 | import { ContextMenuItem } from '/@/hooks/web/useContextMenu'; |
3 | export interface ActionItem { | 3 | export interface ActionItem { |
4 | render: (record: Recordable) => any; | 4 | render: (record: Recordable) => any; |
@@ -47,3 +47,5 @@ export interface ContextMenuOptions { | @@ -47,3 +47,5 @@ export interface ContextMenuOptions { | ||
47 | styles?: any; | 47 | styles?: any; |
48 | items?: ContextMenuItem[]; | 48 | items?: ContextMenuItem[]; |
49 | } | 49 | } |
50 | + | ||
51 | +export type CheckEvent = CheckEventOrigin; |
src/views/demo/tree/index.vue
@@ -3,7 +3,13 @@ | @@ -3,7 +3,13 @@ | ||
3 | <div class="flex"> | 3 | <div class="flex"> |
4 | <BasicTree :treeData="treeData" title="基础示例" class="w-1/3" /> | 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 | <BasicTree | 14 | <BasicTree |
9 | title="默认展开/勾选示例" | 15 | title="默认展开/勾选示例" |
@@ -25,7 +31,10 @@ | @@ -25,7 +31,10 @@ | ||
25 | export default defineComponent({ | 31 | export default defineComponent({ |
26 | components: { BasicTree, PageWrapper }, | 32 | components: { BasicTree, PageWrapper }, |
27 | setup() { | 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 | </script> | 40 | </script> |