components.d.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. declare module 'global-type' {
  2. import {
  3. ElTable,
  4. ElTableColumn,
  5. ElInput,
  6. ElInputNumber,
  7. ElAutocomplete,
  8. ElSwitch,
  9. ElRadioGroup,
  10. ElRadio,
  11. ElCheckboxGroup,
  12. ElCheckbox,
  13. ElSelect,
  14. ElOptionGroup,
  15. ElOption,
  16. ElDatePicker,
  17. ElForm,
  18. ElFormItem,
  19. ElRow,
  20. ElCol,
  21. ElCheckboxButton,
  22. ElRadioButton,
  23. } from 'element-plus'
  24. import type { VNode, Component, DefineComponent, VNodeProps } from 'vue'
  25. import BaseTable from '@/components/element/BaseTable.vue'
  26. import BaseForm from '@/components/element/BaseForm.vue'
  27. import BaseSelect from '@/components/element/BaseSelect.vue'
  28. import BaseCheckBox from '@/components/element/BaseCheckBox.vue'
  29. import BaseRadio from '@/components/element/BaseRadio.vue'
  30. import type {
  31. TableProps,
  32. FormProps,
  33. FormItemProps,
  34. InputProps,
  35. InputNumberProps,
  36. RadioProps,
  37. CheckboxProps,
  38. AutocompleteProps,
  39. SwitchProps,
  40. FormRules,
  41. FormItemRule,
  42. RowProps,
  43. ColProps,
  44. SelectOptionProxy,
  45. } from 'element-plus'
  46. import type { TableColumnCtx } from 'element-plus/es/components/table/src/table-column/defaults'
  47. import MarkHeaderVue from '@/components/shared/MarkHeader.vue'
  48. export type MarkHeaderInstance = InstanceType<typeof MarkHeaderVue>
  49. export type ExtractComponentProps<T extends DefineComponent> = Mutable<
  50. Omit<InstanceType<T>['$props'], keyof VNodeProps>
  51. >
  52. export type CI<T> = {
  53. column: TableColumnCtx<T>
  54. $index: number
  55. }
  56. export type Filters = {
  57. text: string
  58. value: string
  59. }[]
  60. export type FilterMethods<T> = (value: any, row: T, column: TableColumnCtx<T>) => void
  61. export interface EpTableProps<T = any>
  62. extends AssignKeys<ExtractComponentProps<typeof ElTable>, Partial<TableProps<T>>> {
  63. columns?: EpTableColumn<T>[]
  64. }
  65. export type EpTableColumn<T = any> = AssignKeys<
  66. ExtractComponentProps<typeof ElTableColumn>,
  67. Partial<{
  68. type: 'selection' | 'index' | 'expand'
  69. renderHeader: (data: CI<T>) => VNode
  70. sortMethod: (a: T, b: T) => number
  71. sortBy: string | ((row: T, index: number) => string) | string[]
  72. formatter: (row: T, column: TableColumnCtx<T>, cellValue: any, index: number) => VNode | string
  73. align: 'left' | 'center' | 'right'
  74. headerAlign: 'left' | 'center' | 'right'
  75. selectable: (row: T, index: number) => boolean
  76. filters: Filters
  77. filterMethod: FilterMethods<T>
  78. }>
  79. > & { slotName?: string }
  80. export interface FormSupportComponentMap {
  81. input: typeof ElInput
  82. inputNumber: typeof ElInputNumber
  83. autocomplete: typeof ElAutocomplete
  84. switch: typeof ElSwitch
  85. radio: typeof BaseRadio
  86. checkbox: typeof BaseCheckBox
  87. select: typeof BaseSelect
  88. date: typeof ElDatePicker
  89. dateTime: any
  90. }
  91. export type ElFormItemProps = Omit<
  92. AssignKeys<ExtractComponentProps<typeof ElFormItem>, Partial<FormItemProps>>,
  93. 'lineMessage'
  94. >
  95. export type FormItemCustomProp<T extends keyof FormSupportComponentMap, U extends Record<string, unknown>> = {
  96. hidden?: boolean
  97. slotType?: T
  98. slotName?: string
  99. slot?: Partial<AssignKeys<ExtractComponentProps<FormSupportComponentMap[T]>, Mutable<U>>>
  100. }
  101. export type WithCustomProp<T extends keyof FormSupportComponentMap, U extends Record<string, unknown>> = AssignKeys<
  102. ElFormItemProps,
  103. FormItemCustomProp<T, U>
  104. >
  105. export type FormItemInput = WithCustomProp<'input', InputProps>
  106. export type FormItemInputNumber = WithCustomProp<'inputNumber', InputNumberProps>
  107. export type FormItemAutocomplete = WithCustomProp<'autocomplete', AutocompleteProps>
  108. export type FormItemSwitch = WithCustomProp<'switch', SwitchProps>
  109. export type BaseRadioProp = AssignKeys<
  110. ExtractComponentProps<typeof ElRadio>,
  111. RadioProps & { slotLabel?: string | VNode }
  112. >
  113. export type BaseRadioButtonProp = AssignKeys<
  114. ExtractComponentProps<typeof ElRadioButton>,
  115. { slotLabel?: string | VNode }
  116. >
  117. export type FormItemRadioCustomOptions = BaseRadioProp[] | BaseRadioButtonProp[]
  118. export type FormItemRadioCustomProp = AssignKeys<
  119. ExtractComponentProps<typeof ElRadioGroup>,
  120. {
  121. options?: FormItemRadioCustomOptions
  122. }
  123. >
  124. export type FormItemRadio = WithCustomProp<'radio', FormItemRadioCustomProp>
  125. export type BaseCheckBoxProp = AssignKeys<
  126. ExtractComponentProps<typeof ElCheckbox>,
  127. CheckboxProps & { slotLabel?: string | VNode }
  128. >
  129. export type BaseCheckBoxButtonProp = AssignKeys<
  130. ExtractComponentProps<typeof ElCheckboxButton>,
  131. { slotLabel?: string | VNode }
  132. >
  133. export type FormItemCheckBoxCustomOptions = BaseCheckBoxProp[] | BaseCheckBoxButtonProp[]
  134. export type FormItemCheckBoxCustomProp = AssignKeys<
  135. ExtractComponentProps<typeof ElCheckboxGroup>,
  136. {
  137. options?: FormItemCheckBoxCustomOptions
  138. }
  139. >
  140. export type FormItemCheckBox = WithCustomProp<'checkbox', FormItemCheckBoxCustomProp>
  141. export type BaseOptionGroupProp = AssignKeys<ExtractComponentProps<typeof ElOptionGroup>, object>
  142. export type BaseOptionProp = AssignKeys<ExtractComponentProps<typeof ElOption>, object>
  143. export type FormItemSelectCustomOptionGroup = Record<string | number, BaseOptionGroupProp>
  144. export type FormItemSelectCustomOptions = AssignKeys<BaseOptionProp, { groupKey?: string | number }>[]
  145. export type FormItemSelectCustomProp = AssignKeys<
  146. ExtractComponentProps<typeof ElSelect>,
  147. {
  148. optionGroup?: FormItemSelectCustomOptionGroup
  149. options?: FormItemSelectCustomOptions
  150. }
  151. >
  152. export type FormItemSelect = WithCustomProp<'select', FormItemSelectCustomProp>
  153. export type FormItemDatePicker = WithCustomProp<'date', object>
  154. export type FormItemDateTimePicker = WithCustomProp<'dateTime', object>
  155. export type FormItemDescriptionProp = {
  156. itemDescription?: {
  157. requiredAsterisk?: boolean
  158. description: string
  159. }
  160. }
  161. export type WithDescriptionProp<T> = AssignKeys<T, FormItemDescriptionProp>
  162. export type BaseElRowProp = AssignKeys<ExtractComponentProps<typeof ElRow>, Partial<RowProps>>
  163. export type FormItemRowProp = { rowKey?: string | number }
  164. export type WithRowProp<T> = AssignKeys<T, FormItemRowProp>
  165. export type BaseElColProp = AssignKeys<ExtractComponentProps<typeof ElCol>, Partial<ColProps>>
  166. export type FormItemColProp = {
  167. colProp?: Partial<BaseElColProp>
  168. colIndex?: number
  169. }
  170. export type WithColProp<T> = AssignKeys<T, FormItemColProp>
  171. export type PolymerizationFormItem<T> = WithRowProp<WithColProp<WithDescriptionProp<T>>>
  172. export type SupportFormItemType =
  173. | FormItemInput
  174. | FormItemInputNumber
  175. | FormItemAutocomplete
  176. | FormItemSwitch
  177. | FormItemRadio
  178. | FormItemCheckBox
  179. | FormItemSelect
  180. | FormItemDatePicker
  181. | FormItemDateTimePicker
  182. export type EpFormItem = (
  183. | PolymerizationFormItem<FormItemInput>
  184. | PolymerizationFormItem<FormItemInputNumber>
  185. | PolymerizationFormItem<FormItemAutocomplete>
  186. | PolymerizationFormItem<FormItemSwitch>
  187. | PolymerizationFormItem<FormItemRadio>
  188. | PolymerizationFormItem<FormItemCheckBox>
  189. | PolymerizationFormItem<FormItemSelect>
  190. | PolymerizationFormItem<FormItemDatePicker>
  191. | PolymerizationFormItem<FormItemDateTimePicker>
  192. ) & { slot?: any }
  193. export type EpFormRows = Record<
  194. string | number,
  195. AssignKeys<BaseElRowProp, { rowKey?: string | number; hidden?: boolean }>
  196. >
  197. export type FormGroup = {
  198. hidden?: boolean
  199. groupKey?: string | number
  200. groupTitle?: string | VNode
  201. rowKeys?: (string | number)[]
  202. }
  203. export type BaseFormProp = AssignKeys<ExtractComponentProps<typeof ElForm>, Partial<FormProps>>
  204. export interface EpFormProps<T extends Record<string, unknown> = Record<string, unknown>>
  205. extends Omit<BaseFormProp, 'inline' | 'line-message' | 'lineMessage'> {
  206. // 使用的栅格布局,inline失效
  207. model: T
  208. items?: EpFormItem[]
  209. rows?: EpFormRows
  210. groups?: FormGroup[]
  211. }
  212. export type EpFormRules<T extends Record<string, unknown> = Record<string, unknown>> = EpFormProps<T>['rules']
  213. export type InstanceTable = InstanceType<typeof BaseTable>
  214. export type InstanceElTable = InstanceType<typeof ElTable>
  215. export type InstanceForm = InstanceType<typeof BaseForm>
  216. export type InstanceSelect = InstanceType<typeof BaseSelect>
  217. export type InstanceCheckBox = InstanceType<typeof BaseCheckBox>
  218. export type InstanceRadio = InstanceType<typeof BaseRadio>
  219. }