inviteImg.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. toSave() {
  39. uni.showModal({
  40. title: '图片保存',
  41. content: '确定要保存图片吗',
  42. success: e => {
  43. if (e['confirm']) {
  44. //this.saveImgFile();
  45. this.saveImageToPhotosAlbum()
  46. }
  47. }
  48. });
  49. },
  50. saveImageToPhotosAlbum(){
  51. let base64=this.base64;
  52. let fileName = new Date().getTime();
  53. let filePath=wx.env.USER_DATA_PATH + `/hym_pay${fileName}_qrcode.png`;
  54. uni.getFileSystemManager().writeFile({
  55. filePath:filePath , //创建一个临时文件名
  56. data: base64, //写入的文本或二进制数据
  57. encoding: 'base64', //写入当前文件的字符编码
  58. success: res => {
  59. uni.saveImageToPhotosAlbum({
  60. filePath: filePath,
  61. success: function(res2) {
  62. uni.showToast({
  63. title: '保存成功,请从相册选择再分享',
  64. icon:"none",
  65. duration:5000
  66. })
  67. },
  68. fail: function(err) {
  69. // console.log(err.errMsg);
  70. }
  71. })
  72. },
  73. fail: err => {
  74. //console.log(err)
  75. }
  76. })
  77. },
  78. //微信小程序保存到相册
  79. saveEwm:function(e){
  80. let that = this;
  81. //获取相册授权
  82. uni.getSetting({
  83. success(res) {
  84. if (!res.authSetting['scope.writePhotosAlbum']) {
  85. uni.authorize({
  86. scope: 'scope.writePhotosAlbum',
  87. success() {
  88. //这里是用户同意授权后的回调
  89. //that.saveBase64Img(that.qrImg);
  90. that.saveImageToPhotosAlbum()
  91. },
  92. fail() {//这里是用户拒绝授权后的回调
  93. that.openSettingBtnHidden=false
  94. }
  95. })
  96. } else {//用户已经授权过了
  97. //that.saveBase64Img(that.qrImg);
  98. that.saveImageToPhotosAlbum()
  99. }
  100. }
  101. })
  102. },
  103. saveBase64Img(base64) {
  104. //#ifdef APP-PLUS
  105. const bitmap = new plus.nativeObj.Bitmap('test');
  106. bitmap.loadBase64Data(
  107. base64,
  108. function() {
  109. const url = '_doc/' + new Date() + '.png'; // url建议用时间戳命名方式
  110. console.log('url:', url);
  111. bitmap.save(
  112. url,
  113. {
  114. overwrite: true ,// 是否覆盖
  115. quality: 'quality' , // 图片清晰度
  116. },
  117. i => {
  118. uni.saveImageToPhotosAlbum({
  119. filePath: url,
  120. success: function() {
  121. console.log('保存成功');
  122. bitmap.clear();
  123. }
  124. });
  125. },
  126. e => {
  127. console.log('保存失败', e);
  128. bitmap.clear();
  129. }
  130. );
  131. },
  132. e => {
  133. console.log('保存失败', e);
  134. bitmap.clear();
  135. }
  136. );
  137. //#endif
  138. }
  139. }
  140. }
  141. </script>
  142. <style>
  143. .box {
  144. min-height: 100vh;
  145. width: 100%;
  146. background-image: url('http://123.56.219.146:10086/keepCar/yqyl.png');
  147. background-size: 100% 100%;
  148. display: flex;
  149. flex-direction: column;
  150. justify-content: center;
  151. align-items: center;
  152. }
  153. .maBoximg {
  154. width: 377rpx;
  155. height: 377rpx;
  156. border-radius: 19rpx;
  157. background-color: #FFFFFF;
  158. padding: 20rpx;
  159. }
  160. .QR{
  161. width: 100%;
  162. height: 100%;
  163. }
  164. .saveBtn {
  165. width: 411rpx;
  166. height: 115rpx;
  167. margin-top: 60rpx;
  168. }
  169. </style>