浇花器

This commit is contained in:
3321822538@qq.com 2025-04-25 16:37:27 +08:00
parent f9341f88ee
commit 8bd7b1fbcc
3 changed files with 329 additions and 135 deletions

View File

@ -13,6 +13,7 @@
<view class="lt" @click="btnitem(key,index,values)">
<view class="one">{{ formattedTime(values[0], values[1]) }}</view>
<view class="two">P{{ index + 1 }} <text></text> {{ formatTime(values[2]) }}</view>
<view class="two">{{ formatInterval(values[4]) }}</view>
</view>
<view class="rt">
<u-switch v-model="values[3]" @change="btnchange(key,index,values)" active-color="#48893B"
@ -26,18 +27,26 @@
<view class="top">
设置浇水
</view>
<view class="ts">
<view class="jssc">
请设置浇水时间
</view>
<view class="shifen" @click="show = true">
<view class="shifen" @click="btnshowone">
<text>{{hour}}</text> <text>{{minutekq}}</text>
</view>
<view class="jssc">
浇水时长
</view>
<view class="shifen" @click="shows = true">
<view class="shifen" @click="btnshowtwo">
<text>{{minute}}</text> <text>{{second}}</text>
</view>
<view class="jiange">
<text>每几天浇一次</text>
<view class="number-input">
<text class="btn-minus" @click="changeDays(-1)">-</text>
<text class="days">{{jgtian || 1}}</text>
<text class="btn-plus" @click="changeDays(1)">+</text>
</view>
</view>
<view class="anniu">
<view class="qx" @click="btnqx">
取消
@ -134,14 +143,9 @@
maxRetries: 3, //
lastOperation: null, //
//
defaultTime: {
hour: '00',
minute: '00'
},
defaultTimeLength: {
minute: '00',
second: '00'
},
defaultTime:'',
defaultTimeLength: '',
jgtian: ''
}
},
//
@ -172,17 +176,14 @@
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
@ -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);
},
}
}
</script>
@ -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;

View File

