hx-preview-img.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <view class="previewImg" @touchmove.stop.prevent="mpClear" :animation="formAnimationData">
  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. <!-- <movable-area class="movable_box" :scale-area="true" >
  10. <movable-view class="movable_view" :scale="false" direction="all" :scale-min="0.5" :scale-value="1" :scale-max="3" >
  11. </movable-view>
  12. </movable-area> -->
  13. <view class="bg_img" :style="{ backgroundImage: 'url('+ src +')'}"></view>
  14. </swiper-item>
  15. </swiper>
  16. </view>
  17. <view class="pagebox" v-if="picList.length>0">{{ Number(currentIndex) + 1 }} / {{ picList.length }}</view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'hx-preview-img',
  23. props: {
  24. current: {
  25. type: String,
  26. default: ''
  27. },
  28. list: {
  29. type: Array,
  30. default: function(){
  31. return new Array();
  32. }
  33. },
  34. //开始
  35. start: {
  36. type: Number,
  37. default: 0
  38. },
  39. },
  40. data() {
  41. return {
  42. picList: [],
  43. indicatorDots: false,
  44. autoplay: false,
  45. duration: 50,
  46. circular: true,
  47. currentIndex: 0,
  48. isShowSwiper: false,
  49. animation:{},
  50. formAnimationData: {},
  51. };
  52. },
  53. watch: {
  54. list(val) {
  55. },
  56. current(val){
  57. },
  58. start(val,oldVal) {
  59. var that = this;
  60. if(val<=0){
  61. this.close()
  62. }else{
  63. //图片预览器为显示
  64. this.$emit("status",true)
  65. this.picListInit();
  66. }
  67. }
  68. },
  69. created() {
  70. },
  71. methods: {
  72. picListInit() {
  73. let that = this
  74. if(!this.current || !this.list){
  75. return;
  76. }
  77. for(var i in this.list){
  78. if(this.current == this.list[i]){
  79. this.currentIndex = i;
  80. break;
  81. }
  82. }
  83. this.picList=this.list;
  84. that.animation = uni.createAnimation({
  85. //duration: 1000,
  86. timingFunction: 'ease',
  87. })
  88. that.animation.top(0).bottom(0).left(0).right(0).step({ duration: 0 })
  89. that.animation.opacity(1).step({ duration: 300 })
  90. that.formAnimationData = that.animation.export()
  91. },
  92. changeSwiper(e) {
  93. this.currentIndex = e.target.current;
  94. },
  95. mpClear(e) {
  96. // TODO nvue 取消冒泡
  97. e.stopPropagation()
  98. },
  99. close(){
  100. var that = this;
  101. //图片预览器为隐藏
  102. this.$emit("status",false)
  103. this.animation = uni.createAnimation({
  104. //duration: 1000,
  105. timingFunction: 'ease',
  106. })
  107. this.animation.scale(0,0).opacity(0).step({ duration: 300 })
  108. this.animation.top(0).bottom(0).left("-100%").right("100%").step({ duration: 0 })
  109. this.formAnimationData = this.animation.export()
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .previewImg {
  116. opacity: 0;
  117. position: fixed;
  118. top: 0;
  119. right: 100%;
  120. left: -100%;
  121. width: 100%;
  122. height: 100%;
  123. z-index: 99999999;
  124. .close{
  125. position: absolute;
  126. top: calc(var(--status-bar-height) + 15px);
  127. left: 15px;
  128. z-index: 6;
  129. color: #ffffff;
  130. font-size: 14px;
  131. background-color: rgba(255, 255, 255, 0.4);
  132. padding: 0 9px;
  133. border-radius: 4px;
  134. text-align: center;
  135. display: flex;
  136. align-items: center;
  137. height: 27px;
  138. }
  139. .pagebox{
  140. position: absolute;
  141. z-index: 6;
  142. color: #fff;
  143. bottom: 20rpx;
  144. text-align: center;
  145. width: 100%;
  146. }
  147. .mask {
  148. position: absolute;
  149. top: 0;
  150. left: 0;
  151. width: 100%;
  152. height: 100%;
  153. display: flex;
  154. justify-content: center;
  155. align-items: center;
  156. background-color: #000;
  157. z-index: 5;
  158. .my_swiper {
  159. width: 100%;
  160. height: 60vh;
  161. .bg_img {
  162. background-size: 100% auto;
  163. background-repeat: no-repeat;
  164. background-position:center;
  165. width: 100%;
  166. height: 100%;
  167. }
  168. .movable_box{
  169. width: 100%;
  170. height: 60vh;
  171. .movable_view{
  172. width: 100%;
  173. height: 60vh;
  174. }
  175. }
  176. }
  177. }
  178. .pic_list {
  179. display: flex;
  180. flex-flow: row wrap;
  181. > view {
  182. flex: 0 0 33.3vw;
  183. height: 33.3vw;
  184. padding: 1vw;
  185. > image {
  186. width: 100%;
  187. height: 100%;
  188. }
  189. }
  190. }
  191. }
  192. </style>