view.js 1010 B

123456789101112131415161718192021222324252627
  1. import { computed, h } from 'vue'
  2. import { formInputViewProps } from '../../form-input-props'
  3. import { isNotEmpty, isArray, isObject } from '@cip/utils/util'
  4. import { useOptions } from '@cip/components/hooks/form-input'
  5. export default {
  6. props: formInputViewProps,
  7. setup (props) {
  8. const multiple = computed(() => {
  9. return props.config?.multiple ?? false
  10. })
  11. const { getValue, getOtherValue, optionProps } = useOptions(props, multiple)
  12. const viewValue = computed(() => {
  13. if (isNotEmpty(props.otherValue)) return props.otherValue
  14. const value = getValue(props.modelValue)
  15. const otherValue = getOtherValue(props.modelValue, value) // || props.modelValue
  16. if (isArray(otherValue)) {
  17. if (isObject(otherValue[0])) {
  18. return otherValue.map(i => i[optionProps.value.label]).join(', ')
  19. }
  20. return otherValue.join(', ')
  21. }
  22. return otherValue
  23. })
  24. return () => h('span', {}, [viewValue.value])
  25. }
  26. }