swiperPrevie.vue 2.4 KB

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