mobile.jsx 2.0 KB

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