Browse Source

types(BasicTable): 优化 slot 类型提示

main
刘凯 9 months ago
parent
commit
de206f44ce
  1. 4
      src/components/Table/src/BasicTable.vue
  2. 11
      src/components/Table/src/types/table.ts

4
src/components/Table/src/BasicTable.vue

@ -3,7 +3,7 @@
import { computed, inject, ref, toRaw, unref, useAttrs, useSlots, watchEffect } from 'vue'
import { Table } from 'ant-design-vue'
import { omit } from 'lodash-es'
import type { BasicTableProps, ColumnChangeParam, InnerHandlers, SizeType, SlotBodyCellProps, TableActionType } from './types/table'
import type { BasicTableProps, ColumnChangeParam, InnerHandlers, SizeType, SlotBodyCellProps, TableActionType, TableSlotNames } from './types/table'
import HeaderCell from './components/HeaderCell.vue'
import ExpandIcon from './components/ExpandIcon.vue'
import { usePagination } from './hooks/usePagination'
@ -319,7 +319,7 @@ else {
@change="handleTableChange"
@resize-column="setColumnWidth"
>
<template v-for="item in Object.keys($slots)" #[item]="data" :key="item">
<template v-for="item in (Object.keys($slots) as TableSlotNames[])" #[item]="data" :key="item">
<!-- eslint-disable-next-line vue/no-extra-parens -->
<slot :name="item" v-bind="((data || {}) as SlotBodyCellProps<T>)" />
</template>

11
src/components/Table/src/types/table.ts

@ -508,3 +508,14 @@ export interface InnerHandlers {
export type SlotBodyCellProps<T> =
& Omit<Parameters<Required<InstanceType<typeof Table>['$slots']>['bodyCell']>[0], 'record'>
& { record: EditRecordRow<T> }
export type TableSlotNames =
| keyof Omit<
InstanceType<typeof Table>['$slots'],
| 'headerCell'
| 'bodyCell'
| 'expandIcon'
| 'default'
>
| 'tableTitle'
| 'headerTop'

Loading…
Cancel
Save