From 3a672a3795accaa506142a3d2bebe9e76a86f5ee Mon Sep 17 00:00:00 2001
From: "3321822538@qq.com" <3321822538@qq.com>
Date: Fri, 6 Jun 2025 11:33:09 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B5=87=E8=8A=B1=E5=99=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
components/blufi/xBlufi-wx-impl.js | 589 ++++++++++++++---------------
page_user/dingshi.vue | 9 +-
page_user/lanya.vue | 17 +-
page_user/upload.vue | 45 ++-
pages/index/index.vue | 498 ++++++++++++++----------
5 files changed, 601 insertions(+), 557 deletions(-)
diff --git a/components/blufi/xBlufi-wx-impl.js b/components/blufi/xBlufi-wx-impl.js
index c1c4530..c8b0c52 100644
--- a/components/blufi/xBlufi-wx-impl.js
+++ b/components/blufi/xBlufi-wx-impl.js
@@ -118,7 +118,7 @@ function string2buffer(str) {
}
af += s;
var n1 = parseInt('110' + af.substring(0, 5), 2);
- var n2 = parseInt('110' + af.slice(-12), 2);
+ var n2 = parseInt('110' + af.substring(5), 2);
if (n1 > 127) n1 -= 256;
if (n2 > 127) n2 -= 256;
bytes.push(n1);
@@ -417,36 +417,44 @@ function send_ota_data(deviceId, serviceId, characteristicId, data) {
});
});
}
-
+let send_num =0
function send_ota_data_num(deviceId, serviceId, characteristicId, data, num) {
return new Promise(function (resolve, reject) {
- uni.writeBLECharacteristicValue({
- deviceId: deviceId,
- serviceId: serviceId,
- characteristicId: characteristicId,
- value: data,
- // writeType:'writeNoResponse',
- // value: buffer,
- success: function (res) {
- // console.log("送数据成功")
- // let obj = {
- // 'type': mDeviceEvent
- // .XBLUFI_TYPE
- // .TYPE_RECIEVE_MY_DATA,
- // 'result': true,
- // 'data': num
- // };
- // mDeviceEvent
- // .notifyDeviceMsgEvent(
- // obj
- // );
- resolve(res)
- },
- fail: function (res) {
- console.log("送数据失败")
- reject(res)
- }
- });
+ // console.log("送数12据")
+ if(send_num++%5==0)
+ {
+ uni.writeBLECharacteristicValue({
+ deviceId: deviceId,
+ serviceId: serviceId,
+ characteristicId: characteristicId,
+ value: data,
+ writeType:'write',
+ success: function (res) {
+ resolve(res)
+ },
+ fail: function (res) {
+ console.log("送数据失败")
+ reject(FALSE)
+ }
+ });
+ }
+ else
+ {
+ uni.writeBLECharacteristicValue({
+ deviceId: deviceId,
+ serviceId: serviceId,
+ characteristicId: characteristicId,
+ value: data,
+ writeType:'writeNoResponse',
+ success: function (res) {
+ resolve(res)
+ },
+ fail: function (res) {
+ console.log("送数据失败")
+ reject(FALSE)
+ }
+ });
+ }
});
}
@@ -649,6 +657,94 @@ function write_cmd_program(deviceId, serviceId, characteristicId, data) {
// var requestTask =
}
+function write_cmd_program_dd(deviceId, serviceId, characteristicId, data) {
+ var address = 0;
+ var len = 0;
+ var buf = 0;
+ var dv = 0;
+ let result;
+ console.log("更新122")
+ const mtu = 212;
+ uni.setBLEMTU({
+ deviceId: self
+ .data
+ .deviceId,
+ mtu,
+ success: (
+ res
+ ) => {
+ console
+ .log(
+ "setBLEMTU success>>",
+ res
+ )
+ },
+ fail: (
+ res
+ ) => {
+ console
+ .log(
+ "setBLEMTU fail>>",
+ res
+ )
+ },
+ });
+
+ var value1 = util.write_ota_erase(CMD_IAP_ERASE, 4, 0, 0);
+ var typedArray1 = new Uint8Array(value1);
+ console.log("送擦除数据", result)
+ send_ota_data(deviceId, serviceId, characteristicId, typedArray1.buffer);
+ setTimeout(function () {
+ uni.request({
+ url: 'https://www.zenghi.com/gj/三代钉钉.bin', //仅为示例,并非真实接口地址。
+ //url: 'https://www.zenghi.com/gj/BLE钉钉.bin', //仅为示例,并非真实接口地址。
+ // url: 'https://www.zenghi.com/gj/电子秤.bin', //仅为示例,并非真实接口地址。
+ responseType: 'arraybuffer',
+ success: (res) => {
+ dv = new DataView(res.data);
+ var bufferLength = dv.byteLength;
+ var sum = 0;
+ for (var i = 0; i < bufferLength; i++) {
+ sum += dv.getUint8(i)
+ }
+ result = dv
+ console.log(result);
+ console.log("content-length", bufferLength);
+ console.log("sum", sum);
+ len = bufferLength
+ var p_data = 0;
+ var p_ii = 0;
+ while (address <= len) {
+ var offst = 176;
+ if (address + 176 > len) {
+ offst = len - address;
+ }
+ var value = util.write_ota_program(CMD_IAP_PROM, offst, address, result);
+ var typedArray = new Uint8Array(value);
+ send_ota_data_num(deviceId, serviceId, characteristicId, typedArray.buffer, (address /
+ len));
+ address = address + 176;
+
+ }
+
+ // return new Promise
+ var value2 = util.write_ota_sum(CMD_IAP_SUM, bufferLength, sum);
+ var typedArray2 = new Uint8Array(value2);
+ console.log("送结束数据", value2)
+ send_ota_data_num(deviceId, serviceId, characteristicId, typedArray2.buffer, 100);
+ },
+ fail: function (res) {
+ console.log("获取失败");
+ }
+ })
+ }
+
+ , "1000");
+
+ // var requestTask =
+}
+
+
function write_cmd_program_zy(deviceId, serviceId, characteristicId, data) {
var address = 0;
var len = 0;
@@ -824,7 +920,6 @@ function write_cmd_program_yk(deviceId, serviceId, characteristicId, data) {
}
-
function write_cmd_program_fg(web, deviceId, serviceId, characteristicId, data) {
var address = 0;
var len = 0;
@@ -893,7 +988,7 @@ function write_cmd_program_fg(web, deviceId, serviceId, characteristicId, data)
len))
address = address + 176;
- console.log("送数据", qq)
+ // console.log("送数据", qq)
}
// return new Promise
@@ -912,104 +1007,8 @@ function write_cmd_program_fg(web, deviceId, serviceId, characteristicId, data)
// var requestTask =
}
-// 模拟一个异步操作,比如网络请求
-function fetchData() {
- return new Promise((resolve, reject) => {
- setTimeout(() => {
- resolve('Data fetched!');
- }, 20); // 模拟网络延迟 2 秒
- });
-}
-// 模拟一个异步操作,比如网络请求
-function fetchData2() {
- return new Promise((resolve, reject) => {
- setTimeout(() => {
- resolve('Data fetched!');
- }, 2000); // 模拟网络延迟 2 秒
- });
-}
-async function main(res, my_sum, deviceId, serviceId, characteristicId) {
- var address = 0;
- var len = 0;
- var buf = 0;
- var dv = 0;
- let result;
- dv = new DataView(res.data);
- var bufferLength = dv.byteLength;
- var sum = 0;
- for (var i = 0; i < bufferLength; i++) {
- sum += dv.getUint8(i)
- }
- const data1 = await fetchData2();
- result = dv
- console.log(result);
- console.log("content-length", bufferLength);
- console.log("sum", sum);
- len = bufferLength
- if (sum != my_sum && my_sum != 100) {
- console.log("不相等my_sum", my_sum);
- return;
- }
- var p_data = 0;
- var p_ii = 0;
- while (address <= len) {
- var offst = 176;
- if (address + 176 > len) {
- offst = len - address;
- }
- var value = util.write_ota_program(CMD_IAP_PROM, offst, address, result);
- var typedArray = new Uint8Array(value);
- // console.log("12121")
- const data = await fetchData();
- var qq = await send_ota_data_num(deviceId, serviceId, characteristicId, typedArray.buffer, (address /
- len))
- if (qq == false) {
- console.log("返回", sum);
- return
- }
- address = address + 176;
- // //console.log("送数据", qq)
- }
- const data = await fetchData();
- // return new Promise
- var value2 = util.write_ota_sum(CMD_IAP_SUM, bufferLength, sum);
- var typedArray2 = new Uint8Array(value2);
- // console.log("送结束数据", value2)
- send_ota_data_num(deviceId, serviceId, characteristicId, typedArray2.buffer, 100);
-}
-function write_cmd_program_sum(web, sum, deviceId, serviceId, characteristicId, data) {
- var address = 0;
- var len = 0;
- var buf = 0;
- var dv = 0;
- let result;
- console.log("更新122")
- const mtu = 230;
- var value1 = util.write_ota_erase(CMD_IAP_ERASE, 4, 0, 0);
- var typedArray1 = new Uint8Array(value1);
- console.log("翻盖柜", typedArray1)
- console.log("翻盖柜", deviceId)
- console.log("翻盖柜", serviceId)
- console.log("翻盖柜", characteristicId)
- send_ota_data(deviceId, serviceId, characteristicId, typedArray1.buffer);
- // return;
- setTimeout(function () {
- uni.request({
- url: web, //仅为示例,并非真实接口地址。
- //url: 'https://www.zenghi.com/gj/BLE钉钉.bin', //仅为示例,并非真实接口地址。
- // url: 'https://www.zenghi.com/gj/电子秤.bin', //仅为示例,并非真实接口地址。
- responseType: 'arraybuffer',
- success: (res) => {
- main(res, sum, deviceId, serviceId, characteristicId)
- },
- fail: function (res) {
- console.log("获取失败");
- }
- })
- }
- , 3000);
-}
+
function writeCutomsData(deviceId, serviceId, characteristicId, data) {
// var obj = {},
@@ -1037,7 +1036,11 @@ function writeCutomsData(deviceId, serviceId, characteristicId, data) {
console.log("data", data)
// if (data.indexOf("update") != -1 && data.indexOf("all_update") == -1) {
// console.log("送数update据成功")
- // write_cmd_program(deviceId, serviceId, characteristicId, data)
+ // // write_cmd_program(deviceId, serviceId, characteristicId, data)
+ // }
+ // else if (data.indexOf("updddate") != -1 && data.indexOf("all_update") == -1) {
+ // console.log("送数update据成功")
+ // write_cmd_program_dd(deviceId, serviceId, characteristicId, data)
// }
// else if (data.indexOf("upzydsm") != -1 ) {
// console.log("送数upzydsm据成功")
@@ -1047,20 +1050,15 @@ function writeCutomsData(deviceId, serviceId, characteristicId, data) {
// console.log("送数upykdate据成功")
// write_cmd_program_yk(deviceId, serviceId, characteristicId, data)
// }
- // else if (data.indexOf("fgdate") != -1 ) {
- // write_cmd_program_fg('https://fg.zenghi.com/gj/翻盖柜.bin',deviceId, serviceId, characteristicId, data)
- // }
+ // else
+ if (data.sum == 100) {
+ write_cmd_program_fg(data.http,deviceId, serviceId, characteristicId, data)
+ }
// else if (data.indexOf("ble_go7p") != -1 ) {
// console.log("送数update据成功")
// write_cmd_program7p(deviceId, serviceId, characteristicId, data)
// }
- if(data.sum != undefined){
- if(data.http != undefined){
- console.log('升级');
- write_cmd_program_sum(data.http, data.sum, deviceId, serviceId, characteristicId, data)
- }
- }
else {
var buffer = string2buffer(data)
uni.writeBLECharacteristicValue({
@@ -1073,7 +1071,6 @@ function writeCutomsData(deviceId, serviceId, characteristicId, data) {
console.log("送数据成功")
},
fail: function (res) { //console.log(257);
- console.log("送数据成功",res)
}
});
}
@@ -1201,7 +1198,6 @@ function init() {
};
mDeviceEvent.notifyDeviceMsgEvent(obj);
});
- console.log("初始化!!!!!!!!!!!!")
mDeviceEvent.listenStartDiscoverBle(true, function (options) {
if (options.isStart) {
//第一步检查蓝牙适配器是否可用
@@ -1210,147 +1206,123 @@ function init() {
}); //第二步关闭适配器,重新来搜索
uni.closeBluetoothAdapter({
- complete: function (res)
- {
- console.log("这里蓝牙数据")
- wx.openBluetoothAdapter({
+ complete: function (res) {
+ uni.openBluetoothAdapter({
success: function (res) {
uni.getBluetoothAdapterState({
success: function (res) {
- console.log("这里蓝牙数据222")
- {
- let devicesList = [];
- let countsTimes = 0;
- uni.onBluetoothDeviceFound(function (devices) {
- //剔除重复设备,兼容不同设备API的不同返回值
- var isnotexist = true;
-
- // console.log('devices',devices);
- if (devices.deviceId) {
- if (devices.advertisData) {
- devices.advertisData = buf2hex(devices.advertisData);
- } else {
- devices.advertisData = '';
- }
-
- for (var i = 0; i < devicesList.length; i++) {
- if (devices.deviceId === devicesList[i].deviceId) {
+ uni.stopBluetoothDevicesDiscovery({
+ success: function (res) {
+ let devicesList = [];
+ let countsTimes = 0;
+ uni.onBluetoothDeviceFound(function (devices) {
+ //剔除重复设备,兼容不同设备API的不同返回值
+ var isnotexist = true;
+
+ // console.log('devices',devices);
+ if (devices.deviceId) {
+ if (devices.advertisData) {
+ devices.advertisData = buf2hex(devices.advertisData);
+ } else {
+ devices.advertisData = '';
+ }
+
+ for (var i = 0; i < devicesList.length; i++) {
+ if (devices.deviceId === devicesList[i].deviceId) {
+ isnotexist = false;
+ }
+ }
+
+ if (isnotexist) {
+ devicesList.push(devices);
+ }
+ } else if (devices.devices) {
+ // console.log(devices.devices[0])
+ if (devices.devices[0].name != '开发板'
+ && devices.devices[0].name != '无线钉钉'
+ && devices.devices[0].name != '无线工具'
+ // && devices.devices[0].indexOf('TOOL') == -1
+ && devices.devices[0].name.indexOf('WATE') == -1
+ && devices.devices[0].name.indexOf('SMSJ') == -1
+ // && devices.devices[0].name.indexOf('BBLE') == -1
+ // && devices.devices[0].name.indexOf('FXLE') == -1
+ // && devices.devices[0].name.indexOf('CCYK') == -1
+ ) {
+ // console.log("跳过")
isnotexist = false;
}
- }
-
- if (isnotexist) {
- devicesList.push(devices);
- }
- } else if (devices.devices) {
- // console.log(devices.devices[0],'4512544')
- // if (devices.devices[0].name != '开发板'
- // && devices.devices[0].name != 'SMART_R2XS'
- // && devices.devices[0].name != 'SMART_R2XS'
- // )
- if (devices.devices[0].name.indexOf("WATER") != -1 || devices.devices[0].name.indexOf("SMSJ:") != -1){
- // if ( devices.devices[0].name.indexOf("gjkg") != -1 ){
- // console.log("跳过",devices.devices[0].name)
- // isnotexist = false;
- isnotexist = true;
- }
- else
- {
- isnotexist = false;
- }
- // isnotexist = true;
- if (devices.devices[0].advertisData) {
- devices.devices[0].advertisData = buf2hex(devices.devices[0].advertisData);
- } else {
- devices.devices[0].advertisData = '';
- }
-
- for (var i = 0; i < devicesList.length; i++) {
- if (devices.devices[0].deviceId == devicesList[i].deviceId) {
- isnotexist = false;
+ if (devices.devices[0].advertisData) {
+ devices.devices[0].advertisData = buf2hex(devices.devices[0].advertisData);
+ } else {
+ devices.devices[0].advertisData = '';
+ }
+
+ for (var i = 0; i < devicesList.length; i++) {
+ if (devices.devices[0].deviceId == devicesList[i].deviceId) {
+ isnotexist = false;
+ }
+ }
+
+ if (isnotexist) {
+ devicesList.push(devices.devices[0]);
+ }
+ } else if (devices[0]) {
+ if (devices[0].advertisData) {
+ devices[0].advertisData = buf2hex(devices[0].advertisData);
+ } else {
+ devices[0].advertisData = '';
+ }
+
+ for (var i = 0; i < devices_list.length; i++) {
+ if (devices[0].deviceId == devicesList[i].deviceId) {
+ isnotexist = false;
+ }
+ }
+
+ if (isnotexist) {
+ devicesList.push(devices[0]);
}
}
-
- if (isnotexist) {
- devicesList.push(devices.devices[0]);
- console.log("devicesList",devicesList);
- // let obj = {
- // 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS,
- // 'result': true,
- // 'data': devicesList
- // };
- // mDeviceEvent.notifyDeviceMsgEvent(obj);
- }
- } else if (devices[0]) {
- if (devices[0].advertisData) {
- devices[0].advertisData = buf2hex(devices[0].advertisData);
- } else {
- devices[0].advertisData = '';
- }
-
- for (var i = 0; i < devices_list.length; i++) {
- if (devices[0].deviceId == devicesList[i].deviceId) {
- isnotexist = false;
- }
- }
-
- if (isnotexist) {
- devicesList.push(devices[0]);
- console.log("devicesList",devicesList);
- // let obj = {
- // 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS,
- // 'result': true,
- // 'data': devicesList
- // };
- // mDeviceEvent.notifyDeviceMsgEvent(obj);
- }
- }
-
- let obj = {
- 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS,
- 'result': true,
- 'data': devicesList
- };
- mDeviceEvent.notifyDeviceMsgEvent(obj);
- });
-
- uni.startBluetoothDevicesDiscovery({
- allowDuplicatesKey: true,
- success: function (res) {
- console.log(res,'true');
+
let obj = {
- 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
+ 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS,
'result': true,
- 'data': res
- };
- mDeviceEvent.notifyDeviceMsgEvent(obj); //开始扫码,清空列表
-
- devicesList.length = 0;
- },
- fail: function (res) {
- console.log(res,'false');
- let obj = {
- 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
- 'result': false,
- 'data': res
+ 'data': devicesList
};
mDeviceEvent.notifyDeviceMsgEvent(obj);
- }
- });
-
- }
- // uni.stopBluetoothDevicesDiscovery({
- // success: function (res)
- // fail: function (res) {
- // let obj = {
- // 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
- // 'result': false,
- // 'data': res
- // };
- // mDeviceEvent.notifyDeviceMsgEvent(obj);
- // }
- // });
+ });
+ uni.startBluetoothDevicesDiscovery({
+ allowDuplicatesKey: true,
+ success: function (res) {
+ let obj = {
+ 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
+ 'result': true,
+ 'data': res
+ };
+ mDeviceEvent.notifyDeviceMsgEvent(obj); //开始扫码,清空列表
+
+ devicesList.length = 0;
+ },
+ fail: function (res) {
+ let obj = {
+ 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
+ 'result': false,
+ 'data': res
+ };
+ mDeviceEvent.notifyDeviceMsgEvent(obj);
+ }
+ });
+ },
+ fail: function (res) {
+ let obj = {
+ 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
+ 'result': false,
+ 'data': res
+ };
+ mDeviceEvent.notifyDeviceMsgEvent(obj);
+ }
+ });
},
fail: function (res) {
let obj = {
@@ -1396,12 +1368,10 @@ function init() {
}
});
mDeviceEvent.listenConnectBle(true, function (options) {
- console.log("我要连接?", options.isStart,options);
- if (options.isStart){
- uni.createBLEConnection({
- deviceId: options.deviceId,
- success: (res) =>{
- // console.log(res,'100');
+ console.log("我要连接?", options.isStart);
+ if (options.isStart) uni.createBLEConnection({
+ deviceId: options.deviceId,
+ success: function (res) {
self.data.deviceId = options.deviceId;
mDeviceEvent.notifyDeviceMsgEvent({
'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CONNECTED,
@@ -1409,11 +1379,10 @@ function init() {
'data': {
deviceId: options.deviceId,
name: options.name
- },
+ }
});
},
- fail: (res) =>{
- // console.log(res,'1112');
+ fail: function (res) {
self.data.deviceId = null;
mDeviceEvent.notifyDeviceMsgEvent({
'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CONNECTED,
@@ -1422,7 +1391,6 @@ function init() {
});
}
});
- }
else uni.closeBLEConnection({
deviceId: options.deviceId,
success: function (res) {
@@ -1483,20 +1451,46 @@ function init() {
let deviceId = options.deviceId;
self.data.deviceId = options.deviceId;
mac_id = options.deviceId;
-
setTimeout(() => {
- console.log(deviceId,'deviceIddeviceId');
+ var mtu = 212
+ uni.setBLEMTU({
+ deviceId: self
+ .data
+ .deviceId,
+ mtu,
+ success: (
+ res
+ ) => {
+ console
+ .log(
+ "setBLEMTU success>>",
+ res
+ )
+ },
+ fail: (
+ res
+ ) => {
+ console
+ .log(
+ "setBLEMTU fail>>",
+ res
+ )
+ },
+ });
+
uni.getBLEDeviceServices({
// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
deviceId: deviceId,
success: function(res) {
console.log("服务发现456", res)
var services = res.services;
+
if (services.length > 0) {
for (var i = 0; i < services.length; i++) {
if (services[i].uuid === self.data.service_uuid) {
var serviceId = services[i].uuid;
uni.getBLEDeviceCharacteristics({
+
// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
deviceId: deviceId,
serviceId: serviceId,
@@ -1511,14 +1505,7 @@ setTimeout(() => {
if (uuid == self.data.characteristic_write_uuid) {
self.data.serviceId = serviceId;
self.data.uuid = uuid;
- console.log("uuid", uuid)
- let obj = {
- 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT,
- 'result': true,
- 'data': res
- };
- mDeviceEvent.notifyDeviceMsgEvent(obj);
- console.log('服务发现1111111');
+ console.log("uuid", uuid)
uni.notifyBLECharacteristicValueChange({
state: true,
// 启用 notify 功能
@@ -1528,29 +1515,7 @@ setTimeout(() => {
success: function(res) {
console.log("成功", res)
writeCutomsData(self.data.deviceId, self.data.service_uuid, self.data.characteristic_write_uuid, "get_fw");
-
- setTimeout(() => {
const mtu = 212;
- uni.setBLEMTU({
- deviceId: self.data.deviceId,
- mtu,
- success: (
- res
- ) => {
- console
- .log(
- "set1212BLEMTU success>>",
- res
- )
- },
- fail: (
- res
- ) => {
- },
- });
- }, 1000);
-
- console.log("fail getBLEDeviceServices:" + JSON.stringify(res));
uni.onBLECharacteristicValueChange(function(res) {
var my_str = Utf8ArrayToStr(res.value)
if(my_str.indexOf("wifi_ok") != -1)
@@ -1645,7 +1610,7 @@ setTimeout(() => {
}
});
-},700);
+}, 2000);
});
mDeviceEvent.listenSendRouterSsidAndPassword(true, function(options) {
self.data.password = options.password;
diff --git a/page_user/dingshi.vue b/page_user/dingshi.vue
index 68d71fe..edc9ca2 100644
--- a/page_user/dingshi.vue
+++ b/page_user/dingshi.vue
@@ -78,14 +78,14 @@
工作时长:
-
+
秒
间隔时间:
-
+
天
@@ -514,6 +514,7 @@
// 获取时间部分并分割
const timeParts = parts[1].split(",")
// 解析为对象
+ console.log(timeParts,'timePartstimePartstimeParts');
this.csbobj = {
hour: parseInt(timeParts[0]), // 小时
minute: parseInt(timeParts[1]), // 分钟
@@ -521,8 +522,8 @@
day: parseInt(timeParts[3]) // 天数
}
console.log(this.csbobj);
- this.shi = this.csbobj.hour
- this.fen = this.csbobj.minute
+ this.shi = this.csbobj.hour < 10 ? '0' + this.csbobj.hour : this.csbobj.hour
+ this.fen = this.csbobj.minute < 10 ? '0' + this.csbobj.minute : this.csbobj.minute
this.miao = this.csbobj.second
this.tian = this.csbobj.day
}
diff --git a/page_user/lanya.vue b/page_user/lanya.vue
index 2d27cc3..66d823b 100644
--- a/page_user/lanya.vue
+++ b/page_user/lanya.vue
@@ -51,7 +51,7 @@
-
+
重新搜索
@@ -353,7 +353,7 @@
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
if (!options.result) {
uni.showToast({
- title: '蓝牙未开启',
+ title: '蓝牙初始化失败',
icon: 'none',
duration: 3000
})
@@ -373,14 +373,6 @@
},
// 处理搜索按钮点击
handleSearch() {
- if (!this.flag) {
- uni.showToast({
- title: '请等待蓝牙搜索完成后再操作',
- icon: 'none',
- duration: 2000
- })
- return
- }
this.btnss()
},
}
@@ -448,11 +440,6 @@
transform: translateX(-50%);
bottom: 106rpx;
transition: all 0.3s ease;
-
- &.searching {
- background: #E5E5E5;
- color: #666666;
- }
}
.list {
diff --git a/page_user/upload.vue b/page_user/upload.vue
index 537216e..fabcbeb 100644
--- a/page_user/upload.vue
+++ b/page_user/upload.vue
@@ -26,8 +26,8 @@
固件更新
-
- 可更新
+
+ 点击更新
@@ -251,21 +251,14 @@
clearInterval(this.intervalId); // 进度达到 100% 时清除定时器
console.log("加载完成");
}
- }, 30); // 每 30 毫秒更新一次进度
+ }, 1); // 每 1 毫秒更新一次进度
},
// 选择固件版本
gjconfirm(e) {
- // console.log('更新',this.file);
- // var data = {
- // sum: 100,
- // http: this.file
- // }
- // xBlufi.notifySendCustomData({
- // customData: data
- // })
- // this.shengjiflag = true
- // this.startProgress()
if(this.ver != null && this.ver != this.version){
+ xBlufi.notifySendCustomData({
+ customData: '11sleep' + this.xinpin
+ })
if(this.file == '' || this.file == null){
uni.showToast({
title: '暂无新版本',
@@ -276,10 +269,12 @@
console.log('更新');
var data = {
sum: 100,
- http: this.file
- }
+ http:this.file
+ }
+ // https://www.zenghi.com/gj/water_flower.bin
+ console.log(data,'5555555555555555555555555');
xBlufi.notifySendCustomData({
- customData: data
+ customData:data
})
this.shengjiflag = true
this.startProgress()
@@ -323,6 +318,14 @@
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
if (!options.result) {
console.log('duankai');
+ uni.showToast({
+ title: '蓝牙已断开',
+ icon: 'none',
+ duration: 2000
+ })
+ uni.reLaunch({
+ url:'/pages/index/index'
+ })
}
break;
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
@@ -339,7 +342,7 @@
}
break
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
- console.log("选择固件升级收信息:", options.data, options.data.length);
+ // console.log("选择固件升级收信息:", options.data, options.data.length);
if (typeof options.data === 'string') {
if (options.data.indexOf("prom:") !== -1) {
console.log('固件升级中')
@@ -349,10 +352,10 @@
indexOld.indexOf("prom:") + 5,
indexOld.indexOf("@")
)
- this.progress = Number(load_num);
+ this.progress = Number(load_num);
console.log("load_num", load_num);
console.log("升级进度:", this.progress)
- if (this.progress === 6000) {
+ if (this.progress == 6000) {
console.log('固件成功')
this.progress = 100
uni.showToast({
@@ -366,9 +369,9 @@
uni.reLaunch({
url:'/pages/index/index'
})
- },2000)
+ },1000)
}
- if (this.progress === 9000) {
+ if (this.progress == 9000) {
console.log('固件升级失败')
this.progress = 99
uni.showToast({
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 51a6fb6..f051441 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -19,17 +19,6 @@
-
-
@@ -47,9 +36,6 @@
已连接
-
@@ -64,19 +50,9 @@
MAC:{{user.mac == undefined ? '--' : user.mac}}
-
+
+ 可更新
+
@@ -114,10 +90,8 @@
每天
-
-
-
@@ -158,7 +132,7 @@
-
@@ -199,7 +173,7 @@
-
@@ -240,7 +214,7 @@
-
@@ -281,7 +255,7 @@
-
@@ -322,16 +296,40 @@
-
-
- 抽水泵启动时间:{{csbobj.hour == undefined ? '--' : csbobj.hour + '时'}}{{csbobj.minute == undefined ? '' : csbobj.minute + '分'}}
- 抽水泵工作时长/秒:{{csbobj.second == undefined ? '--' : csbobj.second + '秒'}}
- 抽水泵间隔时间/天:{{csbobj.day == undefined ? '--' : csbobj.day + '天'}}
+
+
+
+
+ 启动时间
+
+
+ {{csbobj.hour == undefined ? '--' : csbobj.hour + ':'}}{{csbobj.minute == undefined ? '' : csbobj.minute}}
+
+
+
+
+
+ 工作时长
+
+
+ {{csbobj.second == undefined ? '--' : csbobj.second + '秒'}}
+
+
+
+
+
+ 间隔天数
+
+
+ {{csbobj.day == undefined ? '--' : csbobj.day + '天'}}
+
+
@@ -351,7 +349,6 @@
{{devicetime == '' ? '--' : devicetime.slice(0,5)}}
-
@@ -390,10 +387,8 @@
{{ sdminutes ? sdminutes + ':' : '' }}{{ sdseconds ? sdseconds : '' }}
- 手动浇水
-
+ 手动浇水
+
@@ -414,8 +409,10 @@
+
+ 保存定时设置
+
-
@@ -541,7 +538,13 @@
disconnectTimer: null,
devicetime:'',
imgpic:'',
- xinp:''
+ xinp:'',
+ version:'',
+
+ searchStartTime: 0, // 记录开始搜索的时间戳
+ searchTimeout: 10000, // 10秒超时(单位:毫秒)
+ searchTimer: null, // 搜索定时器
+ isSearching: false // 是否正在搜索中
}
},
// 分享到好友(会话)
@@ -581,6 +584,9 @@
xBlufi.notifyStartDiscoverBle({
'isStart': true
})
+ // setTimeout(()=>{
+ // that.btnlj()
+ // },1500)
},
onShow() {
// 请求个人信息
@@ -602,6 +608,34 @@
this.clearDisconnectTimer()
},
methods: {
+ // 点击保存设置
+ btnbc(){
+ this.handleUserAction()
+ if(this.vardataflag != 3){
+ uni.showToast({
+ title: '设备未连接',
+ icon: 'none',
+ duration:2000
+ })
+ }else{
+ uni.showToast({
+ title: '保存成功',
+ icon: 'success',
+ duration:2000
+ })
+ xBlufi.notifySendCustomData({
+ customData: '11sleep' + this.xinp
+ })
+ }
+ },
+ getbanbens(){
+ this.$u.get(`/app/model/${this.user.modelId}`).then(res => {
+ if (res.code == 200) {
+ this.version = res.data.version.slice(1)
+ console.log(this.version,'this.versionthis.versionthis.version');
+ }
+ })
+ },
// 点击进行设备录入
btnluru(){
this.datalist = ''
@@ -670,6 +704,7 @@
this.deviceId = res.data[0].mac.match(/.{2}/g).reverse().join(':')
this.user = res.data[0]
this.shebid = res.data[0].deviceId
+ this.getbanbens()
let that = this
}else{
this.bjflag = true
@@ -702,6 +737,11 @@
that.findDevice()
}
}
+ setTimeout(()=>{
+ if(this.vardataflag != 3){
+ this.vardataflag = 1
+ }
+ },15000)
}
},
// ios递归函数匹配
@@ -746,13 +786,11 @@
uni.showLoading({
title: '开启中...'
})
- // setTimeout(() => {
- this.yschecked = false
- xBlufi.notifySendCustomData({
- customData: '11yudi'
- })
- uni.hideLoading()
- // }, 1500)
+ this.yschecked = false
+ xBlufi.notifySendCustomData({
+ customData: '11yudi'
+ })
+ uni.hideLoading()
}
},
// 点击同步时间
@@ -767,7 +805,7 @@
}else{
this.devicetime = this.getCurrentTime();
console.log(this.devicetime);
- if(this.pre == 'WATER'){ //单阀
+ // if(this.pre == 'WATER'){ //单阀
uni.showLoading({
title: '设置中...'
})
@@ -775,15 +813,20 @@
customData: '11date' + this.devicetime + ';'
})
uni.hideLoading()
- }else{ //抽水泵
- uni.showLoading({
- title: '设置中...'
+ uni.showToast({
+ title: '同步成功',
+ icon: 'success',
+ duration:2000
})
- xBlufi.notifySendCustomData({
- customData: '11hour' + this.devicetime + '@',
- })
- uni.hideLoading()
- }
+ // }else{ //抽水泵
+ // uni.showLoading({
+ // title: '设置中...'
+ // })
+ // xBlufi.notifySendCustomData({
+ // customData: '11hour' + this.devicetime + '@',
+ // })
+ // uni.hideLoading()
+ // }
}
},
// 点击显示设置时间
@@ -809,30 +852,26 @@
},
// 点击设置当前时间
confirmtime(e){
- if(this.pre == 'WATER'){ //单阀
+ // if(this.pre == 'WATER'){ //单阀
uni.showLoading({
title: '设置中...'
})
console.log(e.hour,e.minute);
- // setTimeout(() => {
- this.devicetime = e.hour + ':' + e.minute
- xBlufi.notifySendCustomData({
- customData: '11date' + e.hour + ':' + e.minute + ';'
- })
- uni.hideLoading()
- // }, 1500)
- }else{ //抽水泵
- uni.showLoading({
- title: '设置中...'
+ this.devicetime = e.hour + ':' + e.minute
+ xBlufi.notifySendCustomData({
+ customData: '11date' + e.hour + ':' + e.minute + ':' + '00' + ';'
})
- console.log(e.hour,e.minute);
- // setTimeout(() => {
- xBlufi.notifySendCustomData({
- customData: '11hour' + e.hour + '@' + e.minute + '@',
- })
- uni.hideLoading()
- // }, 1500)
- }
+ uni.hideLoading()
+ // }else{ //抽水泵
+ // uni.showLoading({
+ // title: '设置中...'
+ // })
+ // console.log(e.hour,e.minute);
+ // xBlufi.notifySendCustomData({
+ // customData: '11hour' + e.hour + '@' + e.minute + '@',
+ // })
+ // uni.hideLoading()
+ // }
},
// 雨水感应关闭
btnyushuis() {
@@ -849,13 +888,11 @@
uni.showLoading({
title: '关闭中...'
})
- // setTimeout(() => {
- this.yschecked = true
- xBlufi.notifySendCustomData({
- customData: '11unyudi'
- })
- uni.hideLoading()
- // }, 1500)
+ this.yschecked = true
+ xBlufi.notifySendCustomData({
+ customData: '11unyudi'
+ })
+ uni.hideLoading()
}
},
// 点击儿童锁开启
@@ -873,13 +910,11 @@
uni.showLoading({
title: '开启中...'
})
- // setTimeout(() => {
- this.etchecked = false
- xBlufi.notifySendCustomData({
- customData: '11lock'
- })
- uni.hideLoading()
- // }, 1500)
+ this.etchecked = false
+ xBlufi.notifySendCustomData({
+ customData: '11lock'
+ })
+ uni.hideLoading()
}
},
// 点击儿童锁关闭
@@ -897,24 +932,27 @@
uni.showLoading({
title: '关闭中...'
})
- // setTimeout(() => {
- this.etchecked = true
- xBlufi.notifySendCustomData({
- customData: '11unlock'
- })
- uni.hideLoading()
- // }, 1500)
+ this.etchecked = true
+ xBlufi.notifySendCustomData({
+ customData: '11unlock'
+ })
+ uni.hideLoading()
}
},
// 点击添加设备
btnaddsb() {
- //跳转后清空数据 重新进行连接
- this.vardataflag = 1
- this.ver_data = {}
- this.datalist = ''
- uni.navigateTo({
- url: '/page_user/lanya'
+ this.$u.get(`/appVerify/profile`).then((res) => {
+ if (res.code == 200) {
+ this.vardataflag = 1
+ this.ver_data = {}
+ this.datalist = ''
+ uni.navigateTo({
+ url: '/page_user/lanya'
+ })
+ }else if(res.code == 401){
+ this.jmlogin()
+ }
})
},
@@ -942,7 +980,6 @@
}
},
-
// 点击取消手动浇水
btnqx() {
this.handleUserAction()
@@ -966,14 +1003,12 @@
uni.showLoading({
title: '开启中...'
})
- // setTimeout(() => {
- xBlufi.notifySendCustomData({
- customData: "11time@" + this.jstime + '@'
- })
- uni.hideLoading()
- this.startTimer(this.jstime)
- this.sdjsflag = false
- // }, 1500)
+ xBlufi.notifySendCustomData({
+ customData: "11time@" + this.jstime + '@'
+ })
+ uni.hideLoading()
+ this.startTimer(this.jstime)
+ this.sdjsflag = false
}
},
@@ -1015,18 +1050,16 @@
uni.showLoading({
title: '关闭中...'
})
- // setTimeout(() => {
- xBlufi.notifySendCustomData({
- customData: "11close"
- })
- clearInterval(this.timer)
- this.sdminutes = ''
- this.sdseconds = ''
- this.kgflag = true
- this.jsked = true
- this.jskeds = false
- uni.hideLoading()
- // }, 1500)
+ xBlufi.notifySendCustomData({
+ customData: "11close"
+ })
+ clearInterval(this.timer)
+ this.sdminutes = ''
+ this.sdseconds = ''
+ this.kgflag = true
+ this.jsked = true
+ this.jskeds = false
+ uni.hideLoading()
}
},
// 开启手动浇水
@@ -1050,6 +1083,9 @@
// 跳转到设置
btnsz() {
xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent)
+ if(this.csbobj.day){
+ this.xctime = '111'
+ }
uni.navigateTo({
url: '/page_user/upload?deviceid=' + this.shebid + '&ver=' + this.ver + '&xctime=' + this.xctime + '&xipin=' + this.xinp + '&img=' + this.imgpic
})
@@ -1107,6 +1143,8 @@
this.imgpic = res.data.modelPicture
this.deviceId = res.data.mac.match(/.{2}/g).reverse().join(':')
this.user = res.data
+ this.getbanbens()
+ // this.btnlj()
}
})
},
@@ -1149,39 +1187,54 @@
xBlufi.notifyInitBleEsp32({
deviceId: this.deviceId
})
- break
- case xBlufi.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT:
if (options.result == true){
console.log('服务发现成功:', options);
this.datalist = '1'
- this.vardataflag = 3
- this.initDisconnectTimer()
- // 连接成功后立即发送一次获取数据命令
- console.log("连接成功后发送获取数据命令")
- xBlufi.notifySendCustomData({
- customData: "11get"
- })
+ setTimeout(()=>{
+ this.vardataflag = 3
+ this.initDisconnectTimer()
+ xBlufi.notifySendCustomData({
+ customData: "11get"
+ })
+ },3000)
}else{
console.log('服务发现失败:', options.data);
this.vardataflag = 1
- this.clearDisconnectTimer()
+ this.clearDisconnectTimer()
}
break
+ case xBlufi.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT:
+ // if (options.result == true){
+ // console.log('服务发现成功:', options);
+ // this.datalist = '1'
+ // this.vardataflag = 3
+ // this.initDisconnectTimer()
+ // // 连接成功后立即发送一次获取数据命令
+ // console.log("连接成功后发送获取数据命令")
+ // xBlufi.notifySendCustomData({
+ // customData: "11get"
+ // })
+ // }else{
+ // console.log('服务发现失败:', options.data);
+ // this.vardataflag = 1
+ // this.clearDisconnectTimer()
+ // }
+ break
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
console.log("收到设备数据:", options.data)
if (options.data.indexOf("prom:") !== -1) {
- console.log('固件升级中')
+ // console.log('固件升级中')
var indexOld = options.data.substring(options.data.indexOf('prom:'))
- console.log("indexOld", indexOld);
+ // console.log("indexOld", indexOld);
var load_num = indexOld.substring(
indexOld.indexOf("prom:") + 5,
indexOld.indexOf("@")
)
this.progress = Number(load_num);
- console.log("load_num", load_num);
+ // console.log("load_num", load_num);
console.log("升级进度:", this.progress)
if (this.progress === 6000) {
- console.log('固件成功')
+ // console.log('固件成功')
this.progress = 100
uni.showToast({
title: '固件升级成功',
@@ -1196,7 +1249,7 @@
},2000)
}
if (this.progress === 9000) {
- console.log('固件升级失败')
+ // console.log('固件升级失败')
this.progress = 99
uni.showToast({
title: '固件升级失败',
@@ -1222,7 +1275,8 @@
break
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
if (!options.result) {
- console.log('蓝牙未开启')
+ this.vardataflag = 1
+ console.log('蓝牙初始化失败')
return
}
break
@@ -1233,7 +1287,7 @@
const that = this
that.intervalId = setInterval(() => {
if (that.vardataflag == 3) {
- console.log("发送获取数据命令")
+ // console.log("发送获取数据命令")
xBlufi.notifySendCustomData({
customData: "11get"
})
@@ -1251,35 +1305,51 @@
// 处理抽水泵接收数据
getcsbshuju(){
const input = this.datalist
- // 去除末尾的分号并分割字符串
+ const inputString = this.datalist;
+ const hasAtSymbol = inputString.includes('@');
+ let processedString;
+ let currentDay = 0;
+ if (hasAtSymbol) {
+ const [ver, restOfString] = inputString.split('@');
+ this.ver = ver || '';
+ processedString = restOfString || '';
+ // 解析当前天数
+ const showMatch = processedString.match(/show:([^;]+)/);
+ if (showMatch) {
+ const showValues = showMatch[1].split(',');
+ currentDay = parseInt(showValues[showValues.length - 1]) || 0;
+ }
+ } else {
+ processedString = inputString;
+ this.ver = '';
+ }
+ const version = this.ver;
const parts = input.replace(";", "").split(":")
// 获取时间部分并分割
const timeParts = parts[1].split(",")
// 解析为对象
this.csbobj = {
- hour: parseInt(timeParts[0]), // 小时
- minute: parseInt(timeParts[1]), // 分钟
+ hour: parseInt(timeParts[0]) < 10 ? '0' + parseInt(timeParts[0]) : parseInt(timeParts[0]), // 小时
+ minute: parseInt(timeParts[1]) < 10 ? '0' + parseInt(timeParts[1]) : parseInt(timeParts[1]), // 分钟
second: parseInt(timeParts[2]), // 秒
day: parseInt(timeParts[3]) // 天数
}
+ this.devicetime = parseInt(timeParts[4]) + ':' + parseInt(timeParts[5])
this.ver_data = this.csbobj
- console.log(this.csbobj);
+ // console.log(this.csbobj);
},
// 处理从设备接收数据
getchuli() {
const inputString = this.datalist;
- console.log('接收到的数据:', inputString);
-
+ // console.log('接收到的数据:', inputString);
// 检查是否有 @ 分隔符
const hasAtSymbol = inputString.includes('@');
let processedString;
let currentDay = 0;
-
if (hasAtSymbol) {
const [ver, restOfString] = inputString.split('@');
this.ver = ver || '';
processedString = restOfString || '';
-
// 解析当前天数
const showMatch = processedString.match(/show:([^;]+)/);
if (showMatch) {
@@ -1290,47 +1360,41 @@
processedString = inputString;
this.ver = '';
}
-
- console.log('处理后的字符串:', processedString);
- console.log(this.ver,'this.verthis.verthis.verthis.ver')
-
+ // console.log('处理后的字符串:', processedString);
+ // console.log(this.ver,'this.verthis.verthis.ver');
const version = this.ver;
// 使用正则表达式提取数字部分
const versionNumber = version.match(/\d+/); // 匹配连续的数字
- if (versionNumber) {
- const num = parseInt(versionNumber[0], 10); // 转换为整数
- if (num < 9 && !this.hasShownVersionAlert) {
- this.hasShownVersionAlert = true; // 设置标记为已显示
- uni.showModal({
- title: "提示",
- content: `您当前设备版本过低,可能无法正常使用,请点击右上角设置前去升级`,
- showCancel: false, // 不显示取消按钮
- confirmText: "确定", // 按钮文字
- success: (res) => {
- if (res.confirm) {
- console.log("用户点击了确定");
- this.hasShownVersionAlert = false; // 重置标记,允许下次判断
- }
- }
- })
- } else {
- console.log(`版本号 ${num} 不小于 9`);
- }
- } else {
- console.log("没有找到版本号数字");
- }
-
+ // if (versionNumber) {
+ // const num = parseInt(versionNumber[0], 10); // 转换为整数
+ // if (num < 9 && !this.hasShownVersionAlert) {
+ // this.hasShownVersionAlert = true; // 设置标记为已显示
+ // uni.showModal({
+ // title: "提示",
+ // content: `您当前设备版本过低,可能无法正常使用,请点击右上角设置前去升级`,
+ // showCancel: false, // 不显示取消按钮
+ // confirmText: "确定", // 按钮文字
+ // success: (res) => {
+ // if (res.confirm) {
+ // console.log("用户点击了确定");
+ // this.hasShownVersionAlert = false; // 重置标记,允许下次判断
+ // }
+ // }
+ // })
+ // } else {
+ // console.log(`版本号 ${num} 不小于 9`);
+ // }
+ // } else {
+ // console.log("没有找到版本号数字");
+ // }
const pairs = processedString.split(';').filter(Boolean);
- console.log('分割后的数据对:', pairs);
-
+ // console.log('分割后的数据对:', pairs);
const showObject = {};
const pSetObjects = {};
-
// 初始化所有p_set为默认值
for (let i = 1; i <= 6; i++) {
pSetObjects[`p_set${i}`] = [0, 0, 0, 0, 0];
}
-
// 解析字符串
pairs.forEach(pair => {
const [key, value] = pair.split(':');
@@ -1348,7 +1412,6 @@
this.ver_data = pSetObjects;
this.jstimeobj = pSetObjects;
this.showobj = showObject;
-
// 设置开关状态
this.yschecked = this.showobj.showArray[1] !== 1;
this.etchecked = this.showobj.showArray[0] !== 1;
@@ -1360,13 +1423,11 @@
const remainingMinutes = diffMinutes % 60;
return { hours: diffHours, minutes: remainingMinutes };
};
-
const formatTime = (seconds) => {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
return `${minutes}分${remainingSeconds}秒`;
};
-
const getTimeFromArray = (timeArray) => {
if (!timeArray || timeArray.length < 2) return null;
const [hour, minute] = timeArray;
@@ -1374,24 +1435,19 @@
date.setHours(hour, minute, 0, 0);
return date;
};
-
let nextTime = null;
let nextTimeDiff = null;
let nextWaterDuration = null;
let prevTime = null;
-
for (const key in this.ver_data) {
if (this.ver_data.hasOwnProperty(key) && this.ver_data[key][3] === 1) {
const timeArray = this.ver_data[key];
const timeDate = getTimeFromArray(timeArray);
if (!timeDate) continue;
-
const diff = calculateTimeDifference(timeDate, new Date());
const interval = timeArray[4] || 0;
-
// 检查是否应该在这一天浇水
const shouldWaterToday = interval === 0 || (currentDay % interval === 0);
-
if (timeDate > new Date() && shouldWaterToday) {
if (!nextTime || (diff.hours * 60 + diff.minutes < (nextTimeDiff?.hours || 0) * 60 + (nextTimeDiff?.minutes || 0))) {
nextTimeDiff = diff;
@@ -1403,13 +1459,11 @@
}
}
}
-
// 输出结果
this.xctime = nextTime ? `${nextTimeDiff.hours}时${nextTimeDiff.minutes}分` : '无距离下次浇水时间';
this.xctimesc = nextWaterDuration || '未知';
this.sctimejs = prevTime ? prevTime.toTimeString().slice(0, 5) : '无上次浇水时间';
this.xctimesj = nextTime ? nextTime.toTimeString().slice(0, 5) : '无下次浇水时间';
-
console.log('解析后的数据:', {
ver_data: this.ver_data,
showobj: this.showobj,
@@ -1418,16 +1472,19 @@
prevTime: this.sctimejs
});
this.xinp = this.showobj.showArray[this.showobj.showArray.length - 1]
- console.log(this.showobj.showArray,this.showobj.showArray[6],this.showobj.showArray[this.showobj.showArray.length - 1],'02020202020');
- if(this.showobj.showArray[6] && this.showobj.showArray[7]){
+ // if(this.showobj.showArray[6] != '' && this.showobj.showArray[7] != ''){
+ // console.log('111111111111111111111111111111111111111111111111111111111111111');
// 显式转为字符串
const yiStr = String(this.showobj.showArray[6])
const erStr = String(this.showobj.showArray[7])
+ // console.log('22222222222222222222222222222222222222222222222222222',yiStr,erStr);
// 判断字符串长度是否为1(而不是<10)
let yi = yiStr.length === 1 ? '0' + yiStr : yiStr
let er = erStr.length === 1 ? '0' + erStr : erStr
+ // console.log('33333333333333333333333333333333333333333333333333',yi,er);
this.devicetime = yi + ':' + er
- }
+ // console.log(this.devicetime,'this.devicetimethis.devicetimethis.devicetimethis.devicetimethis.devicetimethis.devicetimethis.devicetimethis.devicetime');
+ // }
},
// 初始化断开蓝牙定时器
initDisconnectTimer() {
@@ -1438,12 +1495,10 @@
}
}, 600000)
},
-
// 重置断开蓝牙定时器
resetDisconnectTimer() {
this.initDisconnectTimer()
},
-
// 清除断开蓝牙定时器
clearDisconnectTimer() {
if(this.disconnectTimer) {
@@ -1451,7 +1506,6 @@
this.disconnectTimer = null
}
},
-
// 断开蓝牙连接
disconnectBluetooth() {
if(this.deviceId) {
@@ -1475,14 +1529,12 @@
})
}
},
-
// 监听用户操作的方法
handleUserAction() {
if(this.vardataflag === 3) {
this.resetDisconnectTimer()
}
},
-
// 获取时间显示
getTimeDisplay(setKey) {
const set = this.ver_data[setKey];
@@ -1491,12 +1543,48 @@
}
return '--:--';
},
-
// 判断是否是当前时间
isCurrentTime(setKey) {
const set = this.ver_data[setKey];
return set && set[0] == this.xctimesj.slice(0,2) && set[1] == this.xctimesj.slice(-2);
- }
+ },
+ // 计算时间差值(分钟)
+ getTimeDifference(hour, minute) {
+ if (!this.devicetime) return Infinity;
+ const [currentHour, currentMinute] = this.devicetime.split(':').map(Number);
+ const currentTotalMinutes = currentHour * 60 + currentMinute;
+ const targetTotalMinutes = hour * 60 + minute;
+
+ // 计算时间差
+ let diff = targetTotalMinutes - currentTotalMinutes;
+ // 如果时间已过,加上24小时
+ if (diff <= 0) {
+ diff += 1440;
+ }
+ return diff;
+ },
+
+ // 判断是否显示图标
+ shouldShowIcon(pSetIndex) {
+ const pSet = this.ver_data[`p_set${pSetIndex}`];
+ // 如果定时未开启,不显示图标
+ if (!pSet || pSet[3] !== 1) return false;
+
+ const currentDiff = this.getTimeDifference(pSet[0], pSet[1]);
+
+ // 检查是否是第一个最小时间差的定时设置
+ for (let i = 1; i <= 6; i++) {
+ const checkSet = this.ver_data[`p_set${i}`];
+ if (checkSet && checkSet[3] === 1) {
+ const checkDiff = this.getTimeDifference(checkSet[0], checkSet[1]);
+ // 如果找到更小的时间差,或者相同时间差但索引更小,则不显示
+ if (checkDiff < currentDiff || (checkDiff === currentDiff && i < pSetIndex)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ },
}
}