Skip to content

Commit

Permalink
feat: ✨add dbl click event
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjone committed May 16, 2023
1 parent 67699ee commit 4839744
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
5 changes: 5 additions & 0 deletions demo/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:show-today="true"
:show-weekend="true"
@row-click="onClickRow"
@row-dbl-click="onDblClickRow"
@move-slider="onMoveSlider"
@add-link="onAddLink"
@click-link="onClickLink"
Expand Down Expand Up @@ -190,6 +191,10 @@ const onClickRow = (data: any) => {
console.log('click row', data);
};
const onDblClickRow = (data: any) => {
console.log('dblclick row', data);
};
const onMoveSlider = (data: any) => {
console.log('move slider', data);
};
Expand Down
26 changes: 19 additions & 7 deletions src/components/common/Row.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
@mouseenter.capture="onEnter"
@mouseleave="onLeave"
@click="onClick"
@dblclick="onDblClick"
>
<slot />
</div>
Expand Down Expand Up @@ -52,14 +51,27 @@ function onLeave() {
$param.hoverItem = null;
}
const { EmitRowClick } = useEvent();
const { EmitRowClick, EmitRowDblClick } = useEvent();
let clicks = 0;
const delay = 300;
let timer: any = null;
function onClick() {
$param.selectItem = props.data ?? null;
EmitRowClick(props.data?.data);
}
clicks++;
if (clicks === 1) {
// click
timer = setTimeout(() => {
clicks = 0;
}, delay);
$param.selectItem = props.data ?? null;
EmitRowClick(props.data?.data);
} else {
// dbl-click
clearTimeout(timer);
clicks = 0;
function onDblClick() {
// 抛出 data
EmitRowDblClick(props.data?.data);
}
}
</script>

Expand Down
23 changes: 20 additions & 3 deletions src/composables/useEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@ export default () => {
}

// (e: 'row-dbl-click', data: any): void;
/**
* 双击行事件
* @param row 该行的原始数据
*/
function EmitRowDblClick(row: any) {
rootEmit.value?.('row-dbl-click', toRaw(row));
}

// (e: 'row-checked', state: boolean, data: any): void;
// (e: 'move-slider', { row: any; old: { start: Date; end: Date } }[]): void;
// (e: 'move-progress', data: any, old: number): void;
// (e: 'no-date-error'): void;
/**
* 选择行事件 checkbox
* @param row 该行的原始数据
*/
function EmitRowChecked(row: any) {
rootEmit.value?.('row-checked', toRaw(row));
}

/**
* 移动滑块事件
Expand All @@ -47,9 +59,14 @@ export default () => {
rootEmit.value?.('add-link', data);
}

// (e: 'move-progress', data: any, old: number): void;
// (e: 'no-date-error'): void;

return {
setRootEmit,
EmitRowClick,
EmitRowDblClick,
EmitRowChecked,
EmitMoveSlider,
EmitAddLink
};
Expand Down

0 comments on commit 4839744

Please sign in to comment.