index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <view class="swiper-content">
  3. <view class="hander-top p-lr-32 w-s flex-j-sb--a-ct">
  4. <view class="icon-back-wrap"
  5. @click="onBack">
  6. <image class="icon-back"
  7. src="/static/xb-swiper-preview/icon-back.png"
  8. mode="widthFix" />
  9. </view>
  10. <view class="count">{{currentImg + 1}} / {{ imgs.length }}</view>
  11. </view>
  12. <swiper class="swiper-img"
  13. :current="currentImg"
  14. :duration="300"
  15. @change="changeSwiper">
  16. <swiper-item class="swiper-item"
  17. v-for="(item, index) in imgs"
  18. :key="index">
  19. <view class="img-page">
  20. <movable-area scale-area>
  21. <movable-view direction="all"
  22. scale="true"
  23. scale-min="1"
  24. scale-max="4">
  25. <image class="max-img"
  26. :src="item"
  27. :lazy-load="true"
  28. mode="aspectFill" />
  29. </movable-view>
  30. </movable-area>
  31. </view>
  32. </swiper-item>
  33. </swiper>
  34. <view class="item-bottom">
  35. <scroll-view class="scroll-view_H "
  36. :scroll-x="true"
  37. :scroll-into-view="scrollTopIndex"
  38. :scroll-with-animation="true"
  39. scroll-left="20">
  40. <view class="img-page-box scroll-view-item_H"
  41. :class="currentImg == index ? 'img-page-checked' : ''"
  42. v-for="(item, index) in imgs"
  43. :key="index"
  44. :id="`scrollToIndex${index}`"
  45. @click.stop="toImg(index)">
  46. <image class="img"
  47. :src="item"
  48. mode="aspectFill" />
  49. </view>
  50. </scroll-view>
  51. </view>
  52. <!-- <view class="handle-wrap flex-j-sb--a-ct p-lr-32">
  53. <view class="w-64 h-64"
  54. @click="isScale = !isScale">
  55. <image v-show="isScale"
  56. class="w-64 h-64"
  57. src="/static/xb-swiper-preview/icon-scale-yes.png"
  58. mode="widthFix" />
  59. <image v-show="!isScale"
  60. class="w-64 h-64"
  61. src="/static/xb-swiper-preview/icon-scale.png"
  62. mode="widthFix" />
  63. </view>
  64. <view class="w-64 h-64"
  65. @click="isCollect = !isCollect">
  66. <image v-show="isCollect"
  67. class="w-64 h-64"
  68. src="/static/xb-swiper-preview/icon-collect-yes.png"
  69. mode="widthFix" />
  70. <image v-show="!isCollect"
  71. class="w-64 h-64"
  72. src="/static/xb-swiper-preview/icon-collect.png"
  73. mode="widthFix" />
  74. </view>
  75. <view class="w-64 h-64"
  76. @click="isLike = !isLike">
  77. <image v-show="isLike"
  78. class="w-64 h-64"
  79. src="/static/xb-swiper-preview/icon-like-yes.png"
  80. mode="widthFix" />
  81. <image v-show="!isLike"
  82. class="w-64 h-64"
  83. src="/static/xb-swiper-preview/icon-like.png"
  84. mode="widthFix" />
  85. </view>
  86. <image class="w-64 h-64"
  87. src="/static/xb-swiper-preview/icon-set-wallpaper-yes.png"
  88. mode="widthFix" />
  89. <image class="w-64 h-64"
  90. src="/static/xb-swiper-preview/icon-share.png"
  91. mode="widthFix" />
  92. <image class="w-64 h-64"
  93. src="/static/xb-swiper-preview/icon-download.png"
  94. mode="widthFix" />
  95. </view> -->
  96. <view class="pop"
  97. v-if="isPop">
  98. <view class="item"
  99. @click.stop="share()">分享图片</view>
  100. <!-- #ifndef H5 -->
  101. <view class="item"
  102. @click.stop="saveImg(false)">保存图片</view>
  103. <view class="item"
  104. @click.stop="saveImg(true)">保存全部图片</view>
  105. <!-- #endif -->
  106. </view>
  107. </view>
  108. </template>
  109. <script>
  110. export default {
  111. data() {
  112. return {
  113. imgs: [
  114. ],
  115. currentImg: 0,
  116. isPop: false,
  117. scrollTopIndex: "",
  118. isScale: false,
  119. isCollect: false,
  120. isLike: false,
  121. };
  122. },
  123. created() {
  124. this.getSmallPig()
  125. },
  126. onLoad(options) {
  127. // let { imgs, current } = options;
  128. // this.imgs = JSON.parse(imgs);
  129. // this.currentImg = current;
  130. },
  131. methods: {
  132. async getSmallPig() {
  133. const {data: result} = await uni.$http.get('/education/strategy/getSmallPig')
  134. this.imgs = result.data.list
  135. },
  136. changeSwiper(e) {
  137. this.currentImg = e.detail.current;
  138. // console.log("e", e);
  139. this.scrollTopIndex = `scrollToIndex${e.detail.current}`;
  140. },
  141. toImg(index) {
  142. this.currentImg = index;
  143. },
  144. onBack() {
  145. uni.navigateBack();
  146. },
  147. share() {
  148. uni.downloadFile({
  149. // 下面一行时拼接预览PDF的地址!!!
  150. url: this.imgs[this.currentImg],
  151. success: function (res) {
  152. var filePath = res.tempFilePath;
  153. if (!filePath) return;
  154. uni.openDocument({
  155. filePath: filePath,
  156. success: function (res) {
  157. console.log(res);
  158. console.log("打开文档成功");
  159. },
  160. });
  161. },
  162. });
  163. },
  164. saveImg(isAll = false) {
  165. const that = this;
  166. if (!isAll) {
  167. uni.downloadFile({
  168. url: this.imgs[this.currentImg],
  169. success: (res) => {
  170. if (res.statusCode === 200) {
  171. uni.saveImageToPhotosAlbum({
  172. filePath: res.tempFilePath,
  173. success: function () {
  174. uni.showToast({
  175. icon: "none",
  176. title: "保存成功",
  177. });
  178. that.isPop = false;
  179. },
  180. fail: function () {},
  181. });
  182. } else {
  183. }
  184. },
  185. });
  186. return;
  187. }
  188. this.imgs.forEach((item) => {
  189. uni.downloadFile({
  190. url: item,
  191. success: (res) => {
  192. if (res.statusCode === 200) {
  193. uni.saveImageToPhotosAlbum({
  194. filePath: res.tempFilePath,
  195. success: function () {
  196. uni.showToast({
  197. icon: "none",
  198. title: "保存全部成功",
  199. });
  200. that.isPop = false;
  201. },
  202. fail: function () {},
  203. });
  204. } else {
  205. }
  206. },
  207. });
  208. });
  209. },
  210. },
  211. };
  212. </script>
  213. <style lang="scss" scoped>
  214. .swiper-content{
  215. width: 100%;
  216. height: 100vh;
  217. position: relative;
  218. }
  219. movable-view {
  220. display: flex;
  221. align-items: center;
  222. justify-content: center;
  223. width: 100%;
  224. height: 100%;
  225. }
  226. movable-area {
  227. position: fixed;
  228. overflow: hidden;
  229. width: 100%;
  230. height: 100%;
  231. transform: scale();
  232. }
  233. movable-view image {
  234. width: 100%;
  235. }
  236. uni-image > img {
  237. z-index: -1 !important;
  238. }
  239. .hander-top {
  240. position: absolute;
  241. z-index: 1000;
  242. top: 48rpx;
  243. left: 0;
  244. display: flex;
  245. justify-content: space-between;
  246. width: 100%;
  247. padding: 0 32rpx;
  248. box-sizing: border-box;
  249. .icon-back-wrap {
  250. width: 64rpx;
  251. height: 64rpx;
  252. .icon-back{
  253. width: 64rpx;
  254. height: 64rpx;
  255. }
  256. }
  257. .count {
  258. box-sizing: border-box;
  259. padding: 8rpx 24rpx;
  260. color: #fff;
  261. border-radius: 24rpx;
  262. background: rgba(0, 0, 0, .4);
  263. font-size: 28rpx;
  264. }
  265. }
  266. .swiper-img {
  267. width: 100vw;
  268. height: 100vh;
  269. background-color: #000;
  270. .swiper-item {
  271. width: 100vw;
  272. height: 100vh;
  273. .img-page {
  274. display: flex;
  275. align-items: center;
  276. width: 100vw;
  277. height: 100vh;
  278. .max-img {
  279. width: 100%;
  280. height: 100%;
  281. }
  282. }
  283. }
  284. }
  285. .handle-wrap {
  286. position: absolute;
  287. z-index: 100;
  288. bottom: 40rpx;
  289. left: 0;
  290. width: 100%;
  291. display: flex;
  292. justify-content: space-between;
  293. padding: 32rpx;
  294. box-sizing: border-box;
  295. image{
  296. width: 64rpx;
  297. height: 64rpx;
  298. }
  299. width: 100%;
  300. }
  301. .item-bottom {
  302. position: fixed;
  303. z-index: 9999;
  304. bottom: 10rpx;
  305. left: 0rpx;
  306. display: flex;
  307. flex-direction: column;
  308. justify-content: space-between;
  309. width: 100vw;
  310. // height: 200rpx;
  311. padding: 30rpx;
  312. transition: ease-in-out .3s;
  313. }
  314. .small-list-page {
  315. min-height: 60rpx;
  316. }
  317. .scroll-Y {
  318. height: 300rpx;
  319. }
  320. .scroll-view_H {
  321. width: 100%;
  322. box-sizing: border-box;
  323. padding-right: 32rpx;
  324. white-space: nowrap;
  325. }
  326. .scroll-view-item_H {
  327. display: inline-block;
  328. margin-right: 10rpx;
  329. transition: ease-in .1s;
  330. transform: scale(.8);
  331. border-radius: 11rpx;
  332. background: #c2c2c2;
  333. &:last-child {
  334. margin-right: 0;
  335. }
  336. .img {
  337. display: block;
  338. width: 160rpx;
  339. height: 272rpx;
  340. }
  341. }
  342. .img-page-checked {
  343. transform: translateY(-28rpx) scale(1);
  344. }
  345. .pop {
  346. position: fixed;
  347. z-index: 999999;
  348. top: 50%;
  349. left: 50%;
  350. overflow: hidden;
  351. width: 500rpx;
  352. transform: translate(-50%, -50%);
  353. border-radius: 20rpx;
  354. background-color: #fff;
  355. .item {
  356. height: 100rpx;
  357. padding: 0 50rpx;
  358. transition: all .2s;
  359. border-radius: 20rpx;
  360. line-height: 100rpx;
  361. &:active {
  362. background-color: #eee;
  363. }
  364. }
  365. }
  366. </style>