inviteImg.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <view class="box">
  3. <view class="maBoximg">
  4. <image :src="qrImg" mode="" class="QR"></image>
  5. </view>
  6. <image src="../../static/img/saveBtn.png" mode="" class="saveBtn" @click="saveEwm"></image>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. data() {
  12. return {
  13. base64:'',
  14. qrImg: '',
  15. openSettingBtnHidden: true,//是否授权
  16. }
  17. },
  18. onLoad() {
  19. this.getQR();
  20. },
  21. methods: {
  22. getQR() {
  23. uni.showLoading({
  24. title: '加载中'
  25. })
  26. let uidStr = uni.getStorageSync("logodata").uid.replace(/\-/g, "");
  27. let url = 'worldKeepCar/worldDistribution/createMiniAppQrCode',
  28. params = {
  29. path: 'pages/homePage/homePage',
  30. scene: uidStr,
  31. }
  32. this.$httpBinary(url, params, 'GET').then(res => {
  33. uni.hideLoading();
  34. this.base64=uni.arrayBufferToBase64(res)
  35. this.qrImg = 'data:image/png;base64,' + uni.arrayBufferToBase64(res)
  36. })
  37. },
  38. //微信小程序保存到相册
  39. saveEwm:function(e){
  40. let that = this;
  41. //获取相册授权
  42. uni.getSetting({
  43. success(res) {
  44. if (!res.authSetting['scope.writePhotosAlbum']) {
  45. uni.authorize({
  46. scope: 'scope.writePhotosAlbum',
  47. success() {
  48. //这里是用户同意授权后的回调
  49. that.saveImage()
  50. },
  51. fail() {//这里是用户拒绝授权后的回调
  52. that.openSettingBtnHidden=false
  53. }
  54. })
  55. } else {//用户已经授权过了
  56. that.saveImage()
  57. }
  58. }
  59. })
  60. },
  61. saveImage(){
  62. let base64=this.base64;
  63. let fileName = new Date().getTime();
  64. let filePath=wx.env.USER_DATA_PATH + `/hym_pay${fileName}_qrcode.png`;
  65. uni.getFileSystemManager().writeFile({
  66. filePath:filePath , //创建一个临时文件名
  67. data: base64, //写入的文本或二进制数据
  68. encoding: 'base64', //写入当前文件的字符编码
  69. success: res => {
  70. uni.saveImageToPhotosAlbum({
  71. filePath: filePath,
  72. success: function(res2) {
  73. uni.showToast({
  74. title: '保存成功',
  75. icon:"none",
  76. duration:5000
  77. })
  78. },
  79. fail: function(err) {
  80. // console.log(err.errMsg);
  81. }
  82. })
  83. },
  84. fail: err => {
  85. //console.log(err)
  86. }
  87. })
  88. },
  89. }
  90. }
  91. </script>
  92. <style>
  93. .box {
  94. min-height: 100vh;
  95. width: 100%;
  96. background: url('http://123.56.219.146:10086/keepCar/yqyl.png') no-repeat;
  97. background-size: 100%;
  98. display: flex;
  99. flex-direction: column;
  100. justify-content: center;
  101. align-items: center;
  102. }
  103. .maBoximg {
  104. width: 377rpx;
  105. height: 377rpx;
  106. border-radius: 19rpx;
  107. background-color: #FFFFFF;
  108. padding: 20rpx;
  109. }
  110. .QR{
  111. width: 100%;
  112. height: 100%;
  113. }
  114. .saveBtn {
  115. width: 411rpx;
  116. height: 115rpx;
  117. margin-top: 60rpx;
  118. }
  119. </style>