tui-image-group.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view
  3. class="tui-image-container"
  4. :style="{ marginBottom: multiLine ? `-${distance}rpx` : 0 }"
  5. :class="{ 'tui-image-direction': direction == 'column', 'tui-image__warp': multiLine }"
  6. >
  7. <view
  8. v-for="(item, index) in imageList"
  9. :key="index"
  10. class="tui-image__itembox"
  11. :style="{
  12. width: width,
  13. height: height,
  14. borderRadius: radius,
  15. marginLeft: direction == 'column' || multiLine ? 0 : (index && distance) + 'rpx',
  16. marginRight: multiLine ? distance + 'rpx' : 0,
  17. marginBottom: multiLine ? distance + 'rpx' : 0,
  18. marginTop: direction == 'row' ? 0 : (index && distance) + 'rpx'
  19. }"
  20. @tap="bindClick(index, item.id)"
  21. >
  22. <image
  23. class="tui-image-item"
  24. :mode="mode"
  25. :lazy-load="lazyLoad"
  26. fade-show="fadeShow"
  27. :webp="webp"
  28. :show-menu-by-longpress="longpress"
  29. @error="error"
  30. @load="load"
  31. :style="{ width: width, height: height, borderRadius: radius, borderWidth: borderWidth, borderColor: borderColor }"
  32. :src="item.src"
  33. ></image>
  34. <slot />
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. name: 'tuiImageGroup',
  41. props: {
  42. //图片集合
  43. /*
  44. [{id:1,src:"1.png"}]
  45. */
  46. imageList: {
  47. type: Array,
  48. default: () => {
  49. return [];
  50. }
  51. },
  52. //图片宽度
  53. width: {
  54. type: String,
  55. default: '120rpx'
  56. },
  57. //图片高度
  58. height: {
  59. type: String,
  60. default: '120rpx'
  61. },
  62. //图片边框宽度 rpx
  63. borderWidth: {
  64. type: String,
  65. default: '0'
  66. },
  67. //图片边框颜色 可传rgba
  68. borderColor: {
  69. type: String,
  70. default: '#fff'
  71. },
  72. //图片圆角
  73. radius: {
  74. type: String,
  75. default: '50%'
  76. },
  77. //图片裁剪、缩放的模式
  78. mode: {
  79. type: String,
  80. default: 'scaleToFill'
  81. },
  82. //图片懒加载。只针对page与scroll-view下的image有效
  83. lazyLoad: {
  84. type: Boolean,
  85. default: true
  86. },
  87. //图片显示动画效果 | 仅App-nvue 2.3.4+ Android有效
  88. fadeShow: {
  89. type: Boolean,
  90. default: true
  91. },
  92. //默认不解析 webP 格式,只支持网络资源 | 微信小程序2.9.0
  93. webp: {
  94. type: Boolean,
  95. default: false
  96. },
  97. //开启长按图片显示识别小程序码菜单 | 微信小程序2.7.0
  98. longpress: {
  99. type: Boolean,
  100. default: false
  101. },
  102. //是否组合排列
  103. isGroup: {
  104. type: Boolean,
  105. default: false
  106. },
  107. //排列方向 row ,column
  108. direction: {
  109. type: String,
  110. default: 'row'
  111. },
  112. //偏移距离 rpx
  113. distance: {
  114. type: [Number, String],
  115. default: -16
  116. },
  117. //是否可多行展示,排列方向 row时生效,distance需设置为大于0的数
  118. multiLine: {
  119. type: Boolean,
  120. default: false
  121. }
  122. },
  123. data() {
  124. return {};
  125. },
  126. methods: {
  127. error(e) {
  128. this.$emit('errorEvent', e);
  129. },
  130. load(e) {
  131. this.$emit('loaded', e);
  132. },
  133. bindClick(index, id) {
  134. this.$emit('click', {
  135. index: index,
  136. id: id || ''
  137. });
  138. }
  139. }
  140. };
  141. </script>
  142. <style scoped>
  143. .tui-image-container {
  144. display: inline-flex;
  145. align-items: center;
  146. }
  147. .tui-image-direction {
  148. flex-direction: column;
  149. }
  150. .tui-image__warp {
  151. flex-wrap: wrap;
  152. }
  153. .tui-image__itembox {
  154. position: relative;
  155. }
  156. .tui-image-item {
  157. border-style: solid;
  158. flex-shrink: 0;
  159. display: block;
  160. }
  161. </style>