From 070cb9a997e43501e633f5fd69ebb0af365911d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Sat, 26 Nov 2022 22:27:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E5=85=A5=E7=A0=81=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=AE=9D=E5=B0=8F=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/src/pages/residents/code.vue | 4 ++-- miniprogram/src/utils/qrcode/index.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/miniprogram/src/pages/residents/code.vue b/miniprogram/src/pages/residents/code.vue index f4c4e46..6aced57 100644 --- a/miniprogram/src/pages/residents/code.vue +++ b/miniprogram/src/pages/residents/code.vue @@ -98,7 +98,7 @@ export default { }, methods: { drawCode(text = 'https://www.baidu.com/', foreground = 'red') { - const query = wx.createSelectorQuery() + const query = Taro.createSelectorQuery() query.select('#myQrcode') .fields({ node: true, @@ -108,7 +108,7 @@ export default { var canvas = res[0].node // 调用方法drawQrcode生成二维码 - drawQrcode({ + drawQrcode(Taro, { canvas: canvas, canvasId: 'myQrcode', width: 260, diff --git a/miniprogram/src/utils/qrcode/index.js b/miniprogram/src/utils/qrcode/index.js index d3a9e1a..299fb33 100644 --- a/miniprogram/src/utils/qrcode/index.js +++ b/miniprogram/src/utils/qrcode/index.js @@ -25,7 +25,7 @@ function utf16to8(str) { return out } -function drawQrcode(options, debug) { +function drawQrcode(Taro, options, debug) { options = options || {} options = extend(true, { canvasId: 'myQrcode', @@ -66,18 +66,18 @@ function drawQrcode(options, debug) { } else { return new Promise(function (resolve, reject) { - return resolve(createCanvas()); + return resolve(createCanvas(Taro)); }) } - function createCanvas() { + function createCanvas(Taro) { // create the qrcode itself var qrcode = new QRCode(options.typeNumber, options.correctLevel) qrcode.addData(utf16to8(options.text)) qrcode.make() - const dpr = wx ? wx.getSystemInfoSync().pixelRatio : 1 // 兼容支付宝小程序 + const dpr = Taro.getSystemInfoSync().pixelRatio var canvas = options.canvas const ctx = canvas.getContext('2d') canvas.width = options.width * dpr