生成二维码

// 生成二维码或查看二维码
showQRCode (ids) {
console.log('333333', ids)
// console.info(`${process.env.MOBILE_URL}/pages/public/login?id=${this.userInfo.staffCode}`)
this.showQRCodeDialog = true
this.$refs.qrcode.innerHTML = ''
if (!this.qrcodeUrl && !this.qrcode) {
this.$nextTick(() => {
this.qrcode = new QRCode(this.$refs.qrcode, {
width: 130,
height: 130,
text: `https:${this.mobileUrl}/supplier/pages/lobby/lobby?Ids=${ids}`,
colorDark: '#000',
colorLight: '#fff',
correctLevel: QRCode.CorrectLevel.H
})
console.log('this.qrcode', this.qrcode)
setTimeout(() => {
const canvas = document.createElement('canvas')
const qrcode = this.$refs.qrcode
const width = qrcode.offsetWidth
const height = qrcode.offsetHeight
const scale = 2 // 定义任意放大倍数 支持小数
canvas.width = width * scale // 定义canvas 宽度 * 缩放
canvas.height = height * scale // 定义canvas高度 *缩放
canvas.getContext('2d')
html2canvas(this.$refs.qrcode, {
scale: scale, // 添加的scale 参数
useCORS: true,
canvas, // 自定义 canvas
width: width, // dom 原始宽度
height: height // dom 原始高度
}).then(async result => {
this.qrcodeUrl = result.toDataURL('image/png')
})
}, 200)
})
}
}
posted @ 2022-12-02 14:23  爱玩的小丸子  阅读(75)  评论(0编辑  收藏  举报