view.js 913 B

123456789101112131415161718192021222324
  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 { getValue, getOtherValue, optionProps } = useOptions(props, true)
  9. const viewValue = computed(() => {
  10. if (isNotEmpty(props.otherValue)) return props.otherValue
  11. const value = getValue(props.modelValue)
  12. const otherValue = getOtherValue(props.modelValue, value) // || props.modelValue
  13. if (isArray(otherValue)) {
  14. if (isObject(otherValue[0])) {
  15. return otherValue.map(i => i[optionProps.value.label]).join(', ')
  16. }
  17. return otherValue.join(', ')
  18. }
  19. return otherValue
  20. })
  21. return () => h('span', {}, [viewValue.value])
  22. }
  23. }