diff --git a/components/qrcode-modal/qrcode-modal.js b/components/qrcode-modal/qrcode-modal.js
index 46324fc..9429b14 100644
--- a/components/qrcode-modal/qrcode-modal.js
+++ b/components/qrcode-modal/qrcode-modal.js
@@ -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: '' })
}
}
})
diff --git a/pages/index/index.js b/pages/index/index.js
index 53bfd37..88a3110 100644
--- a/pages/index/index.js
+++ b/pages/index/index.js
@@ -6,9 +6,7 @@ Page({
data: {
isLoggedIn: false,
loginFailed: false,
- latestRecord: null,
- qrcodeVisible: false,
- qrcodeId: ''
+ latestRecord: null
},
onLoad() {
@@ -82,11 +80,6 @@ Page({
},
showQrcode(e) {
- const id = e.currentTarget.dataset.id
- this.setData({ qrcodeVisible: true, qrcodeId: id })
- },
-
- hideQrcode() {
- this.setData({ qrcodeVisible: false, qrcodeId: '' })
+ this.selectComponent('#qrcodeModal').show(e.currentTarget.dataset.id)
}
})
diff --git a/pages/index/index.wxml b/pages/index/index.wxml
index d969a16..c8f4a86 100644
--- a/pages/index/index.wxml
+++ b/pages/index/index.wxml
@@ -83,5 +83,5 @@
-
+
\ No newline at end of file
diff --git a/pages/records/records.js b/pages/records/records.js
index 601c8f1..712a6c7 100644
--- a/pages/records/records.js
+++ b/pages/records/records.js
@@ -7,9 +7,7 @@ Page({
records: [],
filteredRecords: [],
currentTab: 'all',
- loading: true,
- qrcodeVisible: false,
- qrcodeId: ''
+ loading: true
},
onLoad() {
@@ -86,11 +84,6 @@ Page({
},
showQrcode(e) {
- const id = e.currentTarget.dataset.id
- this.setData({ qrcodeVisible: true, qrcodeId: id })
- },
-
- hideQrcode() {
- this.setData({ qrcodeVisible: false, qrcodeId: '' })
+ this.selectComponent('#qrcodeModal').show(e.currentTarget.dataset.id)
}
})
diff --git a/pages/records/records.wxml b/pages/records/records.wxml
index 2252350..80c8cb9 100644
--- a/pages/records/records.wxml
+++ b/pages/records/records.wxml
@@ -78,5 +78,5 @@
-
+