|
@@ -1,4 +1,7 @@
|
|
|
-const QR = require('../../miniprogram_npm/qrcode-base64/index.js')
|
|
|
+const QR = require('../../miniprogram_npm/qrcode-base64/index.js');
|
|
|
+import {
|
|
|
+ base64src
|
|
|
+} from './base64src';
|
|
|
Component({
|
|
|
/**
|
|
|
* 组件的属性列表
|
|
@@ -19,9 +22,13 @@ Component({
|
|
|
errorCorrectLevel: 'M',
|
|
|
size: 500
|
|
|
})
|
|
|
- this.setData({
|
|
|
- qrcodeURL: imgData
|
|
|
- })
|
|
|
+ base64src(imgData, res => {
|
|
|
+ console.log("转换", res) // 返回图片地址,直接赋值到image标签即可
|
|
|
+ this.setData({
|
|
|
+ qrcodeURL: res
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
},
|
|
|
detached: function () {
|
|
|
// 在组件实例被从页面节点树移除时执行
|
|
@@ -105,14 +112,9 @@ Component({
|
|
|
/* 特别注意要先获取图片信息在进行保存,不让保存不了 */
|
|
|
img() {
|
|
|
const that = this;
|
|
|
- /// 通过微信小程序自带方法将base64转为二进制去除特殊符号,再转回base64
|
|
|
- const base64Data = wx.arrayBufferToBase64(wx.base64ToArrayBuffer(this.data.qrcodeURL));
|
|
|
- /// 拼接请求头,data格式可以为image/png或者image/jpeg等,看需求
|
|
|
- const base64ImgUrl = "data:image/png;base64," + base64Data;
|
|
|
-
|
|
|
/* 保存图片到相册 */
|
|
|
wx.saveImageToPhotosAlbum({
|
|
|
- filePath: base64ImgUrl,
|
|
|
+ filePath: that.data.qrcodeURL,
|
|
|
success: function () {
|
|
|
console.log('save success');
|
|
|
wx.showModal({
|
|
@@ -125,17 +127,6 @@ Component({
|
|
|
console.log(res);
|
|
|
}
|
|
|
});
|
|
|
- /* 获取图片信息 */
|
|
|
- /* wx.getImageInfo({
|
|
|
- src: that.data.qrcodeURL,
|
|
|
- success: function (res) {
|
|
|
- console.log(res)
|
|
|
-
|
|
|
- },
|
|
|
- fail:(err => {
|
|
|
- console.log(err)
|
|
|
- })
|
|
|
- }); */
|
|
|
}
|
|
|
}
|
|
|
})
|