11 浇花器弹窗手动浇水
This commit is contained in:
parent
03a1b6994b
commit
b3da673f96
|
@ -4,17 +4,17 @@
|
||||||
id="navbar">
|
id="navbar">
|
||||||
</u-navbar>
|
</u-navbar>
|
||||||
<image class="bj" src="https://api.ccttiot.com/smartmeter/img/static/urqUoIyCCEBykZ2oG8eO" mode=""></image>
|
<image class="bj" src="https://api.ccttiot.com/smartmeter/img/static/urqUoIyCCEBykZ2oG8eO" mode=""></image>
|
||||||
<view class="list">
|
<view class="list">
|
||||||
<view class="list_val" v-for="(item,index) in 6" :key="index">
|
<view class="list_val" v-for="(values, key, index) in list" :key="key">
|
||||||
<view class="lt" @click="btnitem">
|
<view class="lt" @click="btnitem(key)">
|
||||||
<view class="one">07:00</view>
|
<view class="one">{{ formattedTime(values[0], values[1]) }}</view>
|
||||||
<view class="two"> P{{index + 1}} <text></text> 5分15秒 </view>
|
<view class="two">P{{ index + 1 }} <text></text> {{ formatTime(values[2]) }}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="rt">
|
<view class="rt">
|
||||||
<u-switch v-model="checked" active-color="#48893B" inactive-color="#BDBCBC"></u-switch>
|
<u-switch v-model="values[3]" active-color="#48893B" inactive-color="#BDBCBC"></u-switch>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 设置浇水时间弹窗 -->
|
<!-- 设置浇水时间弹窗 -->
|
||||||
<view class="jiaoshui" v-if="timeflag">
|
<view class="jiaoshui" v-if="timeflag">
|
||||||
|
@ -84,7 +84,9 @@
|
||||||
minute:'--',
|
minute:'--',
|
||||||
second:'--',
|
second:'--',
|
||||||
hour:'--',
|
hour:'--',
|
||||||
minutekq:'--'
|
minutekq:'--',
|
||||||
|
list:{},
|
||||||
|
checkedStatus: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 分享到好友(会话)
|
// 分享到好友(会话)
|
||||||
|
@ -94,7 +96,6 @@
|
||||||
path: '/pages/index/index'
|
path: '/pages/index/index'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 分享到朋友圈
|
// 分享到朋友圈
|
||||||
onShareTimeline: function() {
|
onShareTimeline: function() {
|
||||||
return {
|
return {
|
||||||
|
@ -103,10 +104,37 @@
|
||||||
path: '/pages/index/index'
|
path: '/pages/index/index'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad(option) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(this.list);
|
||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
|
formattedTime(minutes, seconds) {
|
||||||
|
// 将数字转换为字符串并补零
|
||||||
|
const formattedMinutes = String(minutes).padStart(2, '0');
|
||||||
|
const formattedSeconds = String(seconds).padStart(2, '0');
|
||||||
|
// 返回格式化后的时间字符串
|
||||||
|
return `${formattedMinutes}:${formattedSeconds}`;
|
||||||
|
},
|
||||||
|
|
||||||
|
formatTime(seconds) {
|
||||||
|
const minutes = Math.floor(seconds / 60);
|
||||||
|
const remainingSeconds = seconds % 60;
|
||||||
|
return `${minutes}分${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}秒`;
|
||||||
|
},
|
||||||
|
|
||||||
// 点击定时
|
// 点击定时
|
||||||
btnitem(){
|
btnitem(){
|
||||||
this.timeflag = true
|
this.timeflag = true
|
||||||
|
|
|
@ -22,14 +22,13 @@
|
||||||
MAC:{{item.name}}
|
MAC:{{item.name}}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="add">
|
<view class="add" @click="btnadd(item.name)">
|
||||||
添加
|
添加
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
|
||||||
<!-- 未搜索到设备 -->
|
<!-- 未搜索到设备 -->
|
||||||
<view class="wei" v-else>
|
<view class="wei" v-else>
|
||||||
<image src="https://api.ccttiot.com/smartmeter/img/static/uQ4g6A27FGtF34ebOtea" mode=""></image>
|
<image src="https://api.ccttiot.com/smartmeter/img/static/uQ4g6A27FGtF34ebOtea" mode=""></image>
|
||||||
|
@ -66,7 +65,8 @@
|
||||||
deviceId:'',
|
deviceId:'',
|
||||||
name:'',
|
name:'',
|
||||||
mac:'2952BB7A4EE0',
|
mac:'2952BB7A4EE0',
|
||||||
flags:true
|
flags:true,
|
||||||
|
userid:''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 分享到好友(会话)
|
// 分享到好友(会话)
|
||||||
|
@ -86,6 +86,8 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
|
this.getinfo()
|
||||||
|
|
||||||
let that = this
|
let that = this
|
||||||
xBlufi.initXBlufi(1);
|
xBlufi.initXBlufi(1);
|
||||||
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent)
|
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent)
|
||||||
|
@ -106,6 +108,38 @@
|
||||||
}, 2000)
|
}, 2000)
|
||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
|
// 获取用户信息
|
||||||
|
getinfo() {
|
||||||
|
this.$u.get(`/appVerify/profile`).then((res) => {
|
||||||
|
if (res.code == 200) {
|
||||||
|
this.userid = res.data.userId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
// 点击添加添加绑定设备
|
||||||
|
btnadd(e){
|
||||||
|
let mac = e.name.slice(5, 17)
|
||||||
|
let data = {
|
||||||
|
mac:mac,
|
||||||
|
userId:this.userid
|
||||||
|
}
|
||||||
|
this.$u.get(`/app/bandDevice`,data).then((res) => {
|
||||||
|
if (res.code == 200) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '添加成功',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
uni.showToast({
|
||||||
|
title: res.msg,
|
||||||
|
icon: 'none',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
btnss(){
|
btnss(){
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: '搜索中...'
|
title: '搜索中...'
|
||||||
|
@ -136,7 +170,6 @@
|
||||||
}, 2000)
|
}, 2000)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// 获取附近蓝牙设备列表
|
// 获取附近蓝牙设备列表
|
||||||
funListenDeviceMsgEvent: function(options) {
|
funListenDeviceMsgEvent: function(options) {
|
||||||
switch (options.type) {
|
switch (options.type) {
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="selectbox">
|
<view class="selectbox">
|
||||||
<view class="shebeiname">
|
<view class="shebeiname" @click="btnlj">
|
||||||
丁丁浇花器 <text></text>
|
丁丁浇花器 <text></text>
|
||||||
</view>
|
</view>
|
||||||
<view class="shebeiadd" @click="btnaddsb">
|
<view class="shebeiadd" @click="btnaddsb">
|
||||||
|
@ -62,21 +62,99 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="deviceweek">
|
<view class="deviceweek">
|
||||||
<view class="weeklist" v-for="(item,index) in 6" :key="index">
|
<view class="weeklist">
|
||||||
<view class="kg">
|
<view class="kg" v-if="ver_data.p_set5[3] == 1">
|
||||||
OFF
|
OFF
|
||||||
</view>
|
</view>
|
||||||
|
<view class="kg" style="color: #48893B;" v-else>
|
||||||
|
NO
|
||||||
|
</view>
|
||||||
<view class="weekday">
|
<view class="weekday">
|
||||||
P{{index + 1}}
|
P1
|
||||||
</view>
|
</view>
|
||||||
<view class="img">
|
<view class="img">
|
||||||
<image src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
<image v-if="formattedTime(ver_data.p_set0[0],ver_data.p_set0[1])== xctimesj" src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||||
|
</image>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="weeklist">
|
||||||
|
<view class="kg" v-if="ver_data.p_set4[3] == 1">
|
||||||
|
OFF
|
||||||
|
</view>
|
||||||
|
<view class="kg" style="color: #48893B;" v-else>
|
||||||
|
NO
|
||||||
|
</view>
|
||||||
|
<view class="weekday">
|
||||||
|
P2
|
||||||
|
</view>
|
||||||
|
<view class="img">
|
||||||
|
<image v-if="formattedTime(ver_data.p_set1[0],ver_data.p_set1[1]) == xctimesj" src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||||
|
</image>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="weeklist">
|
||||||
|
<view class="kg" v-if="ver_data.p_set3[3] == 1">
|
||||||
|
OFF
|
||||||
|
</view>
|
||||||
|
<view class="kg" style="color: #48893B;" v-else>
|
||||||
|
NO
|
||||||
|
</view>
|
||||||
|
<view class="weekday">
|
||||||
|
P3
|
||||||
|
</view>
|
||||||
|
<view class="img">
|
||||||
|
<image v-if="formattedTime(ver_data.p_set2[0],ver_data.p_set2[1]) == xctimesj" src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||||
|
</image>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="weeklist">
|
||||||
|
<view class="kg" v-if="ver_data.p_set2[3] == 1">
|
||||||
|
OFF
|
||||||
|
</view>
|
||||||
|
<view class="kg" style="color: #48893B;" v-else>
|
||||||
|
NO
|
||||||
|
</view>
|
||||||
|
<view class="weekday">
|
||||||
|
P4
|
||||||
|
</view>
|
||||||
|
<view class="img">
|
||||||
|
<image v-if="formattedTime(ver_data.p_set3[0],ver_data.p_set3[1]) == xctimesj" src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||||
|
</image>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="weeklist">
|
||||||
|
<view class="kg" v-if="ver_data.p_set1[3] == 1">
|
||||||
|
OFF
|
||||||
|
</view>
|
||||||
|
<view class="kg" style="color: #48893B;" v-else>
|
||||||
|
NO
|
||||||
|
</view>
|
||||||
|
<view class="weekday">
|
||||||
|
P5
|
||||||
|
</view>
|
||||||
|
<view class="img">
|
||||||
|
<image v-if="formattedTime(ver_data.p_set4[0],ver_data.p_set4[1]) == xctimesj" src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||||
|
</image>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="weeklist">
|
||||||
|
<view class="kg" v-if="ver_data.p_set0[3] == 1">
|
||||||
|
OFF
|
||||||
|
</view>
|
||||||
|
<view class="kg" style="color: #48893B;" v-else>
|
||||||
|
NO
|
||||||
|
</view>
|
||||||
|
<view class="weekday">
|
||||||
|
P6
|
||||||
|
</view>
|
||||||
|
<view class="img">
|
||||||
|
<image v-if="formattedTime(ver_data.p_set5[0],ver_data.p_set5[1]) == xctimesj" src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||||
</image>
|
</image>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<button @click="kq">开启</button><button @click="gb">关闭</button>
|
<!-- <button @click="kq">开启</button><button @click="gb">关闭</button><button @click="hq">获取</button> -->
|
||||||
<!-- 开关选择 -->
|
<!-- 开关选择 -->
|
||||||
<view class="switchbox">
|
<view class="switchbox">
|
||||||
<view class="switch_he">
|
<view class="switch_he">
|
||||||
|
@ -113,9 +191,9 @@
|
||||||
</view>
|
</view>
|
||||||
<view class="wateringlogbd">
|
<view class="wateringlogbd">
|
||||||
<view class="lt">
|
<view class="lt">
|
||||||
<view class="">距离下次:8小时</view>
|
<view class="">距离下次:{{xctime}}</view>
|
||||||
<view class="">下次浇水时长:15分钟</view>
|
<view class="">下次浇水时长:{{xctimesc}}</view>
|
||||||
<view class="">上次浇水:10-15 15:22</view>
|
<view class="">上次浇水:{{sctimejs}}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="rt">
|
<view class="rt">
|
||||||
<image src="https://api.ccttiot.com/smartmeter/img/static/uagx3wGa7RYvqKqoSymy" mode=""></image>
|
<image src="https://api.ccttiot.com/smartmeter/img/static/uagx3wGa7RYvqKqoSymy" mode=""></image>
|
||||||
|
@ -147,7 +225,7 @@
|
||||||
<view class="toptit">
|
<view class="toptit">
|
||||||
选择浇水时长
|
选择浇水时长
|
||||||
</view>
|
</view>
|
||||||
<view class="container" @click="show = true">
|
<view class="container" @click="showjs = true">
|
||||||
<view class="">{{minute}}分</view>
|
<view class="">{{minute}}分</view>
|
||||||
<text>:</text>
|
<text>:</text>
|
||||||
<view class="">{{second}}秒</view>
|
<view class="">{{second}}秒</view>
|
||||||
|
@ -163,7 +241,7 @@
|
||||||
</view>
|
</view>
|
||||||
<view class="manualmask" v-if="sdjsflag"></view>
|
<view class="manualmask" v-if="sdjsflag"></view>
|
||||||
<!-- 选择浇水时间-->
|
<!-- 选择浇水时间-->
|
||||||
<u-picker v-model="show" mode="time" :params="params" @confirm="confirm"></u-picker>
|
<u-picker v-model="showjs" mode="time" :params="params" @confirm="confirm"></u-picker>
|
||||||
|
|
||||||
<tab-bar :indexs='0'></tab-bar>
|
<tab-bar :indexs='0'></tab-bar>
|
||||||
|
|
||||||
|
@ -191,7 +269,7 @@
|
||||||
selectedMinute: '1',
|
selectedMinute: '1',
|
||||||
selectedSecond: '1',
|
selectedSecond: '1',
|
||||||
sdjsflag:false ,
|
sdjsflag:false ,
|
||||||
show: false,
|
showjs: false,
|
||||||
params: {
|
params: {
|
||||||
year: false,
|
year: false,
|
||||||
month: false,
|
month: false,
|
||||||
|
@ -207,8 +285,13 @@
|
||||||
deviceId:'',
|
deviceId:'',
|
||||||
name:'',
|
name:'',
|
||||||
mac:'2952BB7A4EE0',
|
mac:'2952BB7A4EE0',
|
||||||
jstime:''
|
jstime:'',
|
||||||
|
ver_data:{},
|
||||||
|
showobj:{},
|
||||||
|
xctime:'--',
|
||||||
|
sctimejs:'--',
|
||||||
|
xctimesc:'--',
|
||||||
|
xctimesj:''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 分享到好友(会话)
|
// 分享到好友(会话)
|
||||||
|
@ -248,12 +331,55 @@
|
||||||
}, 2000)
|
}, 2000)
|
||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
|
this.getinfo()
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
formattedTime(minutes, seconds) {
|
||||||
|
// 将数字转换为字符串并补零
|
||||||
|
const formattedMinutes = String(minutes).padStart(2, '0');
|
||||||
|
const formattedSeconds = String(seconds).padStart(2, '0');
|
||||||
|
// 返回格式化后的时间字符串
|
||||||
|
return `${formattedMinutes}:${formattedSeconds}`;
|
||||||
|
},
|
||||||
|
// 点击连接
|
||||||
|
btnlj(){
|
||||||
|
let that = this
|
||||||
|
xBlufi.initXBlufi(1)
|
||||||
|
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent)
|
||||||
|
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)
|
||||||
|
},
|
||||||
|
// 获取用户信息
|
||||||
|
getinfo() {
|
||||||
|
this.$u.get(`/appVerify/profile`).then((res) => {
|
||||||
|
if (res.code == 200) {
|
||||||
|
this.userobj = res.data
|
||||||
|
// 根据用户id获取当前用户
|
||||||
|
this.$u.get(`/app/getDeviceInfoByUser?userId=${this.userobj.userId}`).then((res) => {
|
||||||
|
if (res.code == 200) {
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
kq(){
|
kq(){
|
||||||
uni.getNetworkType({
|
uni.getNetworkType({
|
||||||
success(res) {
|
success(res) {
|
||||||
|
@ -298,6 +424,28 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
hq(){
|
||||||
|
uni.getNetworkType({
|
||||||
|
success(res) {
|
||||||
|
if (res.networkType !== 'none') {
|
||||||
|
uni.getConnectedBluetoothDevices({
|
||||||
|
success(res) {
|
||||||
|
setTimeout(()=> {
|
||||||
|
xBlufi.notifySendCustomData({
|
||||||
|
customData:'11get'
|
||||||
|
})
|
||||||
|
},1500)
|
||||||
|
},
|
||||||
|
fail(err) {
|
||||||
|
console.error('获取已连接蓝牙设备信息失败:',err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.log('手机未连接网络')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
// 雨水感应
|
// 雨水感应
|
||||||
btnyushui(){
|
btnyushui(){
|
||||||
let that = this
|
let that = this
|
||||||
|
@ -414,7 +562,7 @@
|
||||||
// 点击跳转到定时页面
|
// 点击跳转到定时页面
|
||||||
btntime(){
|
btntime(){
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url:'/page_user/dingshi'
|
url:'/page_user/dingshi?list=' + JSON.stringify(this.ver_data)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -438,7 +586,7 @@
|
||||||
success(res) {
|
success(res) {
|
||||||
setTimeout(()=> {
|
setTimeout(()=> {
|
||||||
xBlufi.notifySendCustomData({
|
xBlufi.notifySendCustomData({
|
||||||
customData: "11time@" + that.jstime
|
customData: "11time@" + that.jstime + '@'
|
||||||
})
|
})
|
||||||
that.sdjsflag = false
|
that.sdjsflag = false
|
||||||
that.kgflag = true
|
that.kgflag = true
|
||||||
|
@ -556,9 +704,9 @@
|
||||||
success(res) {
|
success(res) {
|
||||||
setTimeout(()=> {
|
setTimeout(()=> {
|
||||||
xBlufi.notifySendCustomData({
|
xBlufi.notifySendCustomData({
|
||||||
customData: "11unlock"
|
customData: "11get"
|
||||||
})
|
})
|
||||||
},1500)
|
},3000)
|
||||||
},
|
},
|
||||||
fail(err) {
|
fail(err) {
|
||||||
console.error('获取已连接蓝牙设备信息失败:',err)
|
console.error('获取已连接蓝牙设备信息失败:',err)
|
||||||
|
@ -582,8 +730,98 @@
|
||||||
break;
|
break;
|
||||||
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
|
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
|
||||||
console.log("1收到设备发来的自定义数据结果:", options.data)
|
console.log("1收到设备发来的自定义数据结果:", options.data)
|
||||||
this.ver_data = this.parseCustomData(options.data)
|
const inputString = options.data
|
||||||
break;
|
const pairs = inputString.split(';')
|
||||||
|
const showObject = {}
|
||||||
|
const pSetObjects = {}
|
||||||
|
pairs.forEach(pair => {
|
||||||
|
const [key, value] = pair.split(':');
|
||||||
|
if (key === 'show') {
|
||||||
|
showObject.showArray = value.split(',').map(Number);
|
||||||
|
} else if (key.startsWith('p_set')) {
|
||||||
|
const numbers = value.split(',').map(Number);
|
||||||
|
pSetObjects[key] = numbers;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.ver_data = pSetObjects //六个浇水时间段
|
||||||
|
this.showobj = showObject //雨滴,锁,等是否开启
|
||||||
|
if(this.showobj.showArray[1] == 1){
|
||||||
|
this.yschecked = false
|
||||||
|
}else{
|
||||||
|
this.yschecked = true
|
||||||
|
}
|
||||||
|
if(this.showobj.showArray[0] == 1){
|
||||||
|
this.etchecked = false
|
||||||
|
}else{
|
||||||
|
this.etchecked = true
|
||||||
|
}
|
||||||
|
// 计算浇水时间
|
||||||
|
const ver_Data = this.ver_data
|
||||||
|
function secondsToMinutesAndSeconds(seconds) {
|
||||||
|
const minutes = Math.floor(seconds / 60);
|
||||||
|
const remainingSeconds = seconds % 60;
|
||||||
|
return `${minutes}分${remainingSeconds}秒`;
|
||||||
|
}
|
||||||
|
// 获取当前时间
|
||||||
|
const now = new Date();
|
||||||
|
// 辅助函数:将时间数组转换为 Date 对象
|
||||||
|
function timeArrayToDate(timeArray) {
|
||||||
|
const [hour, minute, second] = timeArray.slice(0, 3);
|
||||||
|
const date = new Date();
|
||||||
|
date.setHours(hour, minute, second, 0); // 毫秒设为0
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
// 辅助函数:计算两个时间之间的差值(以小时和分钟表示)
|
||||||
|
function timeDifference(date1, date2) {
|
||||||
|
const diffMs = Math.abs(date1 - date2);
|
||||||
|
const diffSeconds = Math.floor(diffMs / 1000);
|
||||||
|
const diffMinutes = Math.floor(diffSeconds / 60);
|
||||||
|
const diffHours = Math.floor(diffMinutes / 60);
|
||||||
|
const remainingMinutes = diffMinutes % 60;
|
||||||
|
return { hours: diffHours, minutes: remainingMinutes };
|
||||||
|
}
|
||||||
|
// 遍历 ver_Data 对象
|
||||||
|
let nextTimeDiff = null;
|
||||||
|
let nextTime = null;
|
||||||
|
let prevTimeDiff = null;
|
||||||
|
let prevTime = null;
|
||||||
|
let nextWaterDuration = null; // 用于存储下次浇水时长
|
||||||
|
for (const key in ver_Data) {
|
||||||
|
if (ver_Data.hasOwnProperty(key) && ver_Data[key][3] === 1) {
|
||||||
|
const timeArray = ver_Data[key];
|
||||||
|
const timeDate = timeArrayToDate(timeArray);
|
||||||
|
// 计算与当前时间的差值
|
||||||
|
const diff = timeDifference(timeDate, now);
|
||||||
|
// 判断是下一次时间还是上一次时间
|
||||||
|
if (timeDate > now) {
|
||||||
|
if (!nextTime || diff.hours * 60 + diff.minutes < nextTimeDiff.hours * 60 + nextTimeDiff.minutes) {
|
||||||
|
nextTimeDiff = diff;
|
||||||
|
nextTime = timeDate;
|
||||||
|
nextWaterDuration = secondsToMinutesAndSeconds(timeArray[2]); // 获取并转换浇水时长
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!prevTime || (now.getTime() - timeDate.getTime()) < (now.getTime() - prevTime.getTime())) {
|
||||||
|
prevTimeDiff = timeDifference(now, timeDate); // 注意这里要反过来算
|
||||||
|
prevTime = timeDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 输出结果
|
||||||
|
this.xctime = `${nextTimeDiff.hours}时${nextTimeDiff.minutes}分`
|
||||||
|
this.xctimesc = nextWaterDuration
|
||||||
|
let timesc = prevTime.toTimeString().split(' ')[0]
|
||||||
|
this.sctimejs = timesc.slice(0,-3)
|
||||||
|
let xcjs = nextTime.toTimeString().split(' ')[0]
|
||||||
|
this.xctimesj = xcjs.slice(0,-3)
|
||||||
|
// console.log('距离下次最近的时间差:', nextTimeDiff ? `${nextTimeDiff.hours}时${nextTimeDiff.minutes}分` : '无');
|
||||||
|
// console.log('下次时间:', nextTime ? nextTime.toTimeString().split(' ')[0] : '无');
|
||||||
|
// console.log('下次浇水时长:', nextWaterDuration || '无');
|
||||||
|
// console.log('距离上次最近的时间差:', prevTimeDiff ? `${prevTimeDiff.hours}时${prevTimeDiff.minutes}分` : '无');
|
||||||
|
// console.log('上次时间:', prevTime ? prevTime.toTimeString().split(' ')[0] : '无')
|
||||||
|
|
||||||
|
|
||||||
|
break
|
||||||
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
|
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
|
||||||
if (options.result) {
|
if (options.result) {
|
||||||
let uniqueDevicesList = Array.from(new Set(this.devicesList))
|
let uniqueDevicesList = Array.from(new Set(this.devicesList))
|
||||||
|
@ -604,27 +842,10 @@
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 从蓝牙拿到数据进行解析
|
|
||||||
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
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -969,12 +1190,13 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
margin-top: 34rpx;
|
margin-top: 34rpx;
|
||||||
align-items: center;
|
// align-items: center;
|
||||||
|
|
||||||
.weeklist {
|
.weeklist {
|
||||||
.kg {
|
.kg {
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #999999;
|
color: #999999;
|
||||||
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.weekday {
|
.weekday {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user