refactor: 重构二维码弹窗组件为命令式调用
This commit is contained in:
@@ -1,39 +1,22 @@
|
|||||||
const drawQrcode = require('../../utils/weapp.qrcode.esm.js').default
|
const drawQrcode = require('../../utils/weapp.qrcode.esm.js').default
|
||||||
|
|
||||||
Component({
|
Component({
|
||||||
properties: {
|
|
||||||
visible: {
|
|
||||||
type: Boolean,
|
|
||||||
value: false
|
|
||||||
},
|
|
||||||
qrcodeId: {
|
|
||||||
type: String,
|
|
||||||
value: ''
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
|
visible: false,
|
||||||
|
qrcodeId: '',
|
||||||
loading: true
|
loading: true
|
||||||
},
|
},
|
||||||
|
|
||||||
observers: {
|
|
||||||
'visible'(val) {
|
|
||||||
if (val && this.data.qrcodeId) {
|
|
||||||
this.setData({ loading: true })
|
|
||||||
this.draw()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
draw() {
|
show(id) {
|
||||||
|
this.setData({ visible: true, qrcodeId: id, loading: true })
|
||||||
wx.nextTick(() => {
|
wx.nextTick(() => {
|
||||||
drawQrcode({
|
drawQrcode({
|
||||||
width: 200,
|
width: 200,
|
||||||
height: 200,
|
height: 200,
|
||||||
canvasId: 'qrcodeCanvas',
|
canvasId: 'qrcodeCanvas',
|
||||||
_this: this,
|
_this: this,
|
||||||
text: this.data.qrcodeId,
|
text: id,
|
||||||
callback: () => {
|
callback: () => {
|
||||||
this.setData({ loading: false })
|
this.setData({ loading: false })
|
||||||
}
|
}
|
||||||
@@ -42,7 +25,7 @@ Component({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onClose() {
|
onClose() {
|
||||||
this.triggerEvent('close')
|
this.setData({ visible: false, qrcodeId: '' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ Page({
|
|||||||
data: {
|
data: {
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
loginFailed: false,
|
loginFailed: false,
|
||||||
latestRecord: null,
|
latestRecord: null
|
||||||
qrcodeVisible: false,
|
|
||||||
qrcodeId: ''
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
@@ -82,11 +80,6 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
showQrcode(e) {
|
showQrcode(e) {
|
||||||
const id = e.currentTarget.dataset.id
|
this.selectComponent('#qrcodeModal').show(e.currentTarget.dataset.id)
|
||||||
this.setData({ qrcodeVisible: true, qrcodeId: id })
|
|
||||||
},
|
|
||||||
|
|
||||||
hideQrcode() {
|
|
||||||
this.setData({ qrcodeVisible: false, qrcodeId: '' })
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -83,5 +83,5 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 二维码弹窗 -->
|
<!-- 二维码弹窗 -->
|
||||||
<qrcode-modal visible="{{qrcodeVisible}}" qrcode-id="{{qrcodeId}}" bind:close="hideQrcode" />
|
<qrcode-modal id="qrcodeModal" />
|
||||||
</view>
|
</view>
|
||||||
@@ -7,9 +7,7 @@ Page({
|
|||||||
records: [],
|
records: [],
|
||||||
filteredRecords: [],
|
filteredRecords: [],
|
||||||
currentTab: 'all',
|
currentTab: 'all',
|
||||||
loading: true,
|
loading: true
|
||||||
qrcodeVisible: false,
|
|
||||||
qrcodeId: ''
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
@@ -86,11 +84,6 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
showQrcode(e) {
|
showQrcode(e) {
|
||||||
const id = e.currentTarget.dataset.id
|
this.selectComponent('#qrcodeModal').show(e.currentTarget.dataset.id)
|
||||||
this.setData({ qrcodeVisible: true, qrcodeId: id })
|
|
||||||
},
|
|
||||||
|
|
||||||
hideQrcode() {
|
|
||||||
this.setData({ qrcodeVisible: false, qrcodeId: '' })
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -78,5 +78,5 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 二维码弹窗 -->
|
<!-- 二维码弹窗 -->
|
||||||
<qrcode-modal visible="{{qrcodeVisible}}" qrcode-id="{{qrcodeId}}" bind:close="hideQrcode" />
|
<qrcode-modal id="qrcodeModal" />
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
Reference in New Issue
Block a user