shareQrCode.vue 7.6 KB

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