shareQrCode.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 { 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. height: 100%;
  98. }
  99. .portrait {
  100. width: 100%;
  101. text-align: center;
  102. padding-top: 80rpx;
  103. padding-bottom: 30rpx;
  104. image {
  105. width: 250rpx;
  106. height: 250rpx;
  107. }
  108. }
  109. .text {
  110. text-align: center;
  111. width: 100%;
  112. color: #ffffff;
  113. font-size: 55rpx;
  114. letter-spacing: 15rpx;
  115. }
  116. .uid-name {
  117. padding: 50rpx 0rpx;
  118. text-align: center;
  119. width: 100%;
  120. color: #ffffff;
  121. }
  122. .copy-btn {
  123. color: #ffffff;
  124. background-color: #4ba6ed;
  125. border-radius: 50rpx;
  126. width: 170rpx;
  127. line-height: 70rpx;
  128. margin: 0rpx auto;
  129. text-align: center;
  130. }
  131. .tki-qrcode {
  132. position: fixed;
  133. bottom: 10%;
  134. left: 30%;
  135. }
  136. canvas {
  137. width: 150px;
  138. height: 150px;
  139. margin: auto;
  140. }
  141. </style>