shareQrCode.vue 8.5 KB

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