view.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <div class="audit-status">
  3. <span>{{viewValue}}</span>
  4. <template v-if="isShowOtherValue && contentValue">
  5. <el-popover :title="titleValue" :content="contentValue" placement="top" trigger="hover">
  6. <template #reference>
  7. <i class="el-icon-warning cip-danger-color" style="margin-left:4px"></i>
  8. </template>
  9. </el-popover>
  10. </template>
  11. </div>
  12. </template>
  13. <script>
  14. import { computed, readonly } from 'vue'
  15. import { ElPopover } from 'element-plus'
  16. import { formInputViewProps } from '../../form-input-props'
  17. import { useFormView } from '../../../hooks/form-input'
  18. export default {
  19. components: { ElPopover },
  20. props: formInputViewProps,
  21. setup (props) {
  22. const { securityConfig } = useFormView(props)
  23. const isShowOtherValue = computed(() => {
  24. if (!securityConfig.value.showOtherValue) return false
  25. // 转为数组
  26. const showOtherValue = [].concat(securityConfig.value.showOtherValue)
  27. return showOtherValue.includes(props.modelValue)
  28. })
  29. const contentValue = computed(() => {
  30. const { formatterOther } = securityConfig.value
  31. if (typeof formatterOther === 'function') return formatterOther(props.modelValue, readonly(securityConfig.value), props.dependOnValues)
  32. return props.otherValue
  33. })
  34. const titleValue = computed(() => {
  35. const { formatterTitle } = securityConfig.value
  36. if (typeof formatterTitle === 'function') return formatterTitle(props.modelValue, readonly(securityConfig.value), props.dependOnValues)
  37. return props.otherLabel
  38. })
  39. const viewValue = computed(() => {
  40. const { formatter } = securityConfig.value
  41. if (typeof formatter === 'function') return formatter(props.modelValue, readonly(securityConfig.value))
  42. return props.modelValue
  43. })
  44. return {
  45. isShowOtherValue,
  46. contentValue,
  47. titleValue,
  48. viewValue
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="less">
  54. .audit-status{
  55. display: flex;
  56. align-items: center;
  57. }
  58. </style>