PreviewItem.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <FlexRow justify="space-between" align="flex-start" :gap="gap" :padding="[margin??0,0]">
  3. <FlexRow :width="titleWidth">
  4. <Text v-bind="titleProps" :color="titleColor" :text="title" />
  5. </FlexRow>
  6. <template v-if="valueType === 'text'">
  7. <FlexCol v-if="Array.isArray(value)">
  8. <Text
  9. v-for="(item,k) in value"
  10. :key="k"
  11. v-bind="valueProps"
  12. :color="valueColor"
  13. :text="item"
  14. />
  15. </FlexCol>
  16. <Text v-else v-bind="valueProps" :color="valueColor" :text="value || emptyText" />
  17. </template>
  18. <template v-else-if="valueType === 'image'">
  19. <FlexRow v-if="Array.isArray(value)" wrap>
  20. <Image
  21. v-for="(item,k) in value"
  22. :key="k"
  23. :width="100"
  24. :height="100"
  25. :radius="12"
  26. round
  27. v-bind="(valueProps as ImageProps)"
  28. :src="item"
  29. clickPreview
  30. />
  31. </FlexRow>
  32. <Image
  33. v-else
  34. :width="100"
  35. :height="100"
  36. :radius="12"
  37. round
  38. v-bind="(valueProps as ImageProps)"
  39. :src="value"
  40. clickPreview
  41. />
  42. </template>
  43. </FlexRow>
  44. </template>
  45. <script setup lang="ts">
  46. import FlexRow from '../layout/FlexRow.vue';
  47. import Text,{ type TextProps } from '../basic/Text.vue';
  48. import FlexCol from '../layout/FlexCol.vue';
  49. import Image, { type ImageProps } from '../basic/Image.vue';
  50. export type PreviewItemType = 'text' | 'image';
  51. const props = withDefaults(defineProps<{
  52. title?: string,
  53. titleColor?: string,
  54. titleWidth?: string|number,
  55. titleProps?: TextProps,
  56. value?: string | string[],
  57. valueColor?: string,
  58. valueType?: PreviewItemType,
  59. valueProps?: TextProps|ImageProps,
  60. emptyText?: string,
  61. gap?: number,
  62. margin?: number,
  63. }>(), {
  64. emptyText: '空',
  65. valueType: 'text',
  66. });
  67. </script>