tui-image-group.vue 3.2 KB

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