PreviewPicture.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <!-- PreviewPicture.vue -->
  2. <template>
  3. <view class="div" v-if="detailInfo">
  4. <uni-popup background-color="#fff" ref="isshow">
  5. <view class="div preview-picture">
  6. <title-header />
  7. <view
  8. class="div picture-header"
  9. v-on:click="closePopup()"
  10. v-if="!isshowPopHeader"
  11. >
  12. <text class="span">关闭</text
  13. ><text class="span" v-if="detailInfo.photos"
  14. >{{ defaultindex + 1 }} / {{ detailInfo.photos.length }}</text
  15. >
  16. </view>
  17. <view class="div picture-body">
  18. <swiper
  19. :autoplay="false"
  20. :show-indicators="true"
  21. :current="defaultindex"
  22. class="ui-common-swiper"
  23. @change="handleChange"
  24. >
  25. <swiper-item
  26. v-for="(item, index) in detailInfo.photos"
  27. v-bind:key="index"
  28. >
  29. <image mode="aspectFit" class="img" v-bind:src="item" @click="setPopHeader()" />
  30. </swiper-item>
  31. </swiper>
  32. </view>
  33. </view>
  34. </uni-popup>
  35. </view>
  36. </template>
  37. <script>
  38. import TitleHeader from '../../../TitleHeader'
  39. import { mapState, mapMutations } from 'vuex'
  40. export default {
  41. data() {
  42. return {
  43. isshowPopHeader: false,
  44. defaultindex:0
  45. }
  46. },
  47. components:{
  48. TitleHeader
  49. },
  50. computed: {
  51. ...mapState({
  52. isPreviewPicture: state => state.goodsdetail.isPreviewPicture,
  53. detailInfo: state => state.goodsdetail.detailInfo
  54. })
  55. },
  56. watch: {
  57. isPreviewPicture: function (value) {
  58. if(value){
  59. this.showPopup('isshow')
  60. }else{
  61. this.hidePopup('isshow')
  62. }
  63. },
  64. },
  65. mounted() {
  66. if(this.isPreviewPicture){
  67. this.showPopup('isshow')
  68. }
  69. },
  70. methods:{
  71. showPopup(id){
  72. this.$refs[id].open()
  73. },
  74. hidePopup(id){
  75. this.$refs[id].close()
  76. },
  77. ...mapMutations({
  78. setisPreviewPicture: 'setisPreviewPicture'
  79. }),
  80. /*
  81. handleChange: 轮播图改变时设置是否阻止事件冒泡
  82. @params: index 当前滑动的index
  83. */
  84. handleChange(e) {
  85. this.defaultindex = e.detail.current
  86. },
  87. /*
  88. * closePopup: 关闭图片预览
  89. */
  90. closePopup() {
  91. this.setisPreviewPicture(false)
  92. uni.$emit('hide-priview-picture', false)
  93. },
  94. /*
  95. * setPopHeader: 预览大图点击图片切换header
  96. */
  97. setPopHeader(ev) {
  98. this.isshowPopHeader = !this.isshowPopHeader
  99. }
  100. },
  101. destroyed:function(){
  102. this.setisPreviewPicture(false)
  103. }
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .ui-common-swiper {
  108. width:100%;
  109. height: 100%;
  110. swiper-item{
  111. display: flex;
  112. align-items: center;
  113. }
  114. }
  115. .swipe-wrapper {
  116. width: 100%;
  117. }
  118. .mint-popup {
  119. width: 100%;
  120. height: 100%;
  121. background-color: #000;
  122. }
  123. .mint-swipe,
  124. .mint-swipe-items-wrap {
  125. position: static;
  126. }
  127. .preview-picture {
  128. width: 100%;
  129. height: 100%;
  130. position: fixed;
  131. z-index: 10;
  132. top: 0;
  133. bottom: 0;
  134. left: 0;
  135. right: 0;
  136. background-color: #000;
  137. display: flex;
  138. flex-direction: column;
  139. .picture-header {
  140. color: #000;
  141. background-color: #fff;
  142. display: flex;
  143. justify-content: center;
  144. align-content: center;
  145. align-items: center;
  146. width: 100%;
  147. top: 0;
  148. padding-top:var(--status-bar-height);
  149. .span {
  150. font-size:$subFontSize;
  151. font-weight: normal;
  152. height:2.2rem;
  153. line-height:2.2rem;
  154. &:first-child {
  155. position: absolute;
  156. cursor: pointer;
  157. left:0.75rem;
  158. background-size:1.2rem;
  159. display: inline-block;
  160. height:2.2rem;
  161. line-height:2.2rem;
  162. }
  163. }
  164. }
  165. .picture-body {
  166. flex:1;
  167. display: flex;
  168. justify-content: center;
  169. align-content: center;
  170. align-items: center;
  171. }
  172. }
  173. </style>