refactor: 重构二维码弹窗组件为命令式调用

This commit is contained in:
ws
2026-04-24 17:32:11 +08:00
parent 2cc7d75b08
commit 771cf41b46
5 changed files with 12 additions and 43 deletions
+6 -23
View File
@@ -1,39 +1,22 @@
const drawQrcode = require('../../utils/weapp.qrcode.esm.js').default
Component({
properties: {
visible: {
type: Boolean,
value: false
},
qrcodeId: {
type: String,
value: ''
}
},
data: {
visible: false,
qrcodeId: '',
loading: true
},
observers: {
'visible'(val) {
if (val && this.data.qrcodeId) {
this.setData({ loading: true })
this.draw()
}
}
},
methods: {
draw() {
show(id) {
this.setData({ visible: true, qrcodeId: id, loading: true })
wx.nextTick(() => {
drawQrcode({
width: 200,
height: 200,
canvasId: 'qrcodeCanvas',
_this: this,
text: this.data.qrcodeId,
text: id,
callback: () => {
this.setData({ loading: false })
}
@@ -42,7 +25,7 @@ Component({
},
onClose() {
this.triggerEvent('close')
this.setData({ visible: false, qrcodeId: '' })
}
}
})