描述:扫一扫

This commit is contained in:
SelfRidicule 2024-05-06 15:24:42 +08:00
parent bccb12a3c1
commit 0524e11e69
5 changed files with 107 additions and 19 deletions

View File

@ -4,10 +4,10 @@ import {
// 用户信息 // 用户信息
export function callScanUrl(url, paramUrl) { export function callScanUrl(data) {
return request({ return request({
url: url + paramUrl, url: '/api/equipment/scanOpenDoor',
method: "get", method: "get",
urlIsAll: true data
}); });
} }

View File

@ -2,12 +2,15 @@ App({
// 郑州小程序配置信息 // 郑州小程序配置信息
APPID: 'wx5582a07c1fbbcf06', APPID: 'wx5582a07c1fbbcf06',
APPSECRET: 'ad24130a8919c613efd9538f69abafd3', APPSECRET: 'ad24130a8919c613efd9538f69abafd3',
tenantId : '1', // 地区-郑州 tenantId : '10', // 地区-郑州
// 本地测试时不用加/api // 域名
DOMAIN_NAME_PREFIX: 'https://chuangzhidasha.haxy.com.cn',
// 本地测试
DOMAIN_NAME: 'http://192.168.0.11:9227', //接口域名 DOMAIN_NAME: 'http://192.168.0.11:9227', //接口域名
IMG_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: { globals: {
refreshMyPages: false, refreshMyPages: false,
homedata: {}, homedata: {},

View File

@ -15,6 +15,9 @@ import {
getParkRq getParkRq
} from "../../api/index/index.js" } from "../../api/index/index.js"
import {
getUrlParamsObj
} from "../../utils/util.js"
Page({ Page({
data: { data: {
@ -155,12 +158,23 @@ Page({
], ],
bannerList: [], bannerList: [],
userDetail: {}, userDetail: {},
parkName: '首页' parkName: '首页',
qrcodeParam: null,
}, },
onLoad(options) { onLoad(options) {
console.log('onLoad options', options); console.log('onLoad options', options);
let _this = this; let _this = this;
// 获取到二维码原始链接内容
if (options.q) {
let url = decodeURIComponent(options.q)
let urlParam = getUrlParamsObj(url);
if (!urlParam.noParam) {
_this.setData({
qrcodeParam: urlParam
})
}
}
}, },
// 切换tabbar // 切换tabbar
@ -220,6 +234,11 @@ Page({
bannerList bannerList
}) })
}) })
// 判断是否扫码
if (_this.data.qrcodeParam) {
// 扫码调用地址
_this.scanCallUrl()
}
} else { } else {
wx.navigateTo({ wx.navigateTo({
url: '/pages/index/parkList/parkList', url: '/pages/index/parkList/parkList',
@ -227,6 +246,8 @@ Page({
} }
}, },
// 跳转园区 // 跳转园区
jumpPark() { jumpPark() {
wx.navigateTo({ wx.navigateTo({
@ -260,8 +281,24 @@ Page({
success(res) { success(res) {
console.log('success', res) console.log('success', res)
let url = res.result; 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) { fail(res) {
console.log('fail', res) console.log('fail', res)
@ -272,10 +309,15 @@ Page({
}, },
// 扫码调用地址 // 扫码调用地址
scanCallUrl(url) { scanCallUrl() {
let _this = this; let _this = this;
let paramUrl = '&userId=' + wx.getStorageSync('userId') let qrcodeParam = _this.data.qrcodeParam;
callScanUrl(url, paramUrl).then(res => { qrcodeParam.userId = wx.getStorageSync('userId')
callScanUrl(qrcodeParam).then(res => {
// 清空扫码数据
_this.setData({
qrcodeParam: null
})
if (res.code == 0) { if (res.code == 0) {
// 成功通知 // 成功通知
_this.showSuccessMsg(res.msg) _this.showSuccessMsg(res.msg)

View File

@ -10,6 +10,10 @@ import {
callScanUrl callScanUrl
} from "../../api/common/scan.js" } from "../../api/common/scan.js"
import {
getUrlParamsObj
} from "../../utils/util.js"
Page({ Page({
/** /**
@ -75,6 +79,7 @@ Page({
url: "/pages/parkRepair/parkRepair", url: "/pages/parkRepair/parkRepair",
} }
], ],
qrcodeParam: null,
}, },
// 切换tabbar // 切换tabbar
@ -146,8 +151,24 @@ Page({
success(res) { success(res) {
console.log('success', res) console.log('success', res)
let url = res.result; 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) { fail(res) {
console.log('fail', res) console.log('fail', res)
@ -158,10 +179,15 @@ Page({
}, },
// 扫码调用地址 // 扫码调用地址
scanCallUrl(url) { scanCallUrl() {
let _this = this; let _this = this;
let paramUrl = '&userId=' + wx.getStorageSync('userId') let qrcodeParam = _this.data.qrcodeParam;
callScanUrl(url, paramUrl).then(res => { qrcodeParam.userId = wx.getStorageSync('userId')
callScanUrl(qrcodeParam).then(res => {
// 清空扫码数据
_this.setData({
qrcodeParam: null
})
if (res.code == 0) { if (res.code == 0) {
// 成功通知 // 成功通知
_this.showSuccessMsg(res.msg) _this.showSuccessMsg(res.msg)

View File

@ -215,6 +215,22 @@ function selfArrSum(list) {
return count 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 = { module.exports = {
formatTime: formatTime, formatTime: formatTime,
formatDate: formatDate, formatDate: formatDate,
@ -230,5 +246,6 @@ module.exports = {
selfFormatTimeYMDH, selfFormatTimeYMDH,
twoTimeInterval, twoTimeInterval,
twoTimeIntervalReturnHours, twoTimeIntervalReturnHours,
selfArrSum selfArrSum,
getUrlParamsObj
} }