mobile.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { defineAsyncComponent } from 'vue'
  2. import { formInputProps } from '@cip/components/cip-form-input/form-input-props'
  3. import { useFormInput, useElementFormEvent } from '@cip/components/hooks/form-input'
  4. import { ElButton } from 'element-plus'
  5. import './mobile.less'
  6. const CipFormItem = defineAsyncComponent(() => import('../../../cip-form-item'))
  7. export default {
  8. props: formInputProps,
  9. setup (props, context) {
  10. const { handleChange } = useElementFormEvent()
  11. const formInput = useFormInput(props, context)
  12. const { securityConfig, emitModelValue } = formInput
  13. const updateModelValue = (val, index) => {
  14. const data = props.modelValue
  15. data[index] = val
  16. emitModelValue(data)
  17. }
  18. const addItem = () => {
  19. const val = Array.isArray(props.modelValue) ? props.modelValue : []
  20. val.push({})
  21. handleChange(val)
  22. emitModelValue(val)
  23. }
  24. return () => <div class={'basic-table__mobile'}>
  25. {
  26. (props.modelValue || []).map((row, rowIndex) =>
  27. <div>
  28. <div>{rowIndex + 1}</div>
  29. {securityConfig.value.options.map((option, optionIndex) => {
  30. const inputConfig = { ...option.config }
  31. inputConfig.width = '100%'
  32. inputConfig.ruleKey = `${props.fieldKey}.${rowIndex}.${option.key}`
  33. return <CipFormItem
  34. key={`${rowIndex}-${optionIndex}`}
  35. model={row}
  36. fieldKey={option.key}
  37. config={inputConfig}
  38. inTable={true}
  39. tableData={props.modelValue}
  40. tableDependOnValues={props.dependOnValues}
  41. onUpdate:model={(val) => {
  42. row = val
  43. updateModelValue(val, rowIndex)
  44. }}
  45. />
  46. })}
  47. </div>
  48. )
  49. }
  50. <ElButton size="medium" type="text" onClick={() => addItem()}>
  51. <i className="el-icon-circle-plus create-handle"/>
  52. </ElButton>
  53. </div>
  54. }
  55. }