shareQrCode.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="container">
  3. <image @longtap="bc_code" mode="widthFix" 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: 2,
  50. //#endif
  51. //#ifdef MP
  52. type: 1,
  53. //#endif
  54. }).then(({
  55. data
  56. }) => {
  57. console.log(data);
  58. //#ifdef MP
  59. obj.backImg = data[0].poster;
  60. //#endif
  61. //#ifdef H5
  62. obj.backImg = data[0].wap_poster;
  63. //#endif
  64. //#ifdef APP-PLUS
  65. obj.backImg = data[0].wap_poster;
  66. //#endif
  67. uni.hideLoading();
  68. });
  69. },
  70. bc_code() {
  71. let that = this;
  72. console.log('保存二维码', this.backImg);
  73. uni.downloadFile({
  74. //获得二维码的临时地址
  75. url: this.backImg,
  76. success: res => {
  77. //console.log('获取url',res)
  78. if (res.statusCode == 200) {
  79. uni.saveImageToPhotosAlbum({
  80. filePath: res.tempFilePath, //传入临时地址
  81. success() {
  82. that.$api.msg('保存成功'); //封装的提示
  83. },
  84. fail() {
  85. that.$api.msg('保存失败');
  86. }
  87. });
  88. }
  89. }
  90. });
  91. }
  92. }
  93. };
  94. </script>
  95. <style lang="scss">
  96. page {
  97. width: 100%;
  98. min-height: 100%;
  99. .container {
  100. width: 100%;
  101. height: 100%;
  102. }
  103. }
  104. .backImg {
  105. position: absolute;
  106. width: 100%;
  107. }
  108. .portrait {
  109. width: 100%;
  110. text-align: center;
  111. padding-top: 80rpx;
  112. padding-bottom: 30rpx;
  113. image {
  114. width: 250rpx;
  115. height: 250rpx;
  116. }
  117. }
  118. .text {
  119. text-align: center;
  120. width: 100%;
  121. color: #ffffff;
  122. font-size: 55rpx;
  123. letter-spacing: 15rpx;
  124. }
  125. .uid-name {
  126. padding: 50rpx 0rpx;
  127. text-align: center;
  128. width: 100%;
  129. color: #ffffff;
  130. }
  131. .copy-btn {
  132. color: #ffffff;
  133. background-color: #4ba6ed;
  134. border-radius: 50rpx;
  135. width: 170rpx;
  136. line-height: 70rpx;
  137. margin: 0rpx auto;
  138. text-align: center;
  139. }
  140. .tki-qrcode {
  141. position: fixed;
  142. bottom: 10%;
  143. left: 30%;
  144. }
  145. canvas {
  146. width: 150px;
  147. height: 150px;
  148. margin: auto;
  149. }
  150. </style>