shareQrCode.vue 5.7 KB

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