shareQrCode.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 {
  9. spreadBanner
  10. } from '@/api/user.js';
  11. export default {
  12. // components: { tkiQrcode },
  13. data() {
  14. return {
  15. url: '',
  16. backImg: '',
  17. };
  18. },
  19. onLoad() {
  20. this.bc_code()
  21. },
  22. methods: {
  23. bc_code() {
  24. let that = this;
  25. console.log('保存二维码', this.backImg)
  26. uni.downloadFile({ //获得二维码的临时地址
  27. //需要一个url保存img的地址
  28. url: this.backImg,
  29. success: (res) => {
  30. //console.log('获取url',res)
  31. if (res.statusCode == 200) {
  32. //保存图片到系统相册,上面uni.是临时保存,现在是永久保存到系统相册
  33. uni.saveImageToPhotosAlbum({
  34. filePath: res.tempFilePath, //传入临时地址
  35. success() {
  36. that.$api.msg('保存成功') //封装的提示
  37. },
  38. fail() {
  39. that.$api.msg('保存失败')
  40. }
  41. })
  42. }
  43. }
  44. })
  45. },
  46. //显示保存临时地址,保存成功后会保存到系统地址永久保存
  47. // bc_code() {
  48. // uni.downloadFile(
  49. // //找一个容器保存拿到的地址
  50. // {
  51. // url: this.backImg,
  52. // success:(res)=>{
  53. // console.log(res,'111')
  54. // if(res.statusCode == 200){
  55. // //如果状态码为200说明有,可以保存成功
  56. // uni.saveImageToPhotosAlbum({
  57. // filePath:res.tempFilePath,//传入临时地址
  58. // success() {
  59. // this.$api.msg('保存成功')
  60. // },
  61. // fail(){
  62. // this.$api.msg('保存失败')
  63. // }
  64. // })
  65. // }
  66. // }
  67. // }
  68. // )
  69. // }
  70. },
  71. }
  72. </script>
  73. <style lang="scss">
  74. page {
  75. width: 100%;
  76. min-height: 100%;
  77. .container {
  78. width: 100%;
  79. height: 100%;
  80. }
  81. }
  82. .backImg {
  83. position: absolute;
  84. width: 100%;
  85. height: 100%;
  86. }
  87. canvas {
  88. width: 150px;
  89. height: 150px;
  90. margin: auto;
  91. }
  92. </style>