dillonlfy / weapp-qrcode Goto Github PK
View Code? Open in Web Editor NEW微信小程序快速生成二维码,支持回调函数返回二维码临时文件
License: MIT License
微信小程序快速生成二维码,支持回调函数返回二维码临时文件
License: MIT License
根据示例给的参数,在微信模拟器和真机调试都可以正常显示,发布为体验版本绘制二维码坐标位置全乱了,扫一扫都不能检查出是个二维码。
qrcode = new QRCode('canvas', {
text: "https://github.com/tomfriwel/weapp-qrcode",
image: '/images/bg.jpg',
padding: 12,
width: qrcode_w,
height: qrcode_w,
colorDark: "#1CA4FC",
colorLight: "white",
correctLevel: QRCode.CorrectLevel.H,
callback: (res) => {
// 生成二维码的临时文件
console.log(res.path)
}
});
老哥,希望弄个ts 的声明文件
onload中
var qrcode = new QRCode('canvas', {
usingIn: this,
text: "https://github.com/tomfriwel/weapp-qrcode",
width: 150,
height: 150,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.H,
callback: function(res) {
console.log(res) // 未打印
},
success: res => {
console.log(res) // 未打印
}
});
1、exportImage的方法我改成了这个,这样保存图片的时候才能够保存成功,如果canvas封装成组件的话,canvasToTempFilePath要传入当前canvas的实例
QRCode.prototype.exportImage = function (callback) {
if (callback && typeof callback === 'function') {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: this._htOption.width,
height: this._htOption.height,
destWidth: this._htOption.width,
destHeight: this._htOption.height,
canvasId: this.canvasId,
success: (res) => {
callback({path: res.tempFilePath})
}
}, this._htOption.usingIn)
}
}
2、另外,在初始化的方法内,生成图片本地链接的方法改成了这个,增加了this._htOption.callback的回调
_oContext.draw(false, () => {
setTimeout(() => {
this.exportImage(this._htOption.callback)
}, 800)
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.