shareQrCode.vue 2.4 KB

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