shareQrCode.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. uni.showToast({
  119. title: '保存成功' ,
  120. icon:"success"
  121. })
  122. return
  123. },
  124. fail: function(res) {
  125. uni.showToast({
  126. title: res.errMsg ,
  127. icon:"none"
  128. })
  129. return
  130. },
  131. complete: function(res) {},
  132. })
  133. },
  134. fail() {
  135. uni.showModal({
  136. title: '您已拒绝获取相册权限',
  137. content: '是否进入权限管理,调整授权?',
  138. success(res) {
  139. if (res.confirm) {
  140. uni.openSetting({
  141. success: function(res) {
  142. console.log(res.authSetting)
  143. }
  144. });
  145. } else if (res.cancel) {
  146. uni.showToast({
  147. title: '已取消!' ,
  148. icon:"none"
  149. })
  150. return ;
  151. }
  152. }
  153. })
  154. }
  155. })
  156. } else {
  157. uni.saveImageToPhotosAlbum({
  158. filePath: resFile.tempFilePath,
  159. success: function(res) {
  160. uni.showToast({
  161. title: '保存成功' ,
  162. icon:"success"
  163. })
  164. return;
  165. },
  166. fail: function(res) {
  167. uni.showToast({
  168. title: res.errMsg ,
  169. icon:"none"
  170. })
  171. return ;
  172. },
  173. complete: function(res) {},
  174. })
  175. }
  176. },
  177. fail(res) {
  178. }
  179. })
  180. } else {
  181. uni.showToast({
  182. title: resFile.errMsg ,
  183. icon:"none"
  184. })
  185. return
  186. }
  187. },
  188. fail(res) {
  189. uni.showToast({
  190. title: res.errMsg ,
  191. icon:"none"
  192. })
  193. return
  194. }
  195. })
  196. },
  197. // #ifdef MP-WEIXIN
  198. // 保存画图图片到本地
  199. seav(url) {
  200. uni.showLoading({
  201. title: '生成中...',
  202. mask: true
  203. });
  204. uni.saveImageToPhotosAlbum({
  205. filePath: this.poster,
  206. complete(result) {
  207. uni.hideLoading();
  208. console.log(result);
  209. uni.showToast({
  210. title: '保存图片成功!',
  211. duration: 2000,
  212. icon: 'none'
  213. });
  214. }
  215. });
  216. },
  217. // #endif
  218. // 获取海报
  219. loadData() {
  220. let obj = this;
  221. uni.showLoading({
  222. title: '获取中',
  223. mask: true,
  224. });
  225. spreadBanner({
  226. // #ifdef H5
  227. type: 2,
  228. // #endif
  229. // #ifdef MP
  230. type: 1
  231. // #endif
  232. }).then(res =>{
  233. uni.hideLoading();
  234. obj.shareList = res.data;
  235. console.log('obj.shareList',obj.shareList);
  236. }).catch(err => {
  237. uni.hideLoading();
  238. });
  239. },
  240. }
  241. }
  242. </script>
  243. <style lang="scss">
  244. page {
  245. background: #a3a3a3;
  246. height: 100%;
  247. }
  248. .container {
  249. width: 100%;
  250. .posters-box {
  251. width: 100%;
  252. height: 1000rpx;
  253. margin-top: 40rpx;
  254. .slide-image {
  255. width: 100%;
  256. height: 100%;
  257. border-radius: 15rpx;
  258. }
  259. }
  260. .posters-box .slide-image.active {
  261. transform: none;
  262. transition: all 0.2s ease-in 0s;
  263. }
  264. .posters-box .slide-image.quiet {
  265. transform: scale(0.8333333);
  266. transition: all 0.2s ease-in 0s;
  267. }
  268. .keep {
  269. font-size: 30rpx;
  270. background: $base-color;
  271. color: #fff;
  272. width: 600rpx;
  273. height: 80rpx;
  274. border-radius: 50rpx;
  275. text-align: center;
  276. line-height: 80rpx;
  277. margin: 38rpx auto;
  278. }
  279. }
  280. .preserve {
  281. color: #fff;
  282. text-align: center;
  283. margin-top: 38rpx;
  284. display: flex;
  285. align-items: center;
  286. justify-content: center;
  287. .line {
  288. width: 100rpx;
  289. height: 1px;
  290. background-color: #fff;
  291. }
  292. .tip {
  293. margin: 0 20rpx;
  294. font-size: 28rpx;
  295. }
  296. }
  297. </style>