cus-previewImg.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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">¥{{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: 'cus-previewImg',
  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. console.log(e.target.current)
  55. this.currentIndex = e.target.current;
  56. this.$emit('changeSwitch',e.target.current)
  57. },
  58. open(current) {
  59. if (!current || !this.list.length) return;
  60. this.currentIndex = this.list.map((item)=>item.suk).indexOf(current);
  61. this.showBox = true;
  62. },
  63. close() {
  64. this.showBox = false;
  65. },
  66. shareFriend(){
  67. this.$emit('shareFriend')
  68. this.showBox = false;
  69. }
  70. }
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. @mixin full {
  75. width: 100%;
  76. height: 100%;
  77. }
  78. .previewImg {
  79. position: fixed;
  80. top: 0;
  81. left: 0;
  82. z-index: 300;
  83. @include full;
  84. .mask {
  85. display: flex;
  86. justify-content: center;
  87. align-items: center;
  88. background-color: #000;
  89. opacity: 1;
  90. z-index: 8;
  91. @include full;
  92. &-swiper {
  93. @include full;
  94. &-img {
  95. width: 100%;
  96. }
  97. }
  98. }
  99. .pagebox{
  100. position: absolute;
  101. width: 100%;
  102. bottom: 20rpx;
  103. z-index: 300;
  104. color: #fff;
  105. text-align: center;
  106. }
  107. }
  108. .mask_sku{
  109. color: #fff;
  110. max-width: 80%;
  111. z-index: 300;
  112. text-align: center;
  113. display: flex;
  114. flex-direction: column;
  115. align-items: center;
  116. margin-top: 30rpx;
  117. .sku_name{
  118. font-size: 12px;
  119. border: 1px solid #fff;
  120. padding: 10rpx 30rpx 10rpx;
  121. border-radius: 40px;
  122. box-sizing: border-box;
  123. }
  124. .sku_price{
  125. padding-top: 10px;
  126. }
  127. }
  128. .font12{
  129. font-size: 24rpx;
  130. }
  131. .share_btn{
  132. position: absolute;
  133. top:70rpx;
  134. right:50rpx;
  135. font-size: 40rpx;
  136. color:#fff;
  137. z-index: 300;
  138. }
  139. .flex-column{flex-direction: column;}
  140. .justify-center {justify-content: center;}
  141. .align-center {align-items: center;}
  142. </style>