StdFormItem.vue 790 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <script setup lang="ts">
  2. import { computed } from 'vue'
  3. import type { Column } from '@/components/StdDesign/types'
  4. const props = defineProps<Props>()
  5. export interface Props {
  6. dataIndex?: Column['dataIndex']
  7. label?: string
  8. extra?: string
  9. hint?: string | (() => string)
  10. error?: {
  11. [key: string]: string
  12. }
  13. required?: boolean
  14. }
  15. const tag = computed(() => {
  16. return props.error?.[props.dataIndex!.toString()] ?? ''
  17. })
  18. const help = computed(() => {
  19. if (tag.value.includes('required'))
  20. return $gettext('This field should not be empty')
  21. return props.hint
  22. })
  23. </script>
  24. <template>
  25. <AFormItem
  26. :name="dataIndex as string"
  27. :label="label"
  28. :help="help"
  29. :required="required"
  30. >
  31. <slot />
  32. </AFormItem>
  33. </template>
  34. <style scoped lang="less">
  35. </style>