tui-image-group.vue 2.7 KB

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