shareQrCode.vue 2.3 KB

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