Skip to content

Commit

Permalink
feat: ✨add checkbox event
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjone committed May 16, 2023
1 parent 4839744 commit 9e33b68
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
5 changes: 5 additions & 0 deletions demo/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:show-weekend="true"
@row-click="onClickRow"
@row-dbl-click="onDblClickRow"
@row-checked="onCheckedRow"
@move-slider="onMoveSlider"
@add-link="onAddLink"
@click-link="onClickLink"
Expand Down Expand Up @@ -195,6 +196,10 @@ const onDblClickRow = (data: any) => {
console.log('dblclick row', data);
};
const onCheckedRow = (state: boolean, data: any) => {
console.log('checked row', state, data);
};
const onMoveSlider = (data: any) => {
console.log('move slider', data);
};
Expand Down
18 changes: 13 additions & 5 deletions src/components/column/selection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@
</template>

<script lang="ts" setup>
import { PropType, ref } from 'vue';
import { PropType, ref, watch } from 'vue';
import useStyle from '@/composables/useStyle';
import useData from '@/composables/useData';
import RowItem from '@/models/data/row';
import Icon from '../common/Icon.vue';
import useEvent from '@/composables/useEvent';
const { rowHeight, $styleBox } = useStyle();
const checked = ref(false);
defineProps({
const props = defineProps({
data: {
type: Object as PropType<RowItem>,
default: () => ({})
Expand All @@ -43,6 +41,16 @@ defineProps({
}
});
const { rowHeight, $styleBox } = useStyle();
const checked = ref(false);
const { EmitRowChecked } = useEvent();
watch(
() => checked.value,
val => {
EmitRowChecked(val, props.data);
}
);
const { flattenData } = useData();
</script>

Expand Down
7 changes: 3 additions & 4 deletions src/composables/useEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default () => {
rootEmit.value?.('row-click', toRaw(row));
}

// (e: 'row-dbl-click', data: any): void;
/**
* 双击行事件
* @param row 该行的原始数据
Expand All @@ -26,13 +25,13 @@ export default () => {
rootEmit.value?.('row-dbl-click', toRaw(row));
}

// (e: 'row-checked', state: boolean, data: any): void;
/**
* 选择行事件 checkbox
* @param state 选择状态
* @param row 该行的原始数据
*/
function EmitRowChecked(row: any) {
rootEmit.value?.('row-checked', toRaw(row));
function EmitRowChecked(state: boolean, row: any) {
rootEmit.value?.('row-checked', state, toRaw(row));
}

/**
Expand Down

0 comments on commit 9e33b68

Please sign in to comment.