index.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import StdDataEntry from './StdDataEntry.js'
  2. import {h} from 'vue'
  3. import {Input, InputNumber, Textarea} from 'ant-design-vue'
  4. import StdSelector from './components/StdSelector.vue'
  5. import StdSelect from './components/StdSelect.vue'
  6. import StdPassword from './components/StdPassword.vue'
  7. interface IEdit {
  8. type: Function
  9. placeholder: any
  10. mask: any
  11. key: any
  12. value: any
  13. recordValueIndex: any
  14. selectionType: any
  15. api: Object,
  16. columns: any,
  17. data_key: any,
  18. disable_search: boolean,
  19. get_params: Object,
  20. description: string
  21. generate: boolean
  22. min: number
  23. max: number,
  24. extra: string
  25. }
  26. function fn(obj: Object, desc: any) {
  27. let arr: string[]
  28. if (typeof desc === 'string') {
  29. arr = desc.split('.')
  30. } else {
  31. arr = [...desc]
  32. }
  33. while (arr.length) {
  34. // @ts-ignore
  35. const top = obj[arr.shift()]
  36. if (top === undefined) {
  37. return null
  38. }
  39. obj = top
  40. }
  41. return obj
  42. }
  43. function readonly(edit: IEdit, dataSource: any, dataIndex: any) {
  44. return h('p', fn(dataSource, dataIndex))
  45. }
  46. function input(edit: IEdit, dataSource: any, dataIndex: any) {
  47. return h(Input, {
  48. placeholder: edit.placeholder?.() ?? '',
  49. value: dataSource?.[dataIndex],
  50. 'onUpdate:value': value => {
  51. dataSource[dataIndex] = value
  52. }
  53. })
  54. }
  55. function inputNumber(edit: IEdit, dataSource: any, dataIndex: any) {
  56. return h(InputNumber, {
  57. placeholder: edit.placeholder?.() ?? '',
  58. min: edit.min,
  59. max: edit.max,
  60. value: dataSource?.[dataIndex],
  61. 'onUpdate:value': value => {
  62. dataSource[dataIndex] = value
  63. }
  64. })
  65. }
  66. function textarea(edit: IEdit, dataSource: any, dataIndex: any) {
  67. return h(Textarea, {
  68. placeholder: edit.placeholder?.() ?? '',
  69. value: dataSource?.[dataIndex],
  70. 'onUpdate:value': value => {
  71. dataSource[dataIndex] = value
  72. }
  73. })
  74. }
  75. function password(edit: IEdit, dataSource: any, dataIndex: any) {
  76. return <StdPassword
  77. v-model:value={dataSource[dataIndex]}
  78. generate={edit.generate}
  79. placeholder={edit.placeholder}
  80. />
  81. }
  82. function select(edit: IEdit, dataSource: any, dataIndex: any) {
  83. return <StdSelect
  84. v-model:value={dataSource[dataIndex]}
  85. mask={edit.mask}
  86. />
  87. }
  88. function selector(edit: IEdit, dataSource: any, dataIndex: any) {
  89. return <StdSelector
  90. v-model:selectedKey={dataSource[dataIndex]}
  91. value={edit.value}
  92. recordValueIndex={edit.recordValueIndex}
  93. selectionType={edit.selectionType}
  94. api={edit.api}
  95. columns={edit.columns}
  96. data_key={edit.data_key}
  97. disable_search={edit.disable_search}
  98. get_params={edit.get_params}
  99. description={edit.description}
  100. />
  101. }
  102. export {
  103. readonly,
  104. input,
  105. textarea,
  106. select,
  107. selector,
  108. password,
  109. inputNumber
  110. }
  111. export default StdDataEntry