diff --git a/page_user/dingshi.vue b/page_user/dingshi.vue index 816b7be..bc5249c 100644 --- a/page_user/dingshi.vue +++ b/page_user/dingshi.vue @@ -13,6 +13,7 @@ {{ formattedTime(values[0], values[1]) }} P{{ index + 1 }} {{ formatTime(values[2]) }} + {{ formatInterval(values[4]) }} 设置浇水 - + 请设置浇水时间 - + {{hour}}时 {{minutekq}}分 浇水时长 - + {{minute}}分 {{second}}秒 + + 每几天浇一次 + + - + {{jgtian || 1}} + + + + 取消 @@ -134,14 +143,9 @@ maxRetries: 3, // 最大重试次数 lastOperation: null, // 最后一次操作 // 添加默认时间设置 - defaultTime: { - hour: '00', - minute: '00' - }, - defaultTimeLength: { - minute: '00', - second: '00' - }, + defaultTime:'', + defaultTimeLength: '', + jgtian: '' } }, // 分享到好友(会话) @@ -165,24 +169,21 @@ customData: "11get" }) if (option.list.length > 0) { //判断有无数据 有数据直接拿 无数据则发送命令获取数据 - this.pre = option.pre + this.pre = option.pre if (option.pre == 'WATER') { this.list = JSON.parse(option.list) for (let key in this.list) { if (this.list.hasOwnProperty(key)) { // 获取当前数组 let arr = this.list[key]; - // 判断数组的最后一个元素,并进行替换 - if (arr[arr.length - 1] === 0) { - arr[arr.length - 1] = false; - } else if (arr[arr.length - 1] === 1) { - arr[arr.length - 1] = true; - } + // 只转换开关状态(values[3])为布尔值 + arr[3] = arr[3] === 1; } } - console.log(this.list) + console.log(this.list,'listlistlist') } else { this.csbobj = JSON.parse(option.list) + console.log(this.csbobj,'chobjchobj'); this.shi = this.csbobj.hour this.fen = this.csbobj.minute this.miao = this.csbobj.second @@ -198,11 +199,28 @@ }, methods: { + // 点击选择浇水时间 + btnshowone(){ + this.defaultTime = (this.hour.length < 10 ? '0' + this.hour : this.hour) + ':' + (this.minutekq.length < 10 ? '0' + this.minutekq : this.minutekq) + this.show = true + }, + // 点击选择浇水时长 + btnshowtwo(){ + console.log(this.defaultTimeLength,this.minute,this.second,'111'); + this.defaultTimeLength = '00' + ':' + this.minute + ':' + this.second + console.log(this.defaultTimeLength,this.minute,this.second,'222'); + this.shows = true + }, // 显示加载 showLoading() { this.isLoading = true; }, + // 格式化间隔天数显示 + formatInterval(days) { + return days <= 1 ? '每天浇一次' : '每' + days + '天浇一次'; + }, + // 隐藏加载 hideLoading() { this.isLoading = false; @@ -253,16 +271,15 @@ array[lastIndex] = !lastElement; this.deviceflag = lastElement ? 0 : 1; } - - let cucun = '11num' + this.deviceindex + '@' + this.devicehour + '@' + this.deviceminute + '@' + this.devicemiao + '@' + this.deviceflag + '@'; + let flag = values[3] == 0 ? 1 : 0 + let cucun = '11p_set' + (Number(this.deviceindex) + 1)+ ':' + this.devicehour + ',' + this.deviceminute + ',' + this.devicemiao + ',' + flag + ',' + this.jgtian + ';' this.lastOperation = () => { xBlufi.notifySendCustomData({ customData: cucun - }); - }; - this.lastOperation(); - - await this.delay(1000); + }) + } + this.lastOperation() + await this.delay(1000) xBlufi.notifySendCustomData({ customData: "11get" }); @@ -279,7 +296,9 @@ // 点击设置定时时间 btnitem(key, index, values) { - this.deviceindex = index + // 从 key 中提取索引号,例如从 'p_set1' 提取 '1' + const indexMatch = key.match(/p_set(\d+)/); + this.deviceindex = indexMatch ? indexMatch[1] : index; this.timeflag = true this.hour = values[0] this.minutekq = values[1] @@ -290,14 +309,16 @@ const formattedSeconds = seconds < 10 ? '0' + seconds : seconds.toString() this.minute = formattedMinutes this.second = formattedSeconds + // 添加间隔天数的处理,确保为数字 + this.jgtian = parseInt(values[4]) || 0 + // 设置设备相关值 + this.devicehour = values[0] + this.deviceminute = values[1] + this.devicemiao = values[2] if (this.list.hasOwnProperty(key)) { const array = this.list[key] - const lastElement = array[array.length - 1] - if (lastElement) { - this.deviceflag = 1 - } else { - this.deviceflag = 0 - } + // 只转换开关状态为布尔值 + this.deviceflag = array[3] ? 1 : 0 } }, @@ -326,14 +347,17 @@ // 确定选择设置定时时间 async btnqd() { try { - this.showLoading(); - this.timeflag = false; - this.hour = '--'; - this.minutekq = '--'; - this.minute = '--'; - this.second = '--'; + this.showLoading() + this.timeflag = false + this.hour = '--' + this.minutekq = '--' + this.minute = '--' + this.second = '--' - let cucun = '11num' + this.deviceindex + '@' + this.devicehour + '@' + this.deviceminute + '@' + this.devicemiao + '@' + this.deviceflag + '@'; + // 确保间隔天数为数字 + const intervalDays = parseInt(this.jgtian) || 0; + + let cucun = '11p_set' + this.deviceindex + ':' + this.devicehour + ',' + this.deviceminute + ',' + this.devicemiao + ',' + 1 + ',' + intervalDays + ';' this.lastOperation = () => { xBlufi.notifySendCustomData({ customData: cucun @@ -375,7 +399,7 @@ this.showLoading(); this.timeflag = false; - let cucun = '11num0' + '@' + this.shi + '@' + this.fen + '@' + this.miao + '@' + this.tian + '@'; + let cucun = '11p_set0' + ',' + this.shi + ',' + this.fen + ',' + this.miao + ',' + this.tian + ',' + this.jgtian; this.lastOperation = () => { xBlufi.notifySendCustomData({ customData: cucun @@ -414,8 +438,8 @@ this.minute = e.minute || '00' this.second = e.second || '00' this.devicemiao = (Number(this.minute) * 60 + Number(this.second)) || 0 - console.log(this.devicemiao) - }, + console.log(this.devicemiao) + }, funListenDeviceMsgEvent: function(options) { switch (options.type) { @@ -445,6 +469,8 @@ const parsed = parseInt(num); return isNaN(parsed) ? 0 : parsed; }); + // 只转换开关状态为布尔值 + numbers[3] = numbers[3] === 1; pSetObjects[key] = numbers; } catch (e) { console.error('数据解析错误:', e); @@ -454,13 +480,6 @@ if (Object.keys(pSetObjects).length > 0) { this.list = pSetObjects; - - for (let key in this.list) { - if (this.list.hasOwnProperty(key)) { - let arr = this.list[key]; - arr[arr.length - 1] = arr[arr.length - 1] === 1; - } - } } } else { const input = options.data.slice(0, -1) + ";" @@ -490,6 +509,12 @@ break } }, + // 改变天数 + changeDays(change) { + let newValue = (parseInt(this.jgtian) || 1) + change; + // 确保天数不小于1 + this.jgtian = Math.max(1, newValue); + }, } } @@ -535,7 +560,9 @@ left: 50%; transform: translateX(-50%); width: 678rpx; - height: 800rpx; + max-height: 1200rpx; + padding-bottom: 30rpx; + box-sizing: border-box; background: #FFFFFF; border-radius: 24rpx 24rpx 24rpx 24rpx; z-index: 99; @@ -586,6 +613,49 @@ margin-left: 96rpx; } + .jiange { + width: 512rpx; + margin: 30rpx auto 0; + display: flex; + align-items: center; + justify-content: space-between; + + text { + font-size: 32rpx; + color: #808080; + font-weight: 600; + } + + .number-input { + display: flex; + align-items: center; + background: #F0F0F0; + border-radius: 16rpx; + padding: 0 20rpx; + height: 80rpx; + + .btn-minus, .btn-plus { + width: 60rpx; + height: 60rpx; + line-height: 60rpx; + text-align: center; + font-size: 40rpx; + color: #48893B; + font-weight: bold; + background: #fff; + border-radius: 8rpx; + } + + .days { + margin: 0 30rpx; + min-width: 60rpx; + text-align: center; + font-size: 32rpx; + color: #3D3D3D; + } + } + } + .anniu { display: flex; justify-content: space-between; @@ -633,7 +703,7 @@ .list { .list_val { width: 678rpx; - height: 208rpx; + height: 248rpx; background: #FFFFFF; box-shadow: 0rpx 10rpx 64rpx 0rpx rgba(0, 0, 0, 0.08); border-radius: 20rpx; diff --git a/page_user/upload.vue b/page_user/upload.vue index 930996a..b5c8c8c 100644 --- a/page_user/upload.vue +++ b/page_user/upload.vue @@ -197,6 +197,7 @@ if (res.code == 200) { this.user = res.data this.getbanbens() + // this.file = 'https://wc.chuangtewl.com/download/water_flower(4).bin' } }) }, @@ -232,6 +233,16 @@ }, // 选择固件版本 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){ if(this.file == '' || this.file == null){ uni.showToast({ diff --git a/pages/index/index.vue b/pages/index/index.vue index aa399f9..7b38107 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -79,7 +79,7 @@ - + OFF @@ -88,17 +88,23 @@ P1 - - {{ver_data.p_set0[0] == undefined ? '' : ver_data.p_set0[0] + ':'}}{{ver_data.p_set0[1] == undefined ? '' : ver_data.p_set0[1]}} + + {{ver_data.p_set1 && ver_data.p_set1[0] !== undefined ? ver_data.p_set1[0].toString().padStart(2, '0') + ':' + ver_data.p_set1[1].toString().padStart(2, '0') : '--:--'}} + + + 每{{ver_data.p_set1[4]}}天 + + + 每天 - - + OFF @@ -107,27 +113,14 @@ P2 - - {{ver_data.p_set1[0] == undefined ? '' : ver_data.p_set1[0] + ':'}}{{ver_data.p_set1[1] == undefined ? '' : ver_data.p_set1[1]}} + + {{ver_data.p_set2 && ver_data.p_set2[0] !== undefined ? ver_data.p_set2[0].toString().padStart(2, '0') + ':' + ver_data.p_set2[1].toString().padStart(2, '0') : '--:--'}} - - - + + 每{{ver_data.p_set2[4]}}天 - - - - OFF - - - ON - - - P3 - - - {{ver_data.p_set2[0] == undefined ? '' : ver_data.p_set2[0] + ':'}}{{ver_data.p_set2[1] == undefined ? '' : ver_data.p_set2[1]}} + + 每天 - + OFF ON - P4 + P3 - - {{ver_data.p_set3[0] == undefined ? '' : ver_data.p_set3[0] + ':'}}{{ver_data.p_set3[1] == undefined ? '' : ver_data.p_set3[1]}} + + {{ver_data.p_set3 && ver_data.p_set3[0] !== undefined ? ver_data.p_set3[0].toString().padStart(2, '0') + ':' + ver_data.p_set3[1].toString().padStart(2, '0') : '--:--'}} + + + 每{{ver_data.p_set3[4]}}天 + + + 每天 - + OFF ON - P5 + P4 - - {{ver_data.p_set4[0] == undefined ? '' : ver_data.p_set4[0] + ':'}}{{ver_data.p_set4[1] == undefined ? '' : ver_data.p_set4[1]}} + + {{ver_data.p_set4 && ver_data.p_set4[0] !== undefined ? ver_data.p_set4[0].toString().padStart(2, '0') + ':' + ver_data.p_set4[1].toString().padStart(2, '0') : '--:--'}} + + + 每{{ver_data.p_set4[4]}}天 + + + 每天 - + + OFF + + + ON + + + P5 + + + {{ver_data.p_set5 && ver_data.p_set5[0] !== undefined ? ver_data.p_set5[0].toString().padStart(2, '0') + ':' + ver_data.p_set5[1].toString().padStart(2, '0') : '--:--'}} + + + 每{{ver_data.p_set5[4]}}天 + + + 每天 + + + + + + + + OFF @@ -183,11 +213,17 @@ P6 - - {{ver_data.p_set5[0] == undefined ? '' : ver_data.p_set5[0] + ':'}}{{ver_data.p_set5[1] == undefined ? '' : ver_data.p_set5[1]}} + + {{ver_data.p_set6 && ver_data.p_set6[0] !== undefined ? ver_data.p_set6[0].toString().padStart(2, '0') + ':' + ver_data.p_set6[1].toString().padStart(2, '0') : '--:--'}} + + + 每{{ver_data.p_set6[4]}}天 + + + 每天 - @@ -341,7 +377,7 @@ }, minute: '--', second: '--', - + hasShownVersionAlert: false, devicesList: [], deviceId: '', name: '', @@ -515,7 +551,7 @@ if (that.deviceId != '') { let systemInfo = uni.getSystemInfoSync() if (systemInfo.platform == 'android') { - console.log("进入这里是IOS") + console.log("进入这里是Android") xBlufi.notifyStartDiscoverBle({ 'isStart': false }) @@ -527,9 +563,8 @@ name: that.name }) } else if (systemInfo.platform == 'ios') { - // 当前设备是 iOS console.log("进入这里是IOS") - that.findDevice() //使用递归函数不断去匹配 + that.findDevice() } } } @@ -903,27 +938,34 @@ xBlufi.notifyInitBleEsp32({ deviceId: this.deviceId }) + // 连接成功后立即发送一次获取数据命令 + setTimeout(() => { + console.log("连接成功后发送获取数据命令") + xBlufi.notifySendCustomData({ + customData: "11get" + }) + }, 1000) }else{ this.vardataflag = 1 this.clearDisconnectTimer() } break case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA: - console.log("1收到设备发来的自定义数据结果:", options.data,options.data.length) + console.log("收到设备数据:", options.data) if (options.data.indexOf("prom:") !== -1) { - console.log('固件升级中') - var indexOld = options.data.substring(options.data.indexOf('prom:')) - 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("升级进度:", this.progress) - if (this.progress === 6000) { - console.log('固件成功') - this.progress = 100 + console.log('固件升级中') + var indexOld = options.data.substring(options.data.indexOf('prom:')) + 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("升级进度:", this.progress) + if (this.progress === 6000) { + console.log('固件成功') + this.progress = 100 uni.showToast({ title: '固件升级成功', icon: 'success', @@ -935,10 +977,10 @@ url:'/pages/index/index' }) },2000) - } - if (this.progress === 9000) { - console.log('固件升级失败') - this.progress = 99 + } + if (this.progress === 9000) { + console.log('固件升级失败') + this.progress = 99 uni.showToast({ title: '固件升级失败', icon: 'none', @@ -950,8 +992,8 @@ url:'/pages/index/index' }) },1000) - } - }else{ + } + } else { this.datalist = options.data.slice(0, -1) + ";" this.vardataflag = 3 if(this.pre == 'WATER'){ @@ -971,15 +1013,15 @@ }, // 每隔一时间发送一次获取数据 getshuju() { - const that = this - that.intervalId = setInterval(() => { - if (that.vardataflag == 3) { - xBlufi.notifySendCustomData({ - customData: "11get" - }) - } - console.log("定时器一段时间执行一次") - }, 10000) + const that = this + that.intervalId = setInterval(() => { + if (that.vardataflag == 3) { + console.log("发送获取数据命令") + xBlufi.notifySendCustomData({ + customData: "11get" + }) + } + }, 10000) }, // 清除定时器 clearTimer() { @@ -1009,41 +1051,87 @@ // 处理从设备接收数据 getchuli() { const inputString = this.datalist; + console.log('接收到的数据:', inputString); // 检查是否有 @ 分隔符 const hasAtSymbol = inputString.includes('@'); let processedString; + let currentDay = 0; if (hasAtSymbol) { const [ver, restOfString] = inputString.split('@'); this.ver = ver || ''; - processedString = restOfString || ''; // 如果 restOfString 是 undefined,设置为空字符串 + 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 = ''; // 如果没有 @,ver 设置为空 + processedString = inputString; + this.ver = ''; } - console.log(this.ver, processedString, 'ververver'); + console.log('处理后的字符串:', processedString); + console.log(this.ver,'this.verthis.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("没有找到版本号数字"); + } - const pairs = processedString.split(';').filter(Boolean); // 过滤掉空字符串 - console.log(pairs, '10101010'); + const pairs = processedString.split(';').filter(Boolean); + 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(':'); if (key === 'show') { showObject.showArray = value.split(',').map(Number); } else if (key.startsWith('p_set')) { - pSetObjects[key] = value.split(',').map(Number); + const values = value.split(',').map(Number); + // 确保数组长度为5 + while (values.length < 5) { + values.push(0); + } + pSetObjects[key] = values; } }); - this.ver_data = pSetObjects; // 六个浇水时间段 + this.ver_data = pSetObjects; this.jstimeobj = pSetObjects; - this.showobj = showObject; // 雨滴,锁,等是否开启 + this.showobj = showObject; // 设置开关状态 this.yschecked = this.showobj.showArray[1] !== 1; @@ -1065,9 +1153,10 @@ }; const getTimeFromArray = (timeArray) => { - const [hour, minute, , second] = timeArray; + if (!timeArray || timeArray.length < 2) return null; + const [hour, minute] = timeArray; const date = new Date(); - date.setHours(hour, minute, second, 0); // 毫秒设为0 + date.setHours(hour, minute, 0, 0); return date; }; @@ -1080,9 +1169,15 @@ 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; - if (timeDate > new Date()) { + // 检查是否应该在这一天浇水 + 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; nextTime = timeDate; @@ -1099,7 +1194,14 @@ this.xctimesc = nextWaterDuration || '未知'; this.sctimejs = prevTime ? prevTime.toTimeString().slice(0, 5) : '无上次浇水时间'; this.xctimesj = nextTime ? nextTime.toTimeString().slice(0, 5) : '无下次浇水时间'; - console.log('下次浇水时间', this.xctimesj, '距离下次浇水时间', this.xctime, '上次浇水时间', this.sctimejs); + + console.log('解析后的数据:', { + ver_data: this.ver_data, + showobj: this.showobj, + nextTime: this.xctimesj, + nextTimeDiff: this.xctime, + prevTime: this.sctimejs + }); }, // 初始化断开蓝牙定时器 initDisconnectTimer() { @@ -1464,7 +1566,7 @@ } .devicebox { width: 100%; - max-height: 320rpx; + max-height: 400rpx; background: #FFFFFF; box-shadow: 0rpx 0rpx 38rpx 0rpx rgba(128, 128, 128, 0.3); filter: blur(0px); @@ -1489,6 +1591,17 @@ font-weight: 600; margin-top: 4rpx; } + .time { + font-size: 28rpx; + color: #3D3D3D; + margin-top: 4rpx; + } + .interval { + font-size: 24rpx; + color: #3D3D3D; + font-weight: 600; + margin-top: 4rpx; + } .img { text-align: center; image {