shareQrCode.vue 2.0 KB

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