From 4f0d5c43901221925d0e79b79c2ca0bfc7e2d860 Mon Sep 17 00:00:00 2001 From: "3321822538@qq.com" <3321822538@qq.com> Date: Sat, 2 Nov 2024 15:23:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- page_components/eletj.vue | 45 +-- page_components/fuwu/index.vue | 589 ++++++++++++++++++++++++++--- page_components/wifilist/index.vue | 42 +- 3 files changed, 559 insertions(+), 117 deletions(-) diff --git a/page_components/eletj.vue b/page_components/eletj.vue index 1d7948d..b443a8d 100644 --- a/page_components/eletj.vue +++ b/page_components/eletj.vue @@ -543,6 +543,15 @@ this.imgflag = true } }, 1000) + setTimeout(() =>{ + if(this.ver_data == '' || this.ver_data == null){ + uni.showToast({ + title: '未搜索到蓝牙,请重试', + icon: 'success', + duration: 1500 + }) + } + },15000) } else { // console.log(this.tdtxt,'020202'); if (this.tdtxt == '开启') { @@ -1240,24 +1249,20 @@ const date = new Date(dateTimeString) // 获取当前时间 const now = new Date() - // 计算时间差(毫秒) const diff = now - date - // 将毫秒转换为天、小时、分钟和秒 const days = Math.floor(diff / (1000 * 60 * 60 * 24)) const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)) const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)) const seconds = Math.floor((diff % (1000 * 60)) / 1000) - // 创建一个对象来存储结果,并忽略零值 const timeDifference = { days: days > 0 ? days : undefined, hours: hours > 0 ? hours : undefined, minutes: minutes > 0 ? minutes : undefined, seconds: seconds > 0 ? seconds : undefined - }; - + } // 转换为字符串,忽略未定义的属性 let result = '' if (timeDifference.days !== undefined) { @@ -1329,7 +1334,6 @@ setTimeout(() => { this.getDevice() }, 2000) - // this.loadings=true // this.initChart() } else { @@ -1350,14 +1354,11 @@ changeidx(index) { this.curtitidx = index }, - toydfx() { uni.navigateTo({ url: "/page_components/eletj?id=" + this.id }) }, - - funListenDeviceMsgEvent: function(options) { switch (options.type) { case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS: @@ -1402,7 +1403,7 @@ setTimeout(() => { if (!this.hasCalledGetczly) { - this.btnjieshu() + // this.btnjieshu() this.hasCalledGetczly = true } // this.czflag = false @@ -1469,29 +1470,7 @@ // 返回解析后的数据对象 return parsedData }, - - // parseCustomData(data) { - // // 将字符串按照 "@" 分割成数组 - // const dataArray = data.split('@'); - // // 根据约定,解析各个字段的值 - // const voltage = parseFloat(dataArray[0].substring(1)); // 去除前缀 "V",并将字符串转换为浮点数 - // const switchState = dataArray[1].substring(1); // 去除前缀 "S" - // const current = parseFloat(dataArray[2].substring(1)); // 去除前缀 "A",并将字符串转换为浮点数 - // const power = parseFloat(dataArray[4].substring(1)); // 去除前缀 "P",并将字符串转换为浮点数 - // const remainingPower = parseFloat(dataArray[5].substring(1)); // 去除前缀 "M",并将字符串转换为浮点数 - // const setMode = dataArray[6].substring(1); // 去除前缀 "T" - - // // 返回解析后的数据对象 - // return { - // voltage, - // switchState, - // current, - // power, - // remainingPower, - // setMode - // } - // }, - + } } diff --git a/page_components/fuwu/index.vue b/page_components/fuwu/index.vue index 6f454e3..ec5cdb4 100644 --- a/page_components/fuwu/index.vue +++ b/page_components/fuwu/index.vue @@ -204,7 +204,9 @@ mchShowBillMobile:'', telslag:false, userId:'', - hasCalledGetczly:false + hasCalledGetczly:false, + hasCalledGetczlys:false, + hasCalledGetczlyss:false } }, onLoad(option) { @@ -784,11 +786,49 @@ fail(err) { console.error('获取已连接蓝牙设备信息失败:',err) that.ver_data = '' - uni.showToast({ - title: '蓝牙已断开,充值失败', - icon: 'none', - duration: 2000 + uni.showModal({ + title: '温馨提示', + content: '设备开启失败,检测到设备蓝牙已断开', + showCancel: false, + success: function(res) { + // uni.showLoading({ + // title: '蓝牙连接中' + // }) + } }) + // this.czflag = true + // let that = this + // xBlufi.initXBlufi(1); + // xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvents); + // xBlufi.notifyStartDiscoverBle({ + // 'isStart': true + // }) + // setTimeout(() => { + // xBlufi.notifyStartDiscoverBle({ + // 'isStart': false + // }) + // if (that.devicesList.length > 0) { + // xBlufi.notifyConnectBle({ + // isStart: true, + // deviceId: that.deviceId, + // name: that.name + // }) + // } + // }, 2000) + // setTimeout(()=>{ + // if(this.ver_data == ''){ + // uni.showToast({ + // title: '未连接成功,如多次失败请点击右上角联系客服咨询', + // icon: 'none', + // duration: 5000 + // }) + // this.czflag = false + // this.zhifuflag = false + // setTimeout(()=>{ + // uni.hideLoading() + // },5000) + // } + // },10000) } }) } else { @@ -880,31 +920,71 @@ }, fail(err) { console.error('获取已连接蓝牙设备信息失败:',err) + let that = this that.ver_data = '' - uni.showToast({ - title: '蓝牙已断开,充值失败', - icon: 'none', - duration: 2000 - }) - } - }) - that.$u.get(`/app/bill/recharge/${dingobj}/bluetoothSuccess`).then(res => { - if (res.code == 200) { - that.zhifuflag = false - console.log('蓝牙离线充值成功11') - setTimeout(() => { - uni.reLaunch({ - url:'/page_components/eletj?id=' + that.orderno - }) - },1000) - }else{ - uni.showToast({ - title: res.msg, - icon: 'none', - duration: 2000 - }) + uni.showModal({ + title: '温馨提示', + content: '设备开启失败,检测到设备蓝牙已断开', + showCancel: false, + success: function(res) { + // uni.showLoading({ + // title: '蓝牙连接中' + // }) } }) + // that.czflag = true + // xBlufi.initXBlufi(1); + // xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEventss); + // xBlufi.notifyStartDiscoverBle({ + // 'isStart': true + // }) + // setTimeout(() => { + // xBlufi.notifyStartDiscoverBle({ + // 'isStart': false + // }) + // if (that.devicesList.length > 0) { + // xBlufi.notifyConnectBle({ + // isStart: true, + // deviceId: that.deviceId, + // name: that.name + // }) + // } + // }, 2000) + // setTimeout(()=>{ + // if(that.ver_data == ''){ + // uni.showToast({ + // title: '未连接成功,如多次失败请点击右上角联系客服咨询', + // icon: 'none', + // duration: 5000 + // }) + // that.czflag = false + // that.zhifuflag = false + // setTimeout(()=>{ + // uni.hideLoading() + // },5000) + // } + // },10000) + } + }) + if(that.ver_data != ''){ + that.$u.get(`/app/bill/recharge/${dingobj}/bluetoothSuccess`).then(res => { + if (res.code == 200) { + that.zhifuflag = false + console.log('蓝牙离线充值成功11') + setTimeout(() => { + uni.reLaunch({ + url:'/page_components/eletj?id=' + that.orderno + }) + },1000) + }else{ + uni.showToast({ + title: res.msg, + icon: 'none', + duration: 2000 + }) + } + }) + } } else { console.log('手机未连接网络') // this.baiflag = false @@ -1047,12 +1127,50 @@ }, fail(err) { console.error('获取已连接蓝牙设备信息失败:',err) + let that = this that.ver_data = '' - uni.showToast({ - title: '蓝牙已断开,充值失败', - icon: 'none', - duration: 2000 + uni.showModal({ + title: '温馨提示', + content: '设备开启失败,检测到设备蓝牙已断开', + showCancel: false, + success: function(res) { + // uni.showLoading({ + // title: '蓝牙连接中' + // }) + } }) + // that.czflag = true + // xBlufi.initXBlufi(1); + // xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvents); + // xBlufi.notifyStartDiscoverBle({ + // 'isStart': true + // }) + // setTimeout(() => { + // xBlufi.notifyStartDiscoverBle({ + // 'isStart': false + // }) + // if (that.devicesList.length > 0) { + // xBlufi.notifyConnectBle({ + // isStart: true, + // deviceId: that.deviceId, + // name: that.name + // }) + // } + // }, 2000) + // setTimeout(()=>{ + // if(that.ver_data == ''){ + // uni.showToast({ + // title: '未连接成功,如多次失败请点击右上角联系客服咨询', + // icon: 'none', + // duration: 5000 + // }) + // that.czflag = false + // that.zhifuflag = false + // setTimeout(()=>{ + // uni.hideLoading() + // },5000) + // } + // },10000) } }) } else { @@ -1140,44 +1258,100 @@ xBlufi.notifySendCustomData({ customData: "time@" + that.jine }) + + if(that.ver_data != ''){ + that.$u.get(`/app/bill/recharge/${dingobj}/bluetoothSuccess`).then(res => { + if (res.code == 200) { + that.zhifuflag = false + console.log('蓝牙离线充值成功11') + setTimeout(() => { + if(that.ver_data == ''){ + uni.showToast({ + title: '蓝牙已断开,蓝牙充值失败', + icon: 'none', + duration: 2000 + }) + }else{ + that.zhifuflag = false + uni.reLaunch({ + url:'/page_components/eletj?id=' + that.orderno + }) + } + },1000) + }else{ + uni.showToast({ + title: res.msg, + icon: 'none', + duration: 2000 + }) + } + }) + } + },1000) + }, fail(err) { console.error('获取已连接蓝牙设备信息失败:',err) + let that = this that.ver_data = '' - uni.showToast({ - title: '蓝牙已断开,充值失败', - icon: 'none', - duration: 2000 - }) - } - }) - that.$u.get(`/app/bill/recharge/${dingobj}/bluetoothSuccess`).then(res => { - if (res.code == 200) { - that.zhifuflag = false - console.log('蓝牙离线充值成功11') - setTimeout(() => { - if(that.ver_data == ''){ - uni.showToast({ - title: '蓝牙已断开,蓝牙充值失败', - icon: 'none', - duration: 2000 - }) - }else{ - that.zhifuflag = false - uni.reLaunch({ - url:'/page_components/eletj?id=' + that.orderno - }) - } - },1000) - }else{ - uni.showToast({ - title: res.msg, - icon: 'none', - duration: 2000 - }) + uni.showModal({ + title: '温馨提示', + content: '设备开启失败,检测到设备蓝牙已断开', + showCancel: false, + success: function(res) { + // uni.showLoading({ + // title: '蓝牙连接中' + // }) } }) + // that.czflag = true + // xBlufi.initXBlufi(1); + // xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEventss); + // xBlufi.notifyStartDiscoverBle({ + // 'isStart': true + // }) + // setTimeout(() => { + // xBlufi.notifyStartDiscoverBle({ + // 'isStart': false + // }) + // if (that.devicesList.length > 0) { + // xBlufi.notifyConnectBle({ + // isStart: true, + // deviceId: that.deviceId, + // name: that.name + // }) + // } + // }, 2000) + // setTimeout(()=>{ + // if(that.ver_data == ''){ + // uni.showToast({ + // title: '未连接成功,如多次失败请点击右上角联系客服咨询', + // icon: 'none', + // duration: 5000 + // }) + // that.czflag = false + // that.zhifuflag = false + // setTimeout(()=>{ + // uni.hideLoading() + // },5000) + // }else{ + // uni.showToast({ + // title: '未连接成功,如多次失败请点击右上角联系客服咨询', + // icon: 'none', + // duration: 5000 + // }) + // that.czflag = false + // that.zhifuflag = false + // setTimeout(()=>{ + // uni.hideLoading() + // },5000) + // } + // },10000) + } + }) + + } else { console.log('手机未连接网络') // this.baiflag = false @@ -1323,7 +1497,6 @@ xBlufi.notifyInitBleEsp32({ deviceId: this.deviceId }); - // xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvents); this.deviceIds = options.data.deviceId this.name = this.name } @@ -1369,6 +1542,296 @@ break; } }, + + funListenDeviceMsgEvents: function(options) { + switch (options.type) { + case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED: + if (!options.result) { + uni.showModal({ + title: '很抱歉提醒你!', + content: '小程序与设备异常断开', + showCancel: false, + //是否显示取消按钮 + success: function(res) { + this.ver_data = '' + } + }) + } + break; + case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS: + if (options.result) { + let devicesarr = options.data + console.log(devicesarr,this.mac,'111'); + devicesarr.forEach(device => { + const mac = device.name.substring(4); + if (device.name.slice(5, 17) == this.mac.slice(5, 17)) { + this.deviceId = device.deviceId + this.name = device.name + // console.log(device.name,this.mac,'222'); + this.devicesList.push(device); + let uniqueDevicesList = Array.from(new Set(this.devicesList)); + // 将去重后的数组重新赋值给 this.devicesList + this.devicesList = uniqueDevicesList; + } else { + // uni.showToast({ + // title: '未找到该设备,请确认该设备在附近', + // icon: 'none', + // duration: 3000 + // }) + } + }) + } + break; + case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED: + console.log("连接回调:" + JSON.stringify(options)); + if (options.result) { + // console.log('125451245') + { + xBlufi.notifyInitBleEsp32({ + deviceId: this.deviceId + }); + this.deviceIds = options.data.deviceId + this.name = this.name + } + }else{ + + } + + break; + case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA: + this.ver_data = this.parseCustomData(options.data) + console.log("1收到设备发来的自定义数据结果:", this.ver_data); + setTimeout(()=>{ + this.czflag = false + this.zhifuflag = false + uni.hideLoading() + + if (!this.hasCalledGetczlys) { + this.hasCalledGetczlys = true + let that = this + uni.getNetworkType({ + success(res) { + if (res.networkType !== 'none') { + uni.getConnectedBluetoothDevices({ + success(res) { + that.jzflag = true + that.startLoading() + setTimeout(()=> { + xBlufi.notifySendCustomData({ + customData: 'open' + }) + xBlufi.notifySendCustomData({ + customData: '11open' + }) + setTimeout(() => { + that.zhifuflag = false + uni.reLaunch({ + url:'/page_components/eletj?id=' + that.orderno + }) + },1000) + },1500) + }, + fail(err) { + console.error('获取已连接蓝牙设备信息失败:',err) + } + }) + } else { + console.log('手机未连接网络') + } + } + }) + } + },1000) + break; + case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP: + if (options.result) { + let uniqueDevicesList = Array.from(new Set(this.devicesList)); + let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0, 4) === "CTKG"); + // 将过滤后的数组重新赋值给 this.devicesList + this.devicesList = filteredDevices; + } + break; + case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START: + if (!options.result) { + this.lanyaflag = true + uni.showToast({ + title: '蓝牙未开启', + icon: 'none', + duration: 3000 + }); + return + } else { + this.lanyaflag = false + } + break; + } + }, + + funListenDeviceMsgEventss: function(options) { + switch (options.type) { + case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED: + if (!options.result) { + uni.showModal({ + title: '很抱歉提醒你!', + content: '小程序与设备异常断开', + showCancel: false, + //是否显示取消按钮 + success: function(res) { + this.ver_data = '' + } + }) + } + break; + case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS: + if (options.result) { + let devicesarr = options.data + console.log(devicesarr,this.mac,'111'); + devicesarr.forEach(device => { + const mac = device.name.substring(4); + if (device.name.slice(5, 17) == this.mac.slice(5, 17)) { + this.deviceId = device.deviceId + this.name = device.name + // console.log(device.name,this.mac,'222'); + this.devicesList.push(device); + let uniqueDevicesList = Array.from(new Set(this.devicesList)); + // 将去重后的数组重新赋值给 this.devicesList + this.devicesList = uniqueDevicesList; + } else { + // uni.showToast({ + // title: '未找到该设备,请确认该设备在附近', + // icon: 'none', + // duration: 3000 + // }) + } + }) + } + break; + case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED: + console.log("连接回调:" + JSON.stringify(options)); + if (options.result) { + // console.log('125451245') + { + xBlufi.notifyInitBleEsp32({ + deviceId: this.deviceId + }); + this.deviceIds = options.data.deviceId + this.name = this.name + } + }else{ + + } + + break; + case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA: + this.ver_data = this.parseCustomData(options.data) + console.log("1收到设备发来的自定义数据结果:", this.ver_data); + setTimeout(()=>{ + this.czflag = false + this.zhifuflag = false + uni.hideLoading() + + if (!this.hasCalledGetczlyss) { + this.hasCalledGetczlyss = true + let that = this + that.$u.put(`/app/bill/${that.orderno}/refreshPayResult`).then(res =>{ + // if(res.code == 200 || res.code == 500){ + that.$u.put(`/app/bill/rechargeBillDevice?billNo=${that.orderno}`).then(res=>{ + that.$u.get('/app/bill/recharge/device/fail/list').then(res => { //充值失败调用 + if (res.code == 200) { + console.log('获取订单状态',res); + if(res.data.length > 0 && res.data != null){ + let dingobj = res.data[0].billNo + console.log(dingobj,'订单号'); + uni.getNetworkType({ + success(res) { + if (res.networkType !== 'none') { + uni.getConnectedBluetoothDevices({ + success(res) { + that.jzflag = true + that.startLoading() + setTimeout(()=> { + xBlufi.notifySendCustomData({ + customData: "time@" + that.jine + }) + },1500) + }, + fail(err) { + console.error('获取已连接蓝牙设备信息失败:',err) + } + }) + if(that.ver_data != ''){ + that.$u.get(`/app/bill/recharge/${dingobj}/bluetoothSuccess`).then(res => { + if (res.code == 200) { + that.zhifuflag = false + console.log('蓝牙离线充值成功11') + setTimeout(() => { + if(that.ver_data == ''){ + uni.showToast({ + title: '蓝牙已断开,蓝牙充值失败', + icon: 'none', + duration: 2000 + }) + }else{ + that.zhifuflag = false + uni.reLaunch({ + url:'/page_components/eletj?id=' + that.orderno + }) + } + },1000) + }else{ + uni.showToast({ + title: res.msg, + icon: 'none', + duration: 2000 + }) + } + }) + } + } else { + console.log('手机未连接网络') + // this.baiflag = false + } + } + }) + }else{ + setTimeout(() => { + uni.reLaunch({ + url:'/pages/shouye/index' + }) + },1000) + } + } + }) + }) + // } + }) + } + },1000) + break; + case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP: + if (options.result) { + let uniqueDevicesList = Array.from(new Set(this.devicesList)); + let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0, 4) === "CTKG"); + // 将过滤后的数组重新赋值给 this.devicesList + this.devicesList = filteredDevices; + } + break; + case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START: + if (!options.result) { + this.lanyaflag = true + uni.showToast({ + title: '蓝牙未开启', + icon: 'none', + duration: 3000 + }); + return + } else { + this.lanyaflag = false + } + break; + } + }, + // 从蓝牙拿到数据进行解析 parseCustomData(data) { // 将字符串按照 "@" 分割成数组 diff --git a/page_components/wifilist/index.vue b/page_components/wifilist/index.vue index c711377..0621648 100644 --- a/page_components/wifilist/index.vue +++ b/page_components/wifilist/index.vue @@ -628,28 +628,28 @@ wx.closeBLEConnection({ deviceId: this.objlist.deviceId, }) - uni.showModal({ - title: '温馨提示', - content: `设备初始化失败,请重新连接`, - showCancel: false, - //是否显示取消按钮 - success: function(res) { - let systemInfo = uni.getSystemInfoSync(); - if (systemInfo.platform == 'android') { - // 当前设备是 Android - uni.navigateBack() - } else if (systemInfo.platform == 'ios') { - // 当前设备是 iOS - uni.navigateBack({ - delta:2 - }) - } + // uni.showModal({ + // title: '温馨提示', + // content: `设备初始化失败,请重新连接`, + // showCancel: false, + // //是否显示取消按钮 + // success: function(res) { + // let systemInfo = uni.getSystemInfoSync(); + // if (systemInfo.platform == 'android') { + // // 当前设备是 Android + // uni.navigateBack() + // } else if (systemInfo.platform == 'ios') { + // // 当前设备是 iOS + // uni.navigateBack({ + // delta:2 + // }) + // } - // uni.switchTab({ - // url:'/pages/index/index' - // }) - } - }) + // // uni.switchTab({ + // // url:'/pages/index/index' + // // }) + // } + // }) break; } break;