shareQrCode.vue 2.8 KB

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