showImg.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view @click="back" @longpress="isPop = true">
  3. <swiper class="swiper-img" :current="currentImg" :duration="300" @change="changeSwiper">
  4. <swiper-item class="swiper-item" v-for="(item, index) in imgs" :key="index">
  5. <view class="img-page">
  6. <movable-area scale-area>
  7. <movable-view @change.stop='isPop = false' @scale.stop='isPop = false' direction="all" scale="true" scale-min="1" scale-max="4">
  8. <image :src="item" mode="widthFix" :lazy-load="true" />
  9. </movable-view>
  10. </movable-area>
  11. </view>
  12. </swiper-item>
  13. </swiper>
  14. <view class="item-bottom">
  15. <view class="small-list-page">
  16. <view class="small-list" v-if="imgs.length > 1">
  17. <view class="img-page" :class="currentImg == index ? 'img-page-checked' : ''" v-for="(item, index) in imgs"
  18. :key="index" @click.stop="toImg(index)">
  19. <image class="img" border-radius="10rpx" :src="item" mode="aspectFill" />
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="pop" v-if="isPop">
  25. <!-- <view class="item" @click.stop="share()">分享图片</view> -->
  26. <!-- #ifndef H5 -->
  27. <view class="item" @click.stop="saveImg(false)">保存图片</view>
  28. <view class="item" v-if='imgs.length>1' @click.stop="saveImg(true)">保存全部图片</view>
  29. <!-- #endif -->
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. imgs: [],
  38. currentImg: 0,
  39. isPop: false
  40. };
  41. },
  42. onLoad(options) {
  43. let {
  44. imgs,
  45. current
  46. } = options;
  47. this.imgs = JSON.parse(imgs);
  48. this.currentImg = current;
  49. },
  50. methods: {
  51. changeSwiper(e) {
  52. this.currentImg = e.detail.current;
  53. },
  54. toImg(index) {
  55. this.currentImg = index;
  56. },
  57. back() {
  58. if (this.isPop) {
  59. this.isPop = false
  60. return
  61. }
  62. try {
  63. this.$Router.back(1);
  64. } catch (e) {
  65. //TODO handle the exception
  66. uni.navigateBack();
  67. }
  68. },
  69. share() {
  70. uni.downloadFile({
  71. // 下面一行时拼接预览PDF的地址!!!
  72. url: this.imgs[this.currentImg],
  73. success: function(res) {
  74. var filePath = res.tempFilePath;
  75. if (!filePath) return
  76. uni.openDocument({
  77. filePath: filePath,
  78. success: function(res) {
  79. console.log(res);
  80. console.log('打开文档成功');
  81. }
  82. });
  83. }
  84. });
  85. },
  86. saveImg(isAll = false) {
  87. const that = this;
  88. if (!isAll) {
  89. uni.downloadFile({
  90. url: this.imgs[this.currentImg],
  91. success: res => {
  92. if (res.statusCode === 200) {
  93. uni.saveImageToPhotosAlbum({
  94. filePath: res.tempFilePath,
  95. success: function() {
  96. uni.showToast({
  97. icon: "none",
  98. title: "保存成功"
  99. })
  100. that.isPop =false
  101. },
  102. fail: function() {}
  103. });
  104. } else {}
  105. }
  106. });
  107. return;
  108. }
  109. this.imgs.forEach(item => {
  110. uni.downloadFile({
  111. url: item,
  112. success: res => {
  113. if (res.statusCode === 200) {
  114. uni.saveImageToPhotosAlbum({
  115. filePath: res.tempFilePath,
  116. success: function() {
  117. uni.showToast({
  118. icon: "none",
  119. title: "保存全部成功"
  120. })
  121. that.isPop =false
  122. },
  123. fail: function() {}
  124. });
  125. } else {}
  126. }
  127. });
  128. })
  129. }
  130. },
  131. };
  132. </script>
  133. <style lang="scss" scoped>
  134. movable-view {
  135. display: flex;
  136. align-items: center;
  137. justify-content: center;
  138. width: 100%;
  139. height: 100%;
  140. }
  141. movable-area {
  142. height: 100%;
  143. width: 100%;
  144. position: fixed;
  145. overflow: hidden;
  146. }
  147. movable-view image {
  148. width: 100%;
  149. }
  150. uni-image>img {
  151. z-index: -1 !important;
  152. }
  153. .content {
  154. height: 60vh;
  155. }
  156. .swiper-img {
  157. width: 100vw;
  158. height: 100vh;
  159. background-color: #000000;
  160. &>.swiper-item {
  161. width: 100vw;
  162. height: 100vh;
  163. .img-page {
  164. height: 100vh;
  165. display: flex;
  166. align-items: center;
  167. }
  168. }
  169. }
  170. .item-bottom {
  171. width: 100vw;
  172. position: fixed;
  173. z-index: 9999;
  174. bottom: 0;
  175. left: 0rpx;
  176. padding: 30rpx;
  177. transition: ease-in-out 0.3s;
  178. height: 200rpx;
  179. display: flex;
  180. justify-content: space-between;
  181. flex-direction: column;
  182. }
  183. .small-list-page {
  184. min-height: 60rpx;
  185. }
  186. .small-list {
  187. display: flex;
  188. justify-content: center;
  189. align-items: center;
  190. .img-page {
  191. display: inline-block;
  192. margin-right: 20rpx;
  193. border: 2rpx solid #c2c2c2;
  194. transition: ease-in 0.1s;
  195. border-radius: 11rpx;
  196. background: #c2c2c2;
  197. overflow: hidden;
  198. &:last-child {
  199. margin-right: 0;
  200. }
  201. .img {
  202. width: 46rpx;
  203. height: 46rpx;
  204. display: block;
  205. }
  206. }
  207. .img-page-checked {
  208. transform: scale(1.2);
  209. border: 4rpx solid #c2c2c2;
  210. }
  211. }
  212. .pop {
  213. width: 500rpx;
  214. background-color: #FFFFFF;
  215. border-radius: 20rpx;
  216. overflow: hidden;
  217. position: fixed;
  218. top: 50%;
  219. left: 50%;
  220. transform: translate(-50%, -50%);
  221. z-index: 999999;
  222. .item {
  223. line-height: 100rpx;
  224. height: 100rpx;
  225. padding: 0 50rpx;
  226. transition: all .2s;
  227. border-radius: 20rpx;
  228. &:active {
  229. background-color: #eeeeee;
  230. }
  231. }
  232. }
  233. </style>