view.jsx 1.3 KB

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