index.vue 2.8 KB

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