@ -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({

View File

@ -79,7 +79,7 @@
</view>
<view class="deviceweek" v-if="pre == 'WATER'">
<view class="weeklist">
<view class="kg" v-if="ver_data.p_set0[3] == 0">
<view class="kg" v-if="!ver_data.p_set1 || ver_data.p_set1[3] == 0">
OFF
</view>
<view class="kg" style="color: #48893B;" v-else>
@ -88,27 +88,14 @@
<view class="weekday">
P1
</view>
<view class="">
{{ver_data.p_set0[0] == undefined ? '' : ver_data.p_set0[0] + ':'}}{{ver_data.p_set0[1] == undefined ? '' : ver_data.p_set0[1]}}
<view class="time">
{{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') : '--:--'}}
</view>
<view class="img">
<image v-if="ver_data.p_set0 && ver_data.p_set0[0] == xctimesj.slice(0,2) && ver_data.p_set0[1] == xctimesj.slice(-2)"
src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
</image>
<view class="interval" v-if="ver_data.p_set1 && ver_data.p_set1[4] > 1">
{{ver_data.p_set1[4]}}
</view>
</view>
<view class="weeklist">
<view class="kg" v-if="ver_data.p_set1[3] == 0">
OFF
</view>
<view class="kg" style="color: #48893B;" v-else>
ON
</view>
<view class="weekday">
P2
</view>
<view class="">
{{ver_data.p_set1[0] == undefined ? '' : ver_data.p_set1[0] + ':'}}{{ver_data.p_set1[1] == undefined ? '' : ver_data.p_set1[1]}}
<view class="interval" v-else>
每天
</view>
<view class="img">
<image v-if="ver_data.p_set1 && ver_data.p_set1[0] == xctimesj.slice(0,2) && ver_data.p_set1[1] == xctimesj.slice(-2)"
@ -117,17 +104,23 @@
</view>
</view>
<view class="weeklist">
<view class="kg" v-if="ver_data.p_set2[3] == 0">
<view class="kg" v-if="!ver_data.p_set2 || ver_data.p_set2[3] == 0">
OFF
</view>
<view class="kg" style="color: #48893B;" v-else>
ON
</view>
<view class="weekday">
P3
P2
</view>
<view class="">
{{ver_data.p_set2[0] == undefined ? '' : ver_data.p_set2[0] + ':'}}{{ver_data.p_set2[1] == undefined ? '' : ver_data.p_set2[1]}}
<view class="time">
{{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') : '--:--'}}
</view>
<view class="interval" v-if="ver_data.p_set2 && ver_data.p_set2[4] > 1">
{{ver_data.p_set2[4]}}
</view>
<view class="interval" v-else>
每天
</view>
<view class="img">
<image v-if="ver_data.p_set2 && ver_data.p_set2[0] == xctimesj.slice(0,2) && ver_data.p_set2[1] == xctimesj.slice(-2)"
@ -136,17 +129,23 @@
</view>
</view>
<view class="weeklist">
<view class="kg" v-if="ver_data.p_set3[3] == 0">
<view class="kg" v-if="!ver_data.p_set3 || ver_data.p_set3[3] == 0">
OFF
</view>
<view class="kg" style="color: #48893B;" v-else>
ON
</view>
<view class="weekday">
P4
P3
</view>
<view class="">
{{ver_data.p_set3[0] == undefined ? '' : ver_data.p_set3[0] + ':'}}{{ver_data.p_set3[1] == undefined ? '' : ver_data.p_set3[1]}}
<view class="time">
{{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') : '--:--'}}
</view>
<view class="interval" v-if="ver_data.p_set3 && ver_data.p_set3[4] > 1">
{{ver_data.p_set3[4]}}
</view>
<view class="interval" v-else>
每天
</view>
<view class="img">
<image v-if="ver_data.p_set3 && ver_data.p_set3[0] == xctimesj.slice(0,2) && ver_data.p_set3[1] == xctimesj.slice(-2)"
@ -155,17 +154,23 @@
</view>
</view>
<view class="weeklist">
<view class="kg" v-if="ver_data.p_set4[3] == 0">
<view class="kg" v-if="!ver_data.p_set4 || ver_data.p_set4[3] == 0">
OFF
</view>
<view class="kg" style="color: #48893B;" v-else>
ON
</view>
<view class="weekday">
P5
P4
</view>
<view class="">
{{ver_data.p_set4[0] == undefined ? '' : ver_data.p_set4[0] + ':'}}{{ver_data.p_set4[1] == undefined ? '' : ver_data.p_set4[1]}}
<view class="time">
{{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') : '--:--'}}
</view>
<view class="interval" v-if="ver_data.p_set4 && ver_data.p_set4[4] > 1">
{{ver_data.p_set4[4]}}
</view>
<view class="interval" v-else>
每天
</view>
<view class="img">
<image v-if="ver_data.p_set4 && ver_data.p_set4[0] == xctimesj.slice(0,2) && ver_data.p_set4[1] == xctimesj.slice(-2)"
@ -174,7 +179,32 @@
</view>
</view>
<view class="weeklist">
<view class="kg" v-if="ver_data.p_set5[3] == 0">
<view class="kg" v-if="!ver_data.p_set5 || ver_data.p_set5[3] == 0">
OFF
</view>
<view class="kg" style="color: #48893B;" v-else>
ON
</view>
<view class="weekday">
P5
</view>
<view class="time">
{{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') : '--:--'}}
</view>
<view class="interval" v-if="ver_data.p_set5 && ver_data.p_set5[4] > 1">
{{ver_data.p_set5[4]}}
</view>
<view class="interval" v-else>
每天
</view>
<view class="img">
<image v-if="ver_data.p_set5 && ver_data.p_set5[0] == xctimesj.slice(0,2) && ver_data.p_set5[1] == xctimesj.slice(-2)"
src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
</image>
</view>
</view>
<view class="weeklist">
<view class="kg" v-if="!ver_data.p_set6 || ver_data.p_set6[3] == 0">
OFF
</view>
<view class="kg" style="color: #48893B;" v-else>
@ -183,11 +213,17 @@
<view class="weekday">
P6
</view>
<view class="">
{{ver_data.p_set5[0] == undefined ? '' : ver_data.p_set5[0] + ':'}}{{ver_data.p_set5[1] == undefined ? '' : ver_data.p_set5[1]}}
<view class="time">
{{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') : '--:--'}}
</view>
<view class="interval" v-if="ver_data.p_set6 && ver_data.p_set6[4] > 1">
{{ver_data.p_set6[4]}}
</view>
<view class="interval" v-else>
每天
</view>
<view class="img">
<image v-if="ver_data.p_set5 && ver_data.p_set5[0] == xctimesj.slice(0,2) && ver_data.p_set5[1] == xctimesj.slice(-2)"
<image v-if="ver_data.p_set6 && ver_data.p_set6[0] == xctimesj.slice(0,2) && ver_data.p_set6[1] == xctimesj.slice(-2)"
src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
</image>
</view>
@ -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,13 +938,20 @@
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:'))
@ -951,7 +993,7 @@
})
},1000)
}
}else{
} else {
this.datalist = options.data.slice(0, -1) + ";"
this.vardataflag = 3
if(this.pre == 'WATER'){
@ -974,11 +1016,11 @@
const that = this
that.intervalId = setInterval(() => {
if (that.vardataflag == 3) {
console.log("发送获取数据命令")
xBlufi.notifySendCustomData({
customData: "11get"
})
}
console.log("定时器一段时间执行一次")
}, 10000)
},
//
@ -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 pairs = processedString.split(';').filter(Boolean); //
console.log(pairs, '10101010');
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);
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);
const diff = calculateTimeDifference(timeDate, new Date());
if (!timeDate) continue;
if (timeDate > new Date()) {
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;
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 {