view.jsx 927 B

123456789101112131415161718192021222324252627
  1. import { computed } from 'vue'
  2. import { isNotEmpty } from '@cip/utils/util'
  3. import { formInputViewProps } from '../../form-input-props'
  4. import { useOptions } from '@cip/components/hooks/form-input'
  5. export default {
  6. props: formInputViewProps,
  7. setup (props) {
  8. const { options, optionProps } = useOptions(props)
  9. const showValue = computed(() => {
  10. return isNotEmpty(props.otherValue) ? props.otherValue : showLabel(options.value)
  11. })
  12. const showLabel = (options) => {
  13. // eslint-disable-next-line
  14. for (const option of options) {
  15. if (option[optionProps.value.value] === props.modelValue) {
  16. return option[optionProps.value.label]
  17. }
  18. const children = option[optionProps.value.children]
  19. if (children) {
  20. const label = showLabel(children)
  21. if (label) return label
  22. }
  23. }
  24. }
  25. return () => <span>{showValue.value}</span>
  26. }
  27. }