shareQrCode.vue 8.2 KB

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