index.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { h } from 'vue'
  2. import { Input, InputNumber, Switch, Textarea } from 'ant-design-vue'
  3. import _ from 'lodash'
  4. import StdDataEntry from './StdDataEntry.vue'
  5. import StdSelector from './components/StdSelector.vue'
  6. import StdSelect from './components/StdSelect.vue'
  7. import StdPassword from './components/StdPassword.vue'
  8. import type { StdDesignEdit } from '@/components/StdDesign/types'
  9. const fn = _.get
  10. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  11. function readonly(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
  12. return h('p', fn(dataSource, dataIndex))
  13. }
  14. function placeholder_helper(edit: StdDesignEdit) {
  15. return typeof edit.config?.placeholder === 'function' ? edit.config?.placeholder() : edit.config?.placeholder
  16. }
  17. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  18. function input(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
  19. return h(Input, {
  20. 'placeholder': placeholder_helper(edit),
  21. 'value': dataSource?.[dataIndex],
  22. 'onUpdate:value': value => {
  23. dataSource[dataIndex] = value
  24. },
  25. })
  26. }
  27. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  28. function inputNumber(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
  29. return h(InputNumber, {
  30. 'placeholder': placeholder_helper(edit),
  31. 'min': edit.config?.min,
  32. 'max': edit.config?.max,
  33. 'value': dataSource?.[dataIndex],
  34. 'onUpdate:value': value => {
  35. dataSource[dataIndex] = value
  36. },
  37. })
  38. }
  39. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  40. function textarea(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
  41. return h(Textarea, {
  42. 'placeholder': placeholder_helper(edit),
  43. 'value': dataSource?.[dataIndex],
  44. 'onUpdate:value': value => {
  45. dataSource[dataIndex] = value
  46. },
  47. })
  48. }
  49. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  50. function password(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
  51. return <StdPassword
  52. v-model:value={dataSource[dataIndex]}
  53. generate={edit.config?.generate}
  54. placeholder={placeholder_helper(edit)}
  55. />
  56. }
  57. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  58. function select(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
  59. return <StdSelect
  60. v-model:value={dataSource[dataIndex]}
  61. mask={edit.mask}
  62. />
  63. }
  64. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  65. function selector(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
  66. return <StdSelector
  67. v-model:selectedKey={dataSource[dataIndex]}
  68. recordValueIndex={edit.selector?.recordValueIndex}
  69. selectionType={edit.selector?.selectionType}
  70. api={edit.selector?.api}
  71. columns={edit.selector?.columns}
  72. disableSearch={edit.selector?.disable_search}
  73. getParams={edit.selector?.get_params}
  74. description={edit.selector?.description}
  75. />
  76. }
  77. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  78. function switcher(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
  79. return h(Switch, {
  80. 'checked': dataSource?.[dataIndex],
  81. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  82. 'onUpdate:checked': (value: any) => {
  83. dataSource[dataIndex] = value
  84. },
  85. })
  86. }
  87. export {
  88. readonly,
  89. input,
  90. textarea,
  91. select,
  92. selector,
  93. password,
  94. inputNumber,
  95. switcher,
  96. }
  97. export default StdDataEntry