index.jsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { ElRadioGroup, ElRadio, ElCheckboxGroup, ElCheckbox } from 'element-plus'
  2. import { useFormInput, useOptions } from '@cip/components/hooks/form-input'
  3. import { formInputProps, fromInputEmits } from '../../form-input-props'
  4. import { computed } from 'vue'
  5. export default {
  6. props: formInputProps,
  7. emits: [...fromInputEmits],
  8. setup (props, context) {
  9. const { width, securityConfig, updateStream } = useFormInput(props, context)
  10. const multiple = computed(() => {
  11. return securityConfig.value.multiple ?? false
  12. })
  13. const { options, optionProps, proxyOptionsValue } = useOptions(props, multiple, updateStream)
  14. const display = computed(() => {
  15. return securityConfig.value.display ?? 'inline-block'
  16. })
  17. const SelectComponent = computed(() => multiple.value ? ElCheckbox : ElRadio)
  18. const SelectComponentGroup = computed(() => multiple.value ? ElCheckboxGroup : ElRadioGroup)
  19. return () => <SelectComponentGroup.value
  20. v-model={proxyOptionsValue.value}
  21. style={{ width: width.value }}
  22. disabled={props.disabled}
  23. >
  24. {options.value.map(option => (
  25. <SelectComponent.value
  26. key={option[optionProps.value.value]}
  27. label={option[optionProps.value.value]}
  28. style={{ display: display.value ?? 0 }}
  29. >
  30. <img
  31. src={option[optionProps.value.label]}
  32. width={option.width ?? 64}
  33. style={'vertical-align: middle;'}
  34. />
  35. </SelectComponent.value>
  36. ))}
  37. </SelectComponentGroup.value>
  38. }
  39. }