ImageBlock.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <Touchable
  3. touchable
  4. position="relative"
  5. overflow="hidden"
  6. v-bind="$props"
  7. :flexShrink="0"
  8. :innerStyle="{ borderRadius: theme.resolveThemeSize(radius), overflow: 'hidden', }"
  9. :width="width"
  10. :height="height"
  11. @click="$emit('click')"
  12. >
  13. <Image
  14. :src="src"
  15. mode="aspectFill"
  16. width="100%"
  17. height="100%"
  18. >
  19. <Image
  20. v-if="videoMark"
  21. :src="videoMarkImage"
  22. :width="videoMarkSize"
  23. :height="videoMarkSize"
  24. innerClass="nana-image-block-video-mark"
  25. />
  26. </Image>
  27. <slot name="desc">
  28. <BackgroundBox
  29. color1="background.mask"
  30. position="absolute"
  31. :left="0"
  32. :right="0"
  33. :bottom="0"
  34. :padding="[10,15]"
  35. >
  36. <Text class="nana-image-desc" color="text.second" v-bind="descProps" :text="desc" />
  37. </BackgroundBox>
  38. </slot>
  39. <slot name="footer" />
  40. </Touchable>
  41. </template>
  42. <script lang="ts">
  43. /**
  44. * 组件说明:图片块。
  45. *
  46. * 该组件可以用于显示图片,支持在图片下方显示描述。
  47. *
  48. * 该组件的默认高度为 200rpx。
  49. */
  50. export default {}
  51. </script>
  52. <script setup lang="ts">
  53. import { useTheme } from '@/components/theme/ThemeDefine';
  54. import BackgroundBox from './BackgroundBox.vue';
  55. import VideoMark from '../../images/icons/video-mark.png';
  56. import Touchable from '@/components/feedback/Touchable.vue';
  57. import Image from '@/components/basic/Image.vue';
  58. import Text, { type TextProps } from '@/components/basic/Text.vue';
  59. import type { PropType } from 'vue';
  60. const theme = useTheme();
  61. defineOptions({
  62. options: {
  63. virtualHost: true,
  64. styleIsolation: "shared",
  65. },
  66. });
  67. defineProps({
  68. /**
  69. * 宽度。
  70. */
  71. width: {
  72. type: [ String, Number ],
  73. default: 200
  74. },
  75. /**
  76. * 高度。
  77. */
  78. height: {
  79. type: [ String, Number ],
  80. default: 100
  81. },
  82. /**
  83. * 图片的路径。
  84. */
  85. src: {
  86. type: String,
  87. default: null
  88. },
  89. /**
  90. * 图片的圆角。
  91. */
  92. radius: {
  93. type: [ String, Number ],
  94. default: undefined
  95. },
  96. /**
  97. * 图片下方显示描述。
  98. */
  99. desc: {
  100. type: String,
  101. default: null
  102. },
  103. /**
  104. * 图片下方显示描述的文字属性。
  105. */
  106. descProps: {
  107. type: Object as PropType<TextProps>,
  108. default: () => ({})
  109. },
  110. /**
  111. * 是否显示播放视频标记。
  112. */
  113. videoMark: {
  114. type: Boolean,
  115. default: false
  116. },
  117. /**
  118. * 播放视频标记的图片路径。
  119. */
  120. videoMarkImage: {
  121. type: String,
  122. default: VideoMark
  123. },
  124. /**
  125. * 播放视频标记的大小。
  126. */
  127. videoMarkSize: {
  128. type: [ String, Number ],
  129. default: 80
  130. }
  131. })
  132. defineEmits([
  133. "click"
  134. ])
  135. </script>
  136. <style lang="scss">
  137. .nana-image-desc {
  138. white-space: nowrap;
  139. overflow: hidden;
  140. text-overflow: ellipsis;
  141. }
  142. .nana-image-block-video-mark {
  143. position: absolute;
  144. left: 50%;
  145. top: 40%;
  146. z-index: 100;
  147. transform: translate(-50%, -50%);
  148. }
  149. </style>