createqr2: function (w, h, qrid, text, cb) {
const query = wx.createSelectorQuery().in(this);
var qid = '#' + qrid;
query.select(qid)
.fields({ node: true, size: true })
.exec((res) => {
const canvas = res[0].node;
const ctx = canvas.getContext('2d');
//const dpr = wx.getSystemInfoSync().pixelRatio || 1;
const { pixelRatio: dpr } = wx.getWindowInfo();
// 物理像素大小
canvas.width = w * dpr;
canvas.height = h * dpr;
ctx.scale(dpr, dpr);
drawQrcode({
canvas: canvas,
width: w,
height: h,
padding: 30,
background: '#ffffff',
foreground: '#000000',
text: text
});
// 保存二维码到临时路径
wx.canvasToTempFilePath({
canvas: canvas, // 传节点对象即可
x: 0,
y: 0,
width: w,
height: h,
destWidth: w * dpr,
destHeight: h * dpr,
success(res) {
cb(0, res.tempFilePath);
console.log('二维码临时路径:', res.tempFilePath);
},
fail(err) {
cb(1, '');
console.error(err);
}
});
});
},
