shareQrCode.vue 2.1 KB

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