shareQrCode.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="container">
  3. <image @longtap="bc_code" mode="aspectFit" 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. background: #294bb6;
  90. .container {
  91. width: 100%;
  92. height: 100%;
  93. }
  94. }
  95. .backImg {
  96. position: absolute;
  97. width: 100%;
  98. height: 100%;
  99. }
  100. .portrait {
  101. width: 100%;
  102. text-align: center;
  103. padding-top: 80rpx;
  104. padding-bottom: 30rpx;
  105. image {
  106. width: 250rpx;
  107. height: 250rpx;
  108. }
  109. }
  110. .text {
  111. text-align: center;
  112. width: 100%;
  113. color: #ffffff;
  114. font-size: 55rpx;
  115. letter-spacing: 15rpx;
  116. }
  117. .uid-name {
  118. padding: 50rpx 0rpx;
  119. text-align: center;
  120. width: 100%;
  121. color: #ffffff;
  122. }
  123. .tki-qrcode {
  124. position: fixed;
  125. bottom: 10%;
  126. left: 30%;
  127. }
  128. canvas {
  129. width: 160px;
  130. height: 160px;
  131. margin: auto;
  132. }
  133. </style>