diff --git a/miniprogram/api/common/scan.js b/miniprogram/api/common/scan.js index 1fc3d0c..b452118 100644 --- a/miniprogram/api/common/scan.js +++ b/miniprogram/api/common/scan.js @@ -4,10 +4,10 @@ import { // 用户信息 -export function callScanUrl(url, paramUrl) { +export function callScanUrl(data) { return request({ - url: url + paramUrl, + url: '/api/equipment/scanOpenDoor', method: "get", - urlIsAll: true + data }); } \ No newline at end of file diff --git a/miniprogram/app.js b/miniprogram/app.js index 225304e..27ee587 100644 --- a/miniprogram/app.js +++ b/miniprogram/app.js @@ -2,12 +2,15 @@ App({ // 郑州小程序配置信息 APPID: 'wx5582a07c1fbbcf06', APPSECRET: 'ad24130a8919c613efd9538f69abafd3', - tenantId : '1', // 地区-郑州 - // 本地测试时不用加/api + tenantId : '10', // 地区-郑州 + // 域名 + DOMAIN_NAME_PREFIX: 'https://chuangzhidasha.haxy.com.cn', + // 本地测试 DOMAIN_NAME: 'http://192.168.0.11:9227', //接口域名 IMG_NAME: 'http://192.168.0.11:9227', - // DOMAIN_NAME: 'http://222.184.49.22:9227', //接口域名 - // IMG_NAME: 'http://222.184.49.22:9227', + // 生产 + // DOMAIN_NAME: 'https://chuangzhidasha.haxy.com.cn/saas-ics', //接口域名 + // IMG_NAME: 'https://chuangzhidasha.haxy.com.cn/saas-ics', globals: { refreshMyPages: false, homedata: {}, diff --git a/miniprogram/pages/index/index.js b/miniprogram/pages/index/index.js index b6cf420..6135909 100644 --- a/miniprogram/pages/index/index.js +++ b/miniprogram/pages/index/index.js @@ -15,6 +15,9 @@ import { getParkRq } from "../../api/index/index.js" +import { + getUrlParamsObj +} from "../../utils/util.js" Page({ data: { @@ -155,12 +158,23 @@ Page({ ], bannerList: [], userDetail: {}, - parkName: '首页' + parkName: '首页', + qrcodeParam: null, }, 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 @@ -220,6 +234,11 @@ Page({ bannerList }) }) + // 判断是否扫码 + if (_this.data.qrcodeParam) { + // 扫码调用地址 + _this.scanCallUrl() + } } else { wx.navigateTo({ url: '/pages/index/parkList/parkList', @@ -227,6 +246,8 @@ Page({ } }, + + // 跳转园区 jumpPark() { wx.navigateTo({ @@ -260,8 +281,24 @@ Page({ success(res) { console.log('success', res) let url = res.result; - // 扫码调用地址 - _this.scanCallUrl(url) + // 判断二维码是否符合规范 + if (url.indexOf(app.DOMAIN_NAME_PREFIX) != -1) { + let urlParam = getUrlParamsObj(url); + // 判断是否有设备参数 + if (!urlParam.noParam) { + _this.setData({ + qrcodeParam: urlParam + }) + // 扫码调用地址 + _this.scanCallUrl() + } else { + // 危险通知 + _this.showErrMsg('请预约会议!') + } + } else { + // 危险通知 + _this.showErrMsg('二维码不正确!') + } }, fail(res) { console.log('fail', res) @@ -272,10 +309,15 @@ Page({ }, // 扫码调用地址 - scanCallUrl(url) { + scanCallUrl() { let _this = this; - let paramUrl = '&userId=' + wx.getStorageSync('userId') - callScanUrl(url, paramUrl).then(res => { + let qrcodeParam = _this.data.qrcodeParam; + qrcodeParam.userId = wx.getStorageSync('userId') + callScanUrl(qrcodeParam).then(res => { + // 清空扫码数据 + _this.setData({ + qrcodeParam: null + }) if (res.code == 0) { // 成功通知 _this.showSuccessMsg(res.msg) diff --git a/miniprogram/pages/my/my.js b/miniprogram/pages/my/my.js index d760496..8d04499 100644 --- a/miniprogram/pages/my/my.js +++ b/miniprogram/pages/my/my.js @@ -10,6 +10,10 @@ import { callScanUrl } from "../../api/common/scan.js" +import { + getUrlParamsObj +} from "../../utils/util.js" + Page({ /** @@ -75,6 +79,7 @@ Page({ url: "/pages/parkRepair/parkRepair", } ], + qrcodeParam: null, }, // 切换tabbar @@ -146,8 +151,24 @@ Page({ success(res) { console.log('success', res) let url = res.result; - // 扫码调用地址 - _this.scanCallUrl(url) + // 判断二维码是否符合规范 + if (url.indexOf(app.DOMAIN_NAME_PREFIX) != -1) { + let urlParam = getUrlParamsObj(url); + // 判断是否有设备参数 + if (!urlParam.noParam) { + _this.setData({ + qrcodeParam: urlParam + }) + // 扫码调用地址 + _this.scanCallUrl() + } else { + // 危险通知 + _this.showErrMsg('请预约会议!') + } + } else { + // 危险通知 + _this.showErrMsg('二维码不正确!') + } }, fail(res) { console.log('fail', res) @@ -158,10 +179,15 @@ Page({ }, // 扫码调用地址 - scanCallUrl(url) { + scanCallUrl() { let _this = this; - let paramUrl = '&userId=' + wx.getStorageSync('userId') - callScanUrl(url, paramUrl).then(res => { + let qrcodeParam = _this.data.qrcodeParam; + qrcodeParam.userId = wx.getStorageSync('userId') + callScanUrl(qrcodeParam).then(res => { + // 清空扫码数据 + _this.setData({ + qrcodeParam: null + }) if (res.code == 0) { // 成功通知 _this.showSuccessMsg(res.msg) diff --git a/miniprogram/utils/util.js b/miniprogram/utils/util.js index 2cbae6a..4c6b787 100644 --- a/miniprogram/utils/util.js +++ b/miniprogram/utils/util.js @@ -215,6 +215,22 @@ function selfArrSum(list) { return count } +// 返回url参数对象 +function getUrlParamsObj(url) { + // 通过 ? 分割获取后面的参数字符串 + let urlStr = url.split('?')[1] + // 创建空对象存储参数 + let obj = {}; + // 再通过 & 将每一个参数单独分割出来 + let paramsArr = urlStr.split('&') + for(let i = 0,len = paramsArr.length;i < len;i++){ + // 再通过 = 将每一个参数分割为 key:value 的形式 + let arr = paramsArr[i].split('=') + obj[arr[0]] = arr[1]; + } + return obj +} + module.exports = { formatTime: formatTime, formatDate: formatDate, @@ -230,5 +246,6 @@ module.exports = { selfFormatTimeYMDH, twoTimeInterval, twoTimeIntervalReturnHours, - selfArrSum + selfArrSum, + getUrlParamsObj } \ No newline at end of file