share.vue 5.8 KB

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