shareQrCode.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <view class="container">
  3. <image @longtap="bc_code" class="backImg" @error="imgerror" :src="imageIs"></image>
  4. <view class="tki-qrcode"><canvas @longtap="bc_code" canvas-id="qrcode" /></view>
  5. </view>
  6. </template>
  7. <script>
  8. import {
  9. spreadBanner
  10. } from '@/api/user.js';
  11. export default {
  12. // components: { tkiQrcode },
  13. data() {
  14. return {
  15. url: '',
  16. backImg: '',
  17. imageIs:'',
  18. userInfo: '',
  19. iswei: 1
  20. };
  21. },
  22. onLoad() {
  23. this.spread();
  24. },
  25. computed: {
  26. cpSize() {
  27. if (this.unit == 'upx') {
  28. return uni.upx2px(this.size);
  29. } else {
  30. return this.size;
  31. }
  32. }
  33. },
  34. onNavigationBarButtonTap(res) {
  35. this.spread();
  36. },
  37. methods: {
  38. // 图片重载
  39. imgerror(){
  40. const that = this;
  41. setTimeout(()=>{
  42. that.imageIs = that.backImg+`?time=${(new Date).getTime()}`
  43. },300)
  44. },
  45. spread() {
  46. uni.showLoading({
  47. title: '加载中'
  48. });
  49. let obj = this;
  50. //#ifdef H5
  51. let ua = navigator.userAgent.toLowerCase(); //获取判断用的对象
  52. console.log(ua, '123456');
  53. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  54. obj.iswei = 2;
  55. console.log('weixin');
  56. }
  57. //#endif
  58. spreadBanner({
  59. //#ifdef H5
  60. type: obj.iswei == 2 ? 2 : 3,
  61. //#endif
  62. //#ifdef MP
  63. type: 1,
  64. //#endif
  65. //#ifdef APP-PLUS
  66. type: 3
  67. //#endif
  68. }).then(({
  69. data
  70. }) => {
  71. console.log(data);
  72. //#ifdef MP
  73. obj.backImg = data[0].poster;
  74. //#endif
  75. //#ifdef H5
  76. obj.backImg = data[0].wap_poster;
  77. //#endif
  78. //#ifdef APP-PLUS
  79. obj.backImg = data[0].wap_poster;
  80. //#endif
  81. obj.imageIs = obj.backImg+`?time=${(new Date).getTime()}`
  82. uni.hideLoading();
  83. });
  84. },
  85. bc_code() {
  86. let that = this;
  87. console.log('保存二维码', this.backImg);
  88. uni.downloadFile({
  89. //获得二维码的临时地址
  90. url: this.backImg,
  91. success: res => {
  92. //console.log('获取url',res)
  93. if (res.statusCode == 200) {
  94. uni.saveImageToPhotosAlbum({
  95. filePath: res.tempFilePath, //传入临时地址
  96. success() {
  97. that.$api.msg('保存成功'); //封装的提示
  98. },
  99. fail() {
  100. that.$api.msg('保存失败');
  101. }
  102. });
  103. }
  104. }
  105. });
  106. }
  107. }
  108. };
  109. </script>
  110. <style lang="scss">
  111. page {
  112. width: 100%;
  113. min-height: 100%;
  114. .container {
  115. width: 100%;
  116. height: 100%;
  117. }
  118. }
  119. .backImg {
  120. position: absolute;
  121. width: 100%;
  122. height: 100%;
  123. }
  124. .portrait {
  125. width: 100%;
  126. text-align: center;
  127. padding-top: 80rpx;
  128. padding-bottom: 30rpx;
  129. image {
  130. width: 250rpx;
  131. height: 250rpx;
  132. }
  133. }
  134. .text {
  135. text-align: center;
  136. width: 100%;
  137. color: #ffffff;
  138. font-size: 55rpx;
  139. letter-spacing: 15rpx;
  140. }
  141. .uid-name {
  142. padding: 50rpx 0rpx;
  143. text-align: center;
  144. width: 100%;
  145. color: #ffffff;
  146. }
  147. .copy-btn {
  148. color: #ffffff;
  149. background-color: #4ba6ed;
  150. border-radius: 50rpx;
  151. width: 170rpx;
  152. line-height: 70rpx;
  153. margin: 0rpx auto;
  154. text-align: center;
  155. }
  156. .tki-qrcode {
  157. position: fixed;
  158. bottom: 10%;
  159. left: 30%;
  160. }
  161. canvas {
  162. width: 150px;
  163. height: 150px;
  164. margin: auto;
  165. }
  166. </style>