diff --git a/pages/sign/sign.vue b/pages/sign/sign.vue index 57a9999..ac268bd 100644 --- a/pages/sign/sign.vue +++ b/pages/sign/sign.vue @@ -2,7 +2,7 @@ @@ -27,38 +27,61 @@ export default { siteName: '', success: false, type: 0, // 0进 / 1出 + timer: null, }; }, computed: { ...mapState('site', ['site']), + ...mapState('user', ['token']), typeText() { return this.type === 0 ? '进场打卡' : '出场打卡'; }, }, onLoad(options) { - try { - const query = formatQuery(decodeURIComponent(options.scene)); - console.log('query: ', query); - const { d, t } = query; - if (!d || !t) { - uni.showToast({ - title: '二维码参数错误', - icon: 'none', - duration: 3000, - }); - } - this.siteId = d; - this.type = +t; - this.getSiteByQrId({ param: { id: d, type: t } }); - } catch (error) { - console.log('error: ', error); - } + console.log('options: ', options); + this.init(options); }, methods: { ...mapActions('site', ['sign', 'getSiteByQrId']), + + init(options) { + try { + const query = formatQuery(decodeURIComponent(options.scene)); + console.log('query: ', query); + const { d, t } = query; + if (!d || !t) { + uni.showToast({ + title: '二维码参数错误', + icon: 'none', + duration: 3000, + }); + } + this.siteId = d; + this.type = +t; + this.getSignInfo({ param: { id: d, type: t } }); + } catch (error) { + console.log('error: ', error); + } + }, + + /** + * 获取场所的基本信息 + * @param {object} params 提交给后端的参数 + */ + getSignInfo(params) { + this.timer && clearInterval(this.timer); + if (!this.token) { + this.timer = setTimeout(() => { + this.getSignInfo(params); + }, 100); + } else { + this.getSiteByQrId(params); + } + }, + /** * 扫码打卡 * @param {string} siteId 场所id