Skip to content

Commit

Permalink
refactor: 🎨add type
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjone committed May 11, 2023
1 parent 373ebd2 commit 2a18cf9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
7 changes: 6 additions & 1 deletion demo/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
ellipsis
/>

<x-gantt-slider prop="name"></x-gantt-slider>
<x-gantt-slider prop="name" :move="onMove"></x-gantt-slider>
</x-gantt>
</div>

Expand Down Expand Up @@ -120,6 +120,11 @@ function onReduce() {
const onClickRow = (data: any) => {
console.log('click row', data);
};
function onMove(data: any) {
console.log('move', data);
return true;
}
</script>

<style scoped></style>
4 changes: 3 additions & 1 deletion src/components/slider/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export default {
* 允许移动
*/
move: {
type: [Function, Boolean],
type: [Function, Boolean] as PropType<
boolean | ((data: RowData) => boolean)
>,
default: () => false
},

Expand Down
2 changes: 1 addition & 1 deletion src/composables/useData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default () => {
);
}

function toRowData(data?: RowItem) {
function toRowData(data?: RowItem): RowData {
return {
row: data?.data,
$index: data?.flatIndex
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useSlotsBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default () => {
const { toRowData } = useData();

function isMerge(
m: boolean | undefined | ((data: any) => boolean),
m: boolean | undefined | ((data: RowData) => boolean),
data: RowItem
) {
return typeof m === 'function' ? m(toRowData(data)) : !!m;
Expand Down
7 changes: 7 additions & 0 deletions src/typings/data.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* 事件抛出的数据
*/
declare interface RowData {
row?: any;
$index?: number;
}

0 comments on commit 2a18cf9

Please sign in to comment.