shareQrCode.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <view class="andr-shQ-padL30 andr-shQ-padR30 andr-shQ-Flex andr-shQ-FlexDirC">
  3. <view class="andr-shQ-w100B andr-shQ-Flex andr-shQ-JusCC">
  4. <swiper class="imgw750h375 matop" :indicator-dots="false" :current="current" @change="currentChange" >
  5. <swiper-item v-for="(item, index) in rwmListArr" :key="index"><image :src="item.wap_poster" mode="aspectFit" class="imgw750h375" /></swiper-item>
  6. </swiper>
  7. </view>
  8. <!-- #ifdef H5 -->
  9. <view class="baocun">长按二维码保存图片</view>
  10. <!-- #endif -->
  11. <!-- #ifdef MP-WEIXIN -->
  12. <view class="baocun" @click="seav">保存图片并转发</view>
  13. <!-- <button open-type="share" class="baocun btn" v-if="scLoading == 2">分享到微信</button> -->
  14. <!-- #endif -->
  15. </view>
  16. </template>
  17. <script>
  18. import { mapState } from 'vuex';
  19. import { spreadBanner } from '@/api/user.js';
  20. import { interceptor, saveUrl } from '@/utils/loginUtils';
  21. // #ifdef H5
  22. import { weixindata } from '@/utils/wxAuthorized';
  23. // #endif
  24. export default {
  25. data() {
  26. return {
  27. rwmListArr: [],
  28. current: 0,
  29. imgSrc: ''
  30. };
  31. },
  32. onLoad(option) {
  33. uni.showLoading({
  34. title: '邀请图生成中',
  35. mask: true
  36. });
  37. // 判断是否强制登录
  38. this.loadCodeList();
  39. // #ifdef MP-WEIXIN
  40. uni.authorize({
  41. scope: 'scope.writePhotosAlbum',
  42. complete() {}
  43. });
  44. // #endif
  45. },
  46. onShow() {
  47. if (this.loginInterceptor && !this.hasLogin) {
  48. saveUrl();
  49. // 登录拦截
  50. interceptor();
  51. }
  52. },
  53. //下拉刷新
  54. onPullDownRefresh() {
  55. let obj = this;
  56. //监听下拉刷新动作的执行方法,每次手动下拉刷新都会执行一次
  57. setTimeout(function() {
  58. obj.loadCodeList();
  59. uni.stopPullDownRefresh(); //停止下拉刷新动画
  60. }, 1000);
  61. },
  62. computed: {
  63. ...mapState(['weichatObj', 'baseURL', 'urlFile']),
  64. },
  65. methods: {
  66. loadCodeList() {
  67. let self = this;
  68. // 加载二维码信息
  69. // let andrUid = uni.getStorageSync('andrUid')||'';
  70. spreadBanner({
  71. // #ifdef H5
  72. type: 2,
  73. // #endif
  74. // #ifdef MP
  75. type: 1,
  76. // #endif
  77. }).then(e => {
  78. if (e.status == 200) {
  79. console.log(e.data)
  80. self.rwmListArr = e.data;
  81. // #ifdef H5
  82. self.imgSrc = self.rwmListArr[0].wap_poster;
  83. // #endif
  84. // #ifdef MP-WEIXIN
  85. self.imgSrc = self.rwmListArr[0].poster;
  86. // #endif
  87. }
  88. uni.hideLoading();
  89. });
  90. },
  91. currentChange(e) {
  92. this.current = e.detail.current;
  93. },
  94. // onShareAppMessage(options){
  95. // console.log(options,'options')
  96. // let userInfo = uni.getStorageSync('userInfo');
  97. // console.log(userInfo)
  98. //   let obj = this;
  99. //   // 设置菜单中的转发按钮触发转发事件时的转发内容
  100. //   let shareObj = {
  101. //     title: "邀请好友领券", // 默认是小程序的名称(可以写slogan等)
  102. //     path: '/pages/index/index?spread='+userInfo.uid, // 默认是当前页面,必须是以‘/’开头的完整路径
  103. //     imageUrl: obj.imgSrc,
  104. //     success: function(res){
  105. //       // 转发成功之后的回调
  106. //       if(res.errMsg == 'shareAppMessage:ok'){
  107. //       }
  108. //     },
  109. //     fail: function(){
  110. //       // 转发失败之后的回调
  111. //       if(res.errMsg == 'shareAppMessage:fail cancel'){
  112. //         // 用户取消转发
  113. //       }else if(res.errMsg == 'shareAppMessage:fail'){
  114. //         // 转发失败,其中 detail message 为详细失败信息
  115. //       }
  116. //     }
  117. //   };
  118. //   // 来自页面内的按钮的转发
  119. //   if( options.from == 'button' ){
  120. //     // 此处可以修改 shareObj 中的内容
  121. //     shareObj.path = '/pages/index/index?spread='+userInfo.uid;
  122. // console.log(shareObj.path,'shareObj.path')
  123. //   }
  124. //   // 返回shareObj
  125. //   return shareObj;
  126. // },
  127. // scClick() {
  128. // let self = this;
  129. // // #ifdef H5
  130. // self.imgSrc = self.rwmListArr[self.current].wap_poster;
  131. // // #endif
  132. // // #ifdef MP-WEIXIN
  133. // self.imgSrc = self.rwmListArr[self.current].poster;
  134. // // #endif
  135. // },
  136. // #ifdef MP-WEIXIN
  137. seav() {
  138. uni.getImageInfo({
  139. src: this.imgSrc,
  140. complete: function (result) {
  141. let path = result.path;
  142. uni.getSetting({
  143. success(res) {
  144. console.log(res)
  145. if (!res.authSetting['scope.writePhotosAlbum']) {
  146. uni.authorize({
  147. scope:'scope.writePhotosAlbum',
  148. success(res) {
  149. uni.saveImageToPhotosAlbum({
  150. filePath:path,
  151. complete(result) {
  152. }
  153. });
  154. },
  155. complete(result) {
  156. uni.showToast({
  157. title: '请先授权保存图片',
  158. duration: 2000,
  159. icon:'none'
  160. });
  161. obj.seav();
  162. }
  163. })
  164. }else{
  165. uni.saveImageToPhotosAlbum({
  166. filePath:path,
  167. complete(result) {
  168. uni.showToast({
  169. title: '保存图片成功!',
  170. duration: 2000,
  171. icon:'none'
  172. });
  173. }
  174. });
  175. }
  176. }
  177. });
  178. }
  179. });
  180. }
  181. // #endif
  182. }
  183. };
  184. </script>
  185. <style lang="scss">
  186. .imgw750h375 {
  187. width: 700rpx;
  188. height: 958rpx;
  189. }
  190. .matop{
  191. margin-top: 40rpx;
  192. }
  193. .andr-shQ-padL30 {
  194. padding-left: 30rpx;
  195. }
  196. .andr-shQ-padR30 {
  197. padding-right: 30rpx;
  198. }
  199. .andr-shQ-Flex {
  200. display: flex;
  201. }
  202. .andr-shQ-FlexDirC {
  203. flex-direction: column;
  204. }
  205. .andr-shQ-w100B {
  206. width: 100%;
  207. }
  208. .andr-shQ-JusCC {
  209. justify-content: center;
  210. }
  211. .andr-shQ-marginT30 {
  212. margin-top: 30rpx;
  213. }
  214. .andr-shQ-bgc06B163 {
  215. background-color: $base-color;
  216. }
  217. .andr-shQ-cFFF {
  218. color: #ffffff;
  219. }
  220. .andr-shQ-bdR50 {
  221. border-radius: 50rpx;
  222. }
  223. .andr-shQ-h86 {
  224. height: 86rpx;
  225. }
  226. .andr-shQ-AIC {
  227. align-items: center;
  228. }
  229. .baocun {
  230. color: #ffffff;
  231. background: $base-color;
  232. text-align: center;
  233. width: 80%;
  234. margin: 50rpx auto;
  235. font-size: 28rpx;
  236. padding: 25rpx 0rpx;
  237. border-radius: 50rpx;
  238. }
  239. .btn{
  240. padding: 0rpx 0rpx !important;
  241. margin: 0rpx auto;
  242. margin-bottom: 100rpx;
  243. }
  244. /* #ifdef H5 */
  245. .cbnagan {
  246. width: 80%;
  247. background: $base-color;
  248. margin: 50rpx auto;
  249. font-size: 28rpx;
  250. text-align: center;
  251. }
  252. /* #endif */
  253. </style>