Skip to content

Commit

Permalink
fix(tree): onCheck event lose origin param (#636)
Browse files Browse the repository at this point in the history
修复Tree的onCheck事件缺少节点参数的问题
  • Loading branch information
mynetfan committed May 22, 2021
1 parent 3ef5087 commit d8ff30d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/components/Tree/src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import { basicProps } from './props';
import { CreateContextOptions } from '/@/components/ContextMenu';
import { CheckEvent } from './types';
interface State {
expandedKeys: Keys;
selectedKeys: Keys;
Expand Down Expand Up @@ -87,11 +89,11 @@
state.selectedKeys = v;
emit('update:selectedKeys', v);
},
onCheck: (v: CheckKeys) => {
onCheck: (v: CheckKeys, e: CheckEvent) => {
state.checkedKeys = v;
const rawVal = toRaw(v);
emit('update:value', rawVal);
emit('check', rawVal);
emit('check', rawVal, e);
},
onRightClick: handleRightClick,
};
Expand Down
4 changes: 3 additions & 1 deletion src/components/Tree/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TreeDataItem } from 'ant-design-vue/es/tree/Tree';
import type { TreeDataItem, CheckEvent as CheckEventOrigin } from 'ant-design-vue/es/tree/Tree';
import { ContextMenuItem } from '/@/hooks/web/useContextMenu';
export interface ActionItem {
render: (record: Recordable) => any;
Expand Down Expand Up @@ -47,3 +47,5 @@ export interface ContextMenuOptions {
styles?: any;
items?: ContextMenuItem[];
}

export type CheckEvent = CheckEventOrigin;
13 changes: 11 additions & 2 deletions src/views/demo/tree/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
<div class="flex">
<BasicTree :treeData="treeData" title="基础示例" class="w-1/3" />

<BasicTree :treeData="treeData" title="可勾选" :checkable="true" class="w-1/3 mx-4" />
<BasicTree
:treeData="treeData"
title="可勾选"
:checkable="true"
class="w-1/3 mx-4"
@check="handleCheck"
/>

<BasicTree
title="默认展开/勾选示例"
Expand All @@ -25,7 +31,10 @@
export default defineComponent({
components: { BasicTree, PageWrapper },
setup() {
return { treeData };
function handleCheck(checkedKeys, e) {
console.log('onChecked', checkedKeys, e);
}
return { treeData, handleCheck };
},
});
</script>

0 comments on commit d8ff30d

Please sign in to comment.