1
0

StdFormItem.vue 845 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <script setup lang="ts">
  2. import { computed } from 'vue'
  3. import { useGettext } from 'vue3-gettext'
  4. const props = defineProps<Props>()
  5. const { $gettext } = useGettext()
  6. export interface Props {
  7. dataIndex?: string
  8. label?: string
  9. extra?: string
  10. error?: {
  11. [key: string]: string
  12. }
  13. }
  14. const tag = computed(() => {
  15. return props.error?.[props.dataIndex] ?? ''
  16. })
  17. const valid_status = computed(() => {
  18. if (tag.value)
  19. return 'error'
  20. else
  21. return 'success'
  22. })
  23. const help = computed(() => {
  24. if (tag.value.includes('required'))
  25. return () => $gettext('This field should not be empty')
  26. return () => {
  27. }
  28. })
  29. </script>
  30. <template>
  31. <AFormItem
  32. :label="label"
  33. :extra="extra"
  34. :validate-status="valid_status"
  35. :help="help?.()"
  36. >
  37. <slot />
  38. </AFormItem>
  39. </template>
  40. <style scoped lang="less">
  41. </style>