You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
3.0 KiB

6 months ago
  1. <template>
  2. <view class="previewImg" v-if="showBox" @touchmove.stop.prevent="mpClear">
  3. <view class="close" @click="close">
  4. <text>关闭</text>
  5. </view>
  6. <view class="mask">
  7. <swiper @change="changeSwiper" class="my_swiper" :current="currentIndex" :circular="circular" :indicator-dots="indicatorDots" :autoplay="autoplay" :duration="duration">
  8. <swiper-item v-for="(src, y) in picList" :key="y">
  9. <view class="bg_img" :style="{ backgroundImage: 'url('+ src +')'}"></view>
  10. </swiper-item>
  11. </swiper>
  12. </view>
  13. <view class="pagebox" v-if="picList.length>0">{{ Number(currentIndex) + 1 }} / {{ picList.length }}</view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. name: 'hx-preview-img',
  19. props: {
  20. current: {
  21. type: String,
  22. default: ''
  23. },
  24. list: {
  25. type: Array,
  26. default: function(){
  27. return new Array();
  28. }
  29. },
  30. //开始
  31. start: {
  32. type: Number,
  33. default: 0
  34. },
  35. },
  36. data() {
  37. return {
  38. picList: [],
  39. indicatorDots: false,
  40. autoplay: false,
  41. duration: 500,
  42. circular: true,
  43. currentIndex: 0,
  44. isShowSwiper: false,
  45. showBox: false
  46. };
  47. },
  48. watch: {
  49. list(val) {
  50. },
  51. current(val){
  52. },
  53. start(val,oldVal) {
  54. var that = this;
  55. this.picListInit();
  56. }
  57. },
  58. created() {
  59. },
  60. methods: {
  61. clickPic(index) {
  62. this.currentIndex = index;
  63. this.isShowSwiper = true;
  64. },
  65. picListInit() {
  66. this.showBox = true;
  67. if(!this.current || !this.list){
  68. return;
  69. }
  70. for(var i in this.list){
  71. if(this.current == this.list[i]){
  72. this.currentIndex = i;
  73. break;
  74. }
  75. }
  76. console.log(this.currentIndex);
  77. this.picList=this.list;
  78. },
  79. changeSwiper(e) {
  80. this.currentIndex = e.target.current;
  81. },
  82. mpClear(e) {
  83. // TODO nvue 取消冒泡
  84. e.stopPropagation()
  85. },
  86. close(){
  87. this.showBox = false;
  88. }
  89. }
  90. }
  91. </script>
  92. <style lang="scss" scoped>
  93. .previewImg {
  94. position: fixed;
  95. top: 0;
  96. left: 0;
  97. width: 100%;
  98. height: 100%;
  99. z-index: 99999999;
  100. .close{
  101. position: absolute;
  102. top: calc(0px + 15px);
  103. left: 15px;
  104. z-index: 6;
  105. color: #ffffff;
  106. font-size: 14px;
  107. background-color: rgba(255, 255, 255, 0.4);
  108. padding: 0 9px;
  109. border-radius: 4px;
  110. text-align: center;
  111. display: flex;
  112. align-items: center;
  113. height: 27px;
  114. }
  115. .pagebox{
  116. position: absolute;
  117. z-index: 6;
  118. color: #fff;
  119. bottom: 20rpx;
  120. text-align: center;
  121. width: 100%;
  122. }
  123. .mask {
  124. position: absolute;
  125. top: 0;
  126. left: 0;
  127. width: 100%;
  128. height: 100%;
  129. display: flex;
  130. justify-content: center;
  131. align-items: center;
  132. background-color: #000;
  133. z-index: 5;
  134. > .my_swiper {
  135. width: 100%;
  136. height: 60vh;
  137. .bg_img {
  138. background-size: 100% auto;
  139. background-repeat: no-repeat;
  140. background-position:center;
  141. width: 100%;
  142. height: 100%;
  143. }
  144. }
  145. }
  146. .pic_list {
  147. display: flex;
  148. flex-flow: row wrap;
  149. > view {
  150. flex: 0 0 33.3vw;
  151. height: 33.3vw;
  152. padding: 1vw;
  153. > image {
  154. width: 100%;
  155. height: 100%;
  156. }
  157. }
  158. }
  159. }
  160. </style>