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: { methods: {
drawCode(text = 'https://www.baidu.com/', foreground = 'red') { drawCode(text = 'https://www.baidu.com/', foreground = 'red') {
const query = wx.createSelectorQuery() const query = Taro.createSelectorQuery()
query.select('#myQrcode') query.select('#myQrcode')
.fields({ .fields({
node: true, node: true,
@ -108,7 +108,7 @@ export default {
var canvas = res[0].node var canvas = res[0].node
// drawQrcode // drawQrcode
drawQrcode({ drawQrcode(Taro, {
canvas: canvas, canvas: canvas,
canvasId: 'myQrcode', canvasId: 'myQrcode',
width: 260, width: 260,

View File

@ -25,7 +25,7 @@ function utf16to8(str) {
return out return out
} }
function drawQrcode(options, debug) { function drawQrcode(Taro, options, debug) {
options = options || {} options = options || {}
options = extend(true, { options = extend(true, {
canvasId: 'myQrcode', canvasId: 'myQrcode',
@ -66,18 +66,18 @@ function drawQrcode(options, debug) {
} else { } else {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
return resolve(createCanvas()); return resolve(createCanvas(Taro));
}) })
} }
function createCanvas() { function createCanvas(Taro) {
// create the qrcode itself // create the qrcode itself
var qrcode = new QRCode(options.typeNumber, options.correctLevel) var qrcode = new QRCode(options.typeNumber, options.correctLevel)
qrcode.addData(utf16to8(options.text)) qrcode.addData(utf16to8(options.text))
qrcode.make() qrcode.make()
const dpr = wx ? wx.getSystemInfoSync().pixelRatio : 1 // 兼容支付宝小程序 const dpr = Taro.getSystemInfoSync().pixelRatio
var canvas = options.canvas var canvas = options.canvas
const ctx = canvas.getContext('2d') const ctx = canvas.getContext('2d')
canvas.width = options.width * dpr canvas.width = options.width * dpr