index.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { VNode, ComponentPublicInstance, Ref } from 'vue'
  2. import { BreakPoint, Responsive } from '@/components/Grid/interface'
  3. import { TableColumnCtx } from 'element-plus/es/components/table/src/table-column/defaults'
  4. import ProTableProps from '@/components/ProTable/index.vue'
  5. import ProTable from '@/components/ProTable/index.vue'
  6. export interface EnumProps {
  7. label?: string // 选项框显示的文字
  8. value?: string | number | boolean | any[] // 选项框值
  9. disabled?: boolean // 是否禁用此选项
  10. tagType?: string // 当 tag 为 true 时,此选择会指定 tag 显示类型
  11. children?: EnumProps[] // 为树形选择时,可以通过 children 属性指定子选项
  12. [key: string]: any
  13. }
  14. export type TypeProps = 'index' | 'selection' | 'radio' | 'expand' | 'sort'
  15. export type SearchType =
  16. | 'input'
  17. | 'input-number'
  18. | 'select'
  19. | 'select-v2'
  20. | 'tree-select'
  21. | 'cascader'
  22. | 'date-picker'
  23. | 'time-picker'
  24. | 'time-select'
  25. | 'switch'
  26. | 'slider'
  27. export type SearchRenderScope = {
  28. searchParam: { [key: string]: any }
  29. placeholder: string
  30. clearable: boolean
  31. options: EnumProps[]
  32. data: EnumProps[]
  33. }
  34. export type SearchProps = {
  35. el?: SearchType // 当前项搜索框的类型
  36. label?: string // 当前项搜索框的 label
  37. props?: any // 搜索项参数,根据 element plus 官方文档来传递,该属性所有值会透传到组件
  38. key?: string // 当搜索项 key 不为 prop 属性时,可通过 key 指定
  39. tooltip?: string // 搜索提示
  40. order?: number // 搜索项排序(从大到小)
  41. span?: number // 搜索项所占用的列数,默认为 1 列
  42. offset?: number // 搜索字段左侧偏移列数
  43. defaultValue?: string | number | boolean | any[] | Ref<any> // 搜索项默认值
  44. render?: (scope: SearchRenderScope) => VNode // 自定义搜索内容渲染(tsx语法)
  45. } & Partial<Record<BreakPoint, Responsive>>
  46. export type FieldNamesProps = {
  47. label: string
  48. value: string
  49. children?: string
  50. }
  51. export type RenderScope<T> = {
  52. row: T
  53. $index: number
  54. column: TableColumnCtx<T>
  55. [key: string]: any
  56. }
  57. export type HeaderRenderScope<T> = {
  58. $index: number
  59. column: TableColumnCtx<T>
  60. [key: string]: any
  61. }
  62. export interface ColumnProps<T = any> extends Partial<Omit<TableColumnCtx<T>, 'type' | 'children' | 'renderCell' | 'renderHeader'>> {
  63. type?: TypeProps // 列类型
  64. tag?: boolean | Ref<boolean> // 是否是标签展示
  65. isShow?: boolean | Ref<boolean> // 是否显示在表格当中
  66. search?: SearchProps | undefined // 搜索项配置
  67. enum?: EnumProps[] | Ref<EnumProps[]> | ((params?: any) => Promise<any>) // 枚举字典
  68. isFilterEnum?: boolean | Ref<boolean> // 当前单元格值是否根据 enum 格式化(示例:enum 只作为搜索项数据)
  69. fieldNames?: FieldNamesProps // 指定 label && value && children 的 key 值
  70. headerRender?: (scope: HeaderRenderScope<T>) => VNode // 自定义表头内容渲染(tsx语法)
  71. render?: (scope: RenderScope<T>) => VNode | string // 自定义单元格内容渲染(tsx语法)
  72. _children?: ColumnProps<T>[] // 多级表头
  73. }
  74. export type ProTableInstance = Omit<InstanceType<typeof ProTable>, keyof ComponentPublicInstance | keyof ProTableProps>