diff --git a/miniprogram/api/common/scan.js b/miniprogram/api/common/scan.js index b452118..69d2be6 100644 --- a/miniprogram/api/common/scan.js +++ b/miniprogram/api/common/scan.js @@ -3,10 +3,10 @@ import { } from '../selfRequest'; -// 用户信息 +// 开门 export function callScanUrl(data) { return request({ - url: '/api/equipment/scanOpenDoor', + url: '/api/equipment/scanChangyangOpenDoor', method: "get", data }); diff --git a/miniprogram/pages/index/index.js b/miniprogram/pages/index/index.js index 8bb5ce7..42c0933 100644 --- a/miniprogram/pages/index/index.js +++ b/miniprogram/pages/index/index.js @@ -169,6 +169,18 @@ Page({ onLoad(options) { console.log('onLoad options', options); let _this = this; + + // 获取到二维码原始链接内容 + if (options.q) { + let url = decodeURIComponent(options.q) + let urlParam = getUrlParamsObj(url); + // 是否携带其他参数 + if (!urlParam.noParam) { + _this.setData({ + qrcodeParam: urlParam + }) + } + } }, // 切换tabbar @@ -213,6 +225,11 @@ Page({ bannerList }) }) + // 判断是否开门 + if (_this.data.qrcodeParam) { + // 扫码调用地址 + _this.scanCallUrl() + } } else { app.selfShowMsg(res.msg, '/pages/login/login') } @@ -240,22 +257,59 @@ Page({ } }, - // 成功通知 - showSuccessMsg(msg) { - Notify({ - type: 'success', - top: '160rpx', - message: msg - }); + // 扫一扫 + jumpScan() { + let _this = this; + wx.scanCode({ + scanType: 'qrCode', + success(res) { + console.log('success', res) + let url = res.result; + // 判断二维码是否符合规范 + if (url.indexOf(app.DOMAIN_NAME_PREFIX) != -1) { + let urlParam = getUrlParamsObj(url); + // 判断是否有设备参数 + if (!urlParam.noParam) { + _this.setData({ + qrcodeParam: urlParam + }) + // 扫码调用地址 + _this.scanCallUrl() + } else { + // 危险通知 + app.vantNotifyErrTop(Notify, '请预约会议!') + } + } else { + // 危险通知 + app.vantNotifyErrTop(Notify, '二维码不正确!') + } + }, + fail(res) { + console.log('fail', res) + // 危险通知 + app.vantNotifyErrTop(Notify, '扫码失败!') + } + }) }, - // 危险通知 - showErrMsg(msg) { - Notify({ - type: 'danger', - top: '160rpx', - message: msg - }); + // 扫码调用地址 + scanCallUrl() { + let _this = this; + let qrcodeParam = _this.data.qrcodeParam; + qrcodeParam.userId = wx.getStorageSync('userId') + callScanUrl(qrcodeParam).then(res => { + // 清空扫码数据 + _this.setData({ + qrcodeParam: null + }) + if (res.code == 0) { + // 成功通知 + app.vantNotifySuccessTop(Notify, res.msg) + } else { + // 危险通知 + app.vantNotifyErrTop(Notify, res.msg) + } + }) }, }) \ No newline at end of file diff --git a/miniprogram/pages/index/index.wxml b/miniprogram/pages/index/index.wxml index f385ee4..a1d9566 100644 --- a/miniprogram/pages/index/index.wxml +++ b/miniprogram/pages/index/index.wxml @@ -1,7 +1,7 @@ - + {{parkName}}