shareQrCode.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. <view class="baocun" @click="comfirm(userInfo.uid+'')">复制邀请码</view>
  9. <!-- #ifdef H5 -->
  10. <!-- <view class="baocun">长按二维码保存图片</view> -->
  11. <!-- #endif -->
  12. <!-- #ifdef MP-WEIXIN -->
  13. <view class="baocun" @click="seav">保存图片并转发</view>
  14. <!-- <button open-type="share" class="baocun btn" v-if="scLoading == 2">分享到微信</button> -->
  15. <!-- #endif -->
  16. </view>
  17. </template>
  18. <script>
  19. import weixinObj from "@/plugin/jweixin-module/index.js";
  20. import { mapState } from 'vuex';
  21. import { spreadBanner } from '@/api/user.js';
  22. import { interceptor, saveUrl } from '@/utils/loginUtils';
  23. // #ifdef H5
  24. import { weixindata, weixinlocation,shareLoad } from '@/utils/wxAuthorized';
  25. // #endif
  26. export default {
  27. data() {
  28. return {
  29. rwmListArr: [],
  30. current: 0,
  31. imgSrc: ''
  32. };
  33. },
  34. async onLoad(option) {
  35. uni.showLoading({
  36. title: '邀请图生成中',
  37. mask: true
  38. });
  39. // 判断是否强制登录
  40. weixinObj.hideAllNonBaseMenuItem();
  41. await this.loadCodeList();
  42. // #ifdef MP-WEIXIN
  43. uni.authorize({
  44. scope: 'scope.writePhotosAlbum',
  45. complete() {}
  46. });
  47. // #endif
  48. // #ifdef H5
  49. weixinObj.showAllNonBaseMenuItem()
  50. // weixinObj.showAllNonBaseMenuItem();
  51. this.IndexShare()
  52. // wx.ready(function () { //需在用户可能点击分享按钮前就先调用
  53. // let path = '/#/pages/index/index' + '?';
  54. // console.log(obj.Path)
  55. // // 保存邀请人
  56. // path += 'spread=' + this.userInfo.uid;
  57. // wx.updateAppMessageShareData({
  58. // title: this.userInfo.nickname + '邀请您进入Xingwang鑫旺', // 分享标题
  59. // desc: '欢迎加入Xingwang鑫旺', // 分享描述
  60. // link: this.baseURL + path, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
  61. // imgUrl: '../../static/img/logo.png', // 分享图标
  62. // success: function () {
  63. // // 设置成功
  64. // }
  65. // })
  66. // });
  67. // #endif
  68. },
  69. onShow() {
  70. if (this.loginInterceptor && !this.hasLogin) {
  71. saveUrl();
  72. // 登录拦截
  73. interceptor();
  74. }
  75. },
  76. //下拉刷新
  77. onPullDownRefresh() {
  78. let obj = this;
  79. //监听下拉刷新动作的执行方法,每次手动下拉刷新都会执行一次
  80. setTimeout(function() {
  81. obj.loadCodeList();
  82. uni.stopPullDownRefresh(); //停止下拉刷新动画
  83. }, 1000);
  84. },
  85. computed: {
  86. ...mapState(['weichatObj', 'baseURL', 'urlFile']),
  87. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
  88. },
  89. methods: {
  90. comfirm(text) {
  91. // let text = this.userInfo.uid
  92. console.log(text);
  93. const result = this.uniCopy(text);
  94. if (result === false) {
  95. uni.showToast({
  96. title: '不支持'
  97. });
  98. } else {
  99. uni.showToast({
  100. title: '复制成功',
  101. icon: 'none'
  102. });
  103. }
  104. // this.$refs.popup.close();
  105. },
  106. uniCopy(content) {
  107. /**
  108. * 小程序端 和 app端的复制逻辑
  109. */
  110. //#ifndef H5
  111. uni.setClipboardData({
  112. data: content,
  113. success: function() {
  114. console.log('success');
  115. return true;
  116. }
  117. });
  118. //#endif
  119. /**
  120. * H5端的复制逻辑
  121. */
  122. // #ifdef H5
  123. if (!document.queryCommandSupported('copy')) {
  124. //为了兼容有些浏览器 queryCommandSupported 的判断
  125. // 不支持
  126. return false;
  127. }
  128. let textarea = document.createElement('textarea');
  129. textarea.value = content;
  130. textarea.readOnly = 'readOnly';
  131. document.body.appendChild(textarea);
  132. textarea.select(); // 选择对象
  133. textarea.setSelectionRange(0, content.length); //核心
  134. let result = document.execCommand('copy'); // 执行浏览器复制命令
  135. textarea.remove();
  136. return result;
  137. // #endif
  138. },
  139. loadCodeList() {
  140. let self = this;
  141. // 加载二维码信息
  142. // let andrUid = uni.getStorageSync('andrUid')||'';
  143. spreadBanner({
  144. // #ifdef H5
  145. type: 2,
  146. // #endif
  147. // #ifdef MP
  148. type: 1,
  149. // #endif
  150. }).then(e => {
  151. if (e.status == 200) {
  152. console.log(e.data)
  153. self.rwmListArr = e.data;
  154. // #ifdef H5
  155. self.imgSrc = self.rwmListArr[0].wap_poster;
  156. // #endif
  157. // #ifdef MP-WEIXIN
  158. self.imgSrc = self.rwmListArr[0].poster;
  159. // #endif
  160. }
  161. uni.hideLoading();
  162. });
  163. },
  164. currentChange(e) {
  165. this.current = e.detail.current;
  166. },
  167. // #ifdef H5
  168. IndexShare() {
  169. let obj = this;
  170. let pages = getCurrentPages();
  171. // 获取当前页面
  172. let page = pages[pages.length - 1];
  173. let path = '/#/pages/index/index' + '?';
  174. // 保存传值
  175. for (let i in page.options) {
  176. path += i + '=' + page.options[i] + '&';
  177. }
  178. console.log(obj.Path)
  179. // 保存邀请人
  180. path += 'spread=' + this.userInfo.uid;
  181. let data = {
  182. link: this.baseURL + path,
  183. title: this.userInfo.nickname + '邀请您进入Xingwang鑫旺',
  184. desc:'欢迎加入Xingwang鑫旺',
  185. imgUrl: 'http://xw.liuniu946.com/static/img/logo.png'
  186. };
  187. console.log(data,'分享数据');
  188. shareLoad(data);
  189. },
  190. // #endif
  191. // #ifdef MP-WEIXIN
  192. seav() {
  193. uni.getImageInfo({
  194. src: this.imgSrc,
  195. complete: function (result) {
  196. let path = result.path;
  197. uni.getSetting({
  198. success(res) {
  199. console.log(res)
  200. if (!res.authSetting['scope.writePhotosAlbum']) {
  201. uni.authorize({
  202. scope:'scope.writePhotosAlbum',
  203. success(res) {
  204. uni.saveImageToPhotosAlbum({
  205. filePath:path,
  206. complete(result) {
  207. }
  208. });
  209. },
  210. complete(result) {
  211. uni.showToast({
  212. title: '请先授权保存图片',
  213. duration: 2000,
  214. icon:'none'
  215. });
  216. obj.seav();
  217. }
  218. })
  219. }else{
  220. uni.saveImageToPhotosAlbum({
  221. filePath:path,
  222. complete(result) {
  223. uni.showToast({
  224. title: '保存图片成功!',
  225. duration: 2000,
  226. icon:'none'
  227. });
  228. }
  229. });
  230. }
  231. }
  232. });
  233. }
  234. });
  235. }
  236. // #endif
  237. }
  238. };
  239. </script>
  240. <style lang="scss">
  241. .imgw750h375 {
  242. width: 700rpx;
  243. height: 958rpx;
  244. }
  245. .matop{
  246. margin-top: 40rpx;
  247. }
  248. .andr-shQ-padL30 {
  249. padding-left: 30rpx;
  250. }
  251. .andr-shQ-padR30 {
  252. padding-right: 30rpx;
  253. }
  254. .andr-shQ-Flex {
  255. display: flex;
  256. }
  257. .andr-shQ-FlexDirC {
  258. flex-direction: column;
  259. }
  260. .andr-shQ-w100B {
  261. width: 100%;
  262. }
  263. .andr-shQ-JusCC {
  264. justify-content: center;
  265. }
  266. .andr-shQ-marginT30 {
  267. margin-top: 30rpx;
  268. }
  269. .andr-shQ-bgc06B163 {
  270. background-color: $base-color;
  271. }
  272. .andr-shQ-cFFF {
  273. color: #ffffff;
  274. }
  275. .andr-shQ-bdR50 {
  276. border-radius: 50rpx;
  277. }
  278. .andr-shQ-h86 {
  279. height: 86rpx;
  280. }
  281. .andr-shQ-AIC {
  282. align-items: center;
  283. }
  284. .baocun {
  285. color: #ffffff;
  286. background: $base-color;
  287. text-align: center;
  288. width: 80%;
  289. margin: 50rpx auto;
  290. font-size: 28rpx;
  291. padding: 25rpx 0rpx;
  292. border-radius: 50rpx;
  293. }
  294. .btn{
  295. padding: 0rpx 0rpx !important;
  296. margin: 0rpx auto;
  297. margin-bottom: 100rpx;
  298. }
  299. /* #ifdef H5 */
  300. .cbnagan {
  301. width: 80%;
  302. background: $base-color;
  303. margin: 50rpx auto;
  304. font-size: 28rpx;
  305. text-align: center;
  306. }
  307. /* #endif */
  308. </style>