1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

出入码支持支付宝小程序

This commit is contained in:
程序员小墨 2022-11-26 22:27:52 +08:00
parent 47cb9a730b
commit 070cb9a997
2 changed files with 6 additions and 6 deletions

View File

@ -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,

View File

@ -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