index.jsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * 特殊组件需要和table配合使用
  3. */
  4. import { formInputProps, fromInputEmits } from '@cip/components/cip-form-input/form-input-props'
  5. import { useFormInput } from '@cip/components/hooks/form-input'
  6. import { ElRadio, ElCheckbox } from 'element-plus'
  7. import { setFieldValue } from '@cip/utils/util'
  8. import { computed } from 'vue'
  9. import './index.less'
  10. export default {
  11. name: 'TableRadio',
  12. props: { ...formInputProps },
  13. emits: [...fromInputEmits],
  14. setup (props, context) {
  15. const { width, securityConfig, ...formInput } = useFormInput(props, context)
  16. const activeValue = computed(() => {
  17. return props.config.activeValue ?? true
  18. })
  19. const inactiveValue = computed(() => {
  20. return props.config.inactiveValue ?? false
  21. })
  22. const activeCurrentValue = () => {
  23. // 特殊操作,不建议其他组件使用
  24. props.tableData.forEach(v => {
  25. // 将当前table的其他数据设置为假值
  26. setFieldValue(v, props.fieldKey, inactiveValue.value)
  27. })
  28. formInput.emitModelValue(activeValue.value)
  29. }
  30. const handleChange = (e) => {
  31. console.log(e)
  32. if (props.modelValue !== activeValue.value && !props.config.disabled) {
  33. activeCurrentValue()
  34. }
  35. }
  36. const CheckComponent = computed(() => {
  37. return securityConfig.value.checkComponent === 'checkbox' ? ElCheckbox : ElRadio
  38. })
  39. return () => <CheckComponent.value
  40. class={'cip-table-radio'}
  41. modelValue={props.modelValue}
  42. label={activeValue.value}
  43. disabled={props.disabled}
  44. onChange={(e) => handleChange(e)}
  45. // onUpdate:modelValue={() => { changeModelValue() }}
  46. />
  47. }
  48. }