diff --git a/common/http.interceptor.js b/common/http.interceptor.js index 846e369..3206aef 100644 --- a/common/http.interceptor.js +++ b/common/http.interceptor.js @@ -16,7 +16,7 @@ const install = (Vue, vm) => { // }, // }); Vue.prototype.$u.http.setConfig({ - // baseUrl: 'http://192.168.2.81:4301', + // baseUrl: 'http://192.168.2.241:4301', baseUrl: 'https://bao.chuangtewl.com/prod-api', loadingText: '努力加载中~', loadingTime: 800, diff --git a/pages/index/index.vue b/pages/index/index.vue index 3c7477f..43b9ab6 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -37,6 +37,8 @@ return { bgc: { backgroundColor: " ", + kazuoid:'', + q:'' }, } }, @@ -46,6 +48,62 @@ } else { xBlufi.initXBlufi(1) } + if (option.q) { //判断是否直接扫码进入 解析携带参数 + this.q = option.q + const getQueryParam = (url, paramName) => { + const regex = new RegExp(`[?&]${paramName}=([^&]*)`) + const results = regex.exec(url) + return results ? decodeURIComponent(results[1].replace(/\+/g, ' ')) : null + } + const sceneValue = option.q + const decodedValue = decodeURIComponent(sceneValue) + this.kazuoid = getQueryParam(decodedValue, 'k') + console.log(this.kazuoid,option.q); + if (!this.kazuoid) { //判断是否解析成功 有无id + uni.showModal({ + title: '提示', + content: '无效的二维码', + confirmText: '知道了', + showCancel: false, + success: (res) => { + if (res.confirm) {} + } + }) + return + } + uni.showLoading({ + title: '绑定中...', + mask: true + }) + // 有id的话 一进入直接就进行绑定操作 + this.$u.get(`/app/booth/getBoothDetail/${this.kazuoid}`).then(res => { + uni.hideLoading() + if (res.code == 200) { + + } else { + uni.showModal({ + title: '提示', + content: res.msg, + confirmText: '知道了', + showCancel: false, + success: (res) => { + if (res.confirm) {} + } + }) + } + }).catch(() => { + uni.hideLoading() + uni.showModal({ + title: '提示', + content: '绑定失败,请重试', + confirmText: '知道了', + showCancel: false, + success: (res) => { + if (res.confirm) {} + } + }) + }) + } }, onShow() { xBlufi.notifyStartDiscoverBle({ @@ -71,8 +129,9 @@ this.$u.get(`/getInfo`).then(res => { if (res.code == 200) { if(num == 1){ //跳转爆灯 + console.log(11111); uni.navigateTo({ - url: '/pages/myorder/index' + url: '/pages/myorder/index?q=' + this.q }) }else if(num == 2){ //跳转拼桌 uni.navigateTo({ diff --git a/pages/myorder/index.vue b/pages/myorder/index.vue index 726f506..bc67599 100644 --- a/pages/myorder/index.vue +++ b/pages/myorder/index.vue @@ -166,7 +166,8 @@ findDeviceTimer: null, duration:'', channelId:'', - channellist:[] + channellist:[], + shibainum:0 } }, onLoad(option) { @@ -181,15 +182,7 @@ this.kazuoid = getQueryParam(decodedValue, 'k') console.log(this.kazuoid,option.q); if (!this.kazuoid) { //判断是否解析成功 有无id - uni.showModal({ - title: '提示', - content: '无效的二维码', - confirmText: '知道了', - showCancel: false, - success: (res) => { - if (res.confirm) {} - } - }) + return } uni.showLoading({ @@ -202,9 +195,9 @@ if (res.code == 200) { this.yonghuobj = res.data this.smflag = false - uni.switchTab({ - url:'/pages/index/index' - }) + // uni.switchTab({ + // url:'/pages/index/index' + // }) setTimeout(() => { this.getcishu() }, 500) @@ -235,6 +228,10 @@ }, onShow() { this.tabindex = 0 + xBlufi.initXBlufi(1) + xBlufi.notifyStartDiscoverBle({ + 'isStart': true + }) xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent) this.getqudao() this.getinfo() @@ -357,7 +354,7 @@ }, // 判断离线连接蓝牙 findDevice() { - const matchedDevice = this.devicesarr.find(device => device.name.slice(-12) === this.mac.slice(-12)) //截取最后12位mac号进行判断是否存在相同的 + const matchedDevice = this.devicesarr.find(device => device.name.slice(-12) == this.mac.slice(-12)) //截取最后12位mac号进行判断是否存在相同的 if (matchedDevice) { //如果有则停止搜索 进行连接 xBlufi.notifyStartDiscoverBle({ 'isStart': false @@ -506,7 +503,7 @@ }, // 爆灯成功开始倒计时 需倒计时结束后方可再次点击 startCountdown() { - this.countdown = this.duration + this.countdown = this.yonghuobj.devices[0].duration this.countdownTimer = setInterval(() => { if (this.countdown > 0) { this.countdown-- @@ -545,16 +542,16 @@ if (res.code == 200 && res.data.db >= 1) { if (res.data.iot == false) { //判断是否进行蓝牙充值 为true则进行蓝牙发送命令 if (this.ver_dataflag == 3) { //判断蓝牙是否已经连接 - xBlufi.notifySendCustomData({ - customData: "11time" + this.duration + '@' //进行蓝牙发送命令 - }) - uni.showToast({ - title: "爆灯成功", - icon: 'success', - duration: 2000 - }) - this.getcishu() - this.startCountdown() //爆灯成功后进行禁用倒计时 + // xBlufi.notifySendCustomData({ + // customData: "11time" + this.yonghuobj.devices[0].duration + '@' //进行蓝牙发送命令 + // }) + // uni.showToast({ + // title: "爆灯成功", + // icon: 'success', + // duration: 2000 + // }) + // this.getcishu() + // this.startCountdown() //爆灯成功后进行禁用倒计时 } else { uni.showToast({ title: '设备离线', @@ -571,6 +568,74 @@ this.getcishu() this.startCountdown() //爆灯成功后进行禁用倒计时 } + }else if(res.code == 20001){ + uni.showLoading({ + title: '爆灯开启中...', + mask: true + }) + const findDevice = () =>{ + this.ver_dataflag = 2 + const matchedDevice = this.devicesarr.find(device => { + if(device.name){ + console.log(device.localName.slice(-12),this.yonghuobj.devices[0].mac.slice(-12)); + return device.localName.slice(-12) == this.yonghuobj.devices[0].mac.slice(-12) + } + }) + if (matchedDevice) { + xBlufi.notifyStartDiscoverBle({ + 'isStart': false + }) + xBlufi.notifyConnectBle({ + isStart: true, + deviceId: matchedDevice.deviceId, + name: matchedDevice.name + }) + this.deviceid = matchedDevice.deviceId + this.devicename = matchedDevice.name + setTimeout(()=>{ + if(this.ver_dataflag == 3){ + uni.hideLoading() + xBlufi.notifySendCustomData({ + customData: "11time" + this.yonghuobj.devices[0].duration + '@' //进行蓝牙发送命令 + }) + console.log('10101010'); + this.$u.put(`/app/booth/${this.yonghuobj.boothId}/lighting?requiredIot=false`).then(res={}) + this.getcishu() + this.startCountdown() //爆灯成功后进行禁用倒计时 + let data = { + mac:this.yonghuobj.devices[0].mac, + reason:'用户蓝牙开启', + command:"11time" + this.yonghuobj.devices[0].duration + '@', + result:'sucess' + } + this.$u.post(`/app/commandLog/bluetooth`,data).then(res => {}) + }else{ + this.ver_dataflag = 1 + this.shibainum = 0 + uni.hideLoading() + } + },4000) + } else { + if(this.shibainum < 3){ + this.shibainum++ + this.findDeviceTimer = setTimeout(findDevice.bind(this), 1000) // 使用 bind 保持 this 上下文 + }else{ + this.ver_dataflag = 1 + this.shibainum = 0 + uni.hideLoading() + uni.showModal({ + title: '提示', + content: '爆灯失败', + confirmText: '知道了', + showCancel: false, + success: (res) => { + if (res.confirm) {} + } + }) + } + } + } + findDevice() } else { console.log(res.msg); uni.showToast({