shareQrCode.vue 5.9 KB

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