index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="previewImg" v-if="showBox" @touchmove.stop.prevent>
  3. <view class="mask" @click="close">
  4. <swiper @change="changeSwiper" class="mask-swiper" :current="currentIndex" :circular="circular"
  5. :duration="duration">
  6. <swiper-item v-for="(src, i) in list" :key="i" class="flex flex-column justify-center align-center">
  7. <image class="mask-swiper-img" :src="src.image" mode="widthFix" />
  8. <view class="mask_sku">
  9. <text class="sku_name">{{src.suk}}</text>
  10. <text class="sku_price">{{$t(`¥`)}}{{src.price}}</text>
  11. </view>
  12. </swiper-item>
  13. </swiper>
  14. </view>
  15. <view class="pagebox" v-if="list.length>0">{{ Number(currentIndex) + 1 }} / {{ list.length }}</view>
  16. <!-- #ifndef MP -->
  17. <!-- <text class="iconfont icon-fenxiang share_btn" @click="shareFriend()"></text> -->
  18. <!-- #endif -->
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'cusPreviewImg',
  24. props: {
  25. list: {
  26. type: Array,
  27. required: true,
  28. default: () => {
  29. return [];
  30. }
  31. },
  32. circular: {
  33. type: Boolean,
  34. default: true
  35. },
  36. duration: {
  37. type: Number,
  38. default: 500
  39. }
  40. },
  41. data() {
  42. return {
  43. currentIndex: 0,
  44. showBox: false
  45. };
  46. },
  47. watch: {
  48. list(val) {}
  49. },
  50. methods: {
  51. // 左右切换
  52. changeSwiper(e) {
  53. this.currentIndex = e.target.current;
  54. this.$emit('changeSwitch', e.target.current)
  55. },
  56. open(current) {
  57. if (!current || !this.list.length) return;
  58. this.currentIndex = this.list.map((item) => item.suk).indexOf(current);
  59. this.showBox = true;
  60. },
  61. close() {
  62. this.showBox = false;
  63. },
  64. shareFriend() {
  65. this.$emit('shareFriend')
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="scss" scoped>
  71. @mixin full {
  72. width: 100%;
  73. height: 100%;
  74. }
  75. .previewImg {
  76. position: fixed;
  77. top: 0;
  78. left: 0;
  79. z-index: 300;
  80. @include full;
  81. .mask {
  82. display: flex;
  83. justify-content: center;
  84. align-items: center;
  85. background-color: #000;
  86. opacity: 1;
  87. z-index: 8;
  88. @include full;
  89. &-swiper {
  90. @include full;
  91. &-img {
  92. width: 100%;
  93. }
  94. }
  95. }
  96. .pagebox {
  97. position: absolute;
  98. width: 100%;
  99. bottom: 20rpx;
  100. z-index: 300;
  101. color: #fff;
  102. text-align: center;
  103. }
  104. }
  105. .mask_sku {
  106. color: #fff;
  107. max-width: 80%;
  108. z-index: 300;
  109. text-align: center;
  110. display: flex;
  111. flex-direction: column;
  112. align-items: center;
  113. margin-top: 30rpx;
  114. .sku_name {
  115. font-size: 12px;
  116. border: 1px solid #fff;
  117. padding: 10rpx 30rpx 10rpx;
  118. border-radius: 40px;
  119. box-sizing: border-box;
  120. }
  121. .sku_price {
  122. padding-top: 10px;
  123. }
  124. }
  125. .font12 {
  126. font-size: 24rpx;
  127. }
  128. .share_btn {
  129. position: absolute;
  130. top: 70rpx;
  131. right: 50rpx;
  132. font-size: 40rpx;
  133. color: #fff;
  134. z-index: 300;
  135. }
  136. .flex-column {
  137. flex-direction: column;
  138. }
  139. .justify-center {
  140. justify-content: center;
  141. }
  142. .align-center {
  143. align-items: center;
  144. }
  145. </style>