ShareIndex.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="container">
  3. <swiper
  4. class="posters-box"
  5. :autoplay="false"
  6. :circular="false"
  7. :interval="3000"
  8. :duration="500"
  9. @change="bindchange"
  10. previous-margin="40px"
  11. next-margin="40px">
  12. <block v-for="(item, index ) in shareList" :key="index">
  13. <swiper-item>
  14. <!-- #ifndef MP -->
  15. <image
  16. class="slide-image"
  17. :class="swiperIndex == index ? 'active' : 'quiet'"
  18. mode='aspectFill'
  19. :src="item.wap_poster"
  20. ></image>
  21. <!-- #endif -->
  22. <!-- #ifdef MP -->
  23. <image
  24. class="slide-image"
  25. :class="swiperIndex == index ? 'active' : 'quiet'"
  26. mode='aspectFill'
  27. :src="item.poster"
  28. ></image>
  29. <!-- #endif -->
  30. </swiper-item>
  31. </block>
  32. </swiper>
  33. <!-- #ifndef MP -->
  34. <div class="preserve">
  35. <div class="line"></div>
  36. <div class="tip">长按保存图片</div>
  37. <div class="line"></div>
  38. </div>
  39. <!-- #endif -->
  40. <!-- #ifdef MP -->
  41. <view class='keep' @click='savePosterPath'>保存海报</view>
  42. <!-- #endif -->
  43. </view>
  44. </template>
  45. <script>
  46. import { spreadBanner } from '@/api/user.js';
  47. export default {
  48. data() {
  49. return {
  50. shareList: [],
  51. swiperIndex: 0,
  52. poster: '', // 当前海报
  53. }
  54. },
  55. onLoad() {
  56. this.loadData();
  57. },
  58. methods: {
  59. bindchange(e) {
  60. let shareList = this.shareList;
  61. this.swiperIndex = e.detail.current;
  62. // #ifdef MP
  63. this.poster = shareList[this.swiperIndex].poster;
  64. // #endif
  65. // // #ifndef MP
  66. // this.poster = shareList[this.swiperIndex].wap_poster;
  67. // // #endif
  68. console.log(this.poster)
  69. },
  70. // 保存海报
  71. savePosterPath: function() {
  72. let that = this;
  73. if(that.poster==''){
  74. that.poster = that.shareList[0].poster;
  75. }
  76. uni.downloadFile({
  77. url: that.poster,
  78. success(resFile) {
  79. if (resFile.statusCode === 200) {
  80. uni.getSetting({
  81. success(res) {
  82. if (!res.authSetting['scope.writePhotosAlbum']) {
  83. uni.authorize({
  84. scope: 'scope.writePhotosAlbum',
  85. success() {
  86. uni.saveImageToPhotosAlbum({
  87. filePath: resFile.tempFilePath,
  88. success: function(res) {
  89. return that.$api.msg( '保存成功' );
  90. },
  91. fail: function(res) {
  92. return that.$api.msg( res.errMsg );
  93. },
  94. complete: function(res) {},
  95. })
  96. },
  97. fail() {
  98. uni.showModal({
  99. title: '您已拒绝获取相册权限',
  100. content: '是否进入权限管理,调整授权?',
  101. success(res) {
  102. if (res.confirm) {
  103. uni.openSetting({
  104. success: function(res) {
  105. console.log(res.authSetting)
  106. }
  107. });
  108. } else if (res.cancel) {
  109. return that.$api.msg( '已取消!' );
  110. }
  111. }
  112. })
  113. }
  114. })
  115. } else {
  116. uni.saveImageToPhotosAlbum({
  117. filePath: resFile.tempFilePath,
  118. success: function(res) {
  119. return that.$api.msg( '保存成功' );
  120. },
  121. fail: function(res) {
  122. return that.$api.msg( res.errMsg );
  123. },
  124. complete: function(res) {},
  125. })
  126. }
  127. },
  128. fail(res) {
  129. }
  130. })
  131. } else {
  132. return that.$api.msg( resFile.errMsg );
  133. }
  134. },
  135. fail(res) {
  136. return that.$api.msg( res.errMsg );
  137. }
  138. })
  139. },
  140. // #ifdef MP-WEIXIN
  141. // 保存画图图片到本地
  142. seav(url) {
  143. uni.showLoading({
  144. title: '生成中...',
  145. mask: true
  146. });
  147. uni.saveImageToPhotosAlbum({
  148. filePath: this.poster,
  149. complete(result) {
  150. uni.hideLoading();
  151. console.log(result);
  152. uni.showToast({
  153. title: '保存图片成功!',
  154. duration: 2000,
  155. icon: 'none'
  156. });
  157. }
  158. });
  159. },
  160. // #endif
  161. // 获取海报
  162. loadData() {
  163. let obj = this;
  164. uni.showLoading({
  165. title: '获取中',
  166. mask: true,
  167. })
  168. spreadBanner(
  169. // #ifdef MP
  170. '1'
  171. // #endif
  172. ).then(res => {
  173. uni.hideLoading();
  174. obj.shareList = res.data;
  175. console.log(obj.shareList )
  176. }).catch(err => {
  177. uni.hideLoading();
  178. });
  179. },
  180. }
  181. }
  182. </script>
  183. <style lang="scss">
  184. page {
  185. background: #a3a3a3;
  186. height: 100%;
  187. }
  188. .container {
  189. width: 100%;
  190. .posters-box {
  191. width: 100%;
  192. height: 1000rpx;
  193. margin-top: 40rpx;
  194. .slide-image {
  195. width: 100%;
  196. height: 100%;
  197. border-radius: 15rpx;
  198. }
  199. }
  200. .posters-box .slide-image.active {
  201. transform: none;
  202. transition: all 0.2s ease-in 0s;
  203. }
  204. .posters-box .slide-image.quiet {
  205. transform: scale(0.8333333);
  206. transition: all 0.2s ease-in 0s;
  207. }
  208. .keep {
  209. font-size: 30rpx;
  210. background: $base-color;
  211. color: #fff;
  212. width: 600rpx;
  213. height: 80rpx;
  214. border-radius: 50rpx;
  215. text-align: center;
  216. line-height: 80rpx;
  217. margin: 38rpx auto;
  218. }
  219. }
  220. .preserve {
  221. color: #fff;
  222. text-align: center;
  223. margin-top: 38rpx;
  224. display: flex;
  225. align-items: center;
  226. justify-content: center;
  227. .line {
  228. width: 100rpx;
  229. height: 1px;
  230. background-color: #fff;
  231. }
  232. .tip {
  233. margin: 0 20rpx;
  234. font-size: 28rpx;
  235. }
  236. }
  237. </style>