index.jsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * 特殊组件需要和table配合使用
  3. */
  4. import { formInputProps } from '@cip/components/cip-form-input/form-input-props'
  5. import { useFormInput } from '@cip/components/hooks/form-input'
  6. import { ElRadio } 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. setup (props, context) {
  14. const { width, ...formInput } = useFormInput(props, context)
  15. const activeValue = computed(() => {
  16. return props.config.activeValue ?? true
  17. })
  18. const inactiveValue = computed(() => {
  19. return props.config.inactiveValue ?? false
  20. })
  21. const activeCurrentValue = () => {
  22. // 特殊操作,不建议其他组件使用
  23. props.tableData.forEach(v => {
  24. // 将当前table的其他数据设置为假值
  25. setFieldValue(v, props.fieldKey, inactiveValue.value)
  26. })
  27. formInput.emitModelValue(activeValue.value)
  28. }
  29. const click = (e) => {
  30. // TODO: 此处element存在bug radio触发2次click disabled 无法控制click事件
  31. if (props.modelValue !== activeValue.value && !props.config.disabled) {
  32. activeCurrentValue()
  33. }
  34. }
  35. return () => <ElRadio
  36. class={'cip-table-radio'}
  37. modelValue={props.modelValue}
  38. label={activeValue.value}
  39. disabled={props.config.disabled}
  40. onClick={(e) => click(e)}
  41. // onUpdate:modelValue={() => { changeModelValue() }}
  42. />
  43. }
  44. }