11 浇花器弹窗手动浇水

This commit is contained in:
3321822538@qq.com 2024-10-23 18:04:30 +08:00
parent 03a1b6994b
commit b3da673f96
3 changed files with 345 additions and 62 deletions

View File

@ -4,17 +4,17 @@
id="navbar">
</u-navbar>
<image class="bj" src="https://api.ccttiot.com/smartmeter/img/static/urqUoIyCCEBykZ2oG8eO" mode=""></image>
<view class="list">
<view class="list_val" v-for="(item,index) in 6" :key="index">
<view class="lt" @click="btnitem">
<view class="one">07:00</view>
<view class="two"> P{{index + 1}} <text></text> 5分15秒 </view>
</view>
<view class="rt">
<u-switch v-model="checked" active-color="#48893B" inactive-color="#BDBCBC"></u-switch>
</view>
</view>
</view>
<view class="list">
<view class="list_val" v-for="(values, key, index) in list" :key="key">
<view class="lt" @click="btnitem(key)">
<view class="one">{{ formattedTime(values[0], values[1]) }}</view>
<view class="two">P{{ index + 1 }} <text></text> {{ formatTime(values[2]) }}</view>
</view>
<view class="rt">
<u-switch v-model="values[3]" active-color="#48893B" inactive-color="#BDBCBC"></u-switch>
</view>
</view>
</view>
<!-- 设置浇水时间弹窗 -->
<view class="jiaoshui" v-if="timeflag">
@ -84,7 +84,9 @@
minute:'--',
second:'--',
hour:'--',
minutekq:'--'
minutekq:'--',
list:{},
checkedStatus: {}
}
},
//
@ -94,7 +96,6 @@
path: '/pages/index/index'
}
},
//
onShareTimeline: function() {
return {
@ -103,10 +104,37 @@
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:{
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(){
this.timeflag = true

View File

@ -22,14 +22,13 @@
MAC{{item.name}}
</view>
</view>
<view class="add">
<view class="add" @click="btnadd(item.name)">
添加
</view>
</view>
</view>
</view>
<!-- 未搜索到设备 -->
<view class="wei" v-else>
<image src="https://api.ccttiot.com/smartmeter/img/static/uQ4g6A27FGtF34ebOtea" mode=""></image>
@ -66,7 +65,8 @@
deviceId:'',
name:'',
mac:'2952BB7A4EE0',
flags:true
flags:true,
userid:''
}
},
//
@ -86,6 +86,8 @@
}
},
onLoad() {
this.getinfo()
let that = this
xBlufi.initXBlufi(1);
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent)
@ -106,6 +108,38 @@
}, 2000)
},
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(){
uni.showLoading({
title: '搜索中...'
@ -136,7 +170,6 @@
}, 2000)
},
//
funListenDeviceMsgEvent: function(options) {
switch (options.type) {

View File

@ -30,7 +30,7 @@
</view>
</view>
<view class="selectbox">
<view class="shebeiname">
<view class="shebeiname" @click="btnlj">
丁丁浇花器 <text></text>
</view>
<view class="shebeiadd" @click="btnaddsb">
@ -62,21 +62,99 @@
</view>
</view>
<view class="deviceweek">
<view class="weeklist" v-for="(item,index) in 6" :key="index">
<view class="kg">
<view class="weeklist">
<view class="kg" v-if="ver_data.p_set5[3] == 1">
OFF
</view>
<view class="kg" style="color: #48893B;" v-else>
NO
</view>
<view class="weekday">
P{{index + 1}}
P1
</view>
<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>
</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="switch_he">
@ -113,9 +191,9 @@
</view>
<view class="wateringlogbd">
<view class="lt">
<view class="">距离下次8小时</view>
<view class="">下次浇水时长15分钟</view>
<view class="">上次浇水10-15 15:22</view>
<view class="">距离下次{{xctime}}</view>
<view class="">下次浇水时长{{xctimesc}}</view>
<view class="">上次浇水{{sctimejs}}</view>
</view>
<view class="rt">
<image src="https://api.ccttiot.com/smartmeter/img/static/uagx3wGa7RYvqKqoSymy" mode=""></image>
@ -147,7 +225,7 @@
<view class="toptit">
选择浇水时长
</view>
<view class="container" @click="show = true">
<view class="container" @click="showjs = true">
<view class="">{{minute}}</view>
<text>:</text>
<view class="">{{second}}</view>
@ -163,7 +241,7 @@
</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>
@ -191,7 +269,7 @@
selectedMinute: '1',
selectedSecond: '1',
sdjsflag:false ,
show: false,
showjs: false,
params: {
year: false,
month: false,
@ -207,8 +285,13 @@
deviceId:'',
name:'',
mac:'2952BB7A4EE0',
jstime:''
jstime:'',
ver_data:{},
showobj:{},
xctime:'--',
sctimejs:'--',
xctimesc:'--',
xctimesj:''
}
},
//
@ -248,12 +331,55 @@
}, 2000)
},
onShow() {
this.getinfo()
},
mounted() {
},
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(){
uni.getNetworkType({
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(){
let that = this
@ -414,7 +562,7 @@
//
btntime(){
uni.navigateTo({
url:'/page_user/dingshi'
url:'/page_user/dingshi?list=' + JSON.stringify(this.ver_data)
})
},
@ -438,7 +586,7 @@
success(res) {
setTimeout(()=> {
xBlufi.notifySendCustomData({
customData: "11time@" + that.jstime
customData: "11time@" + that.jstime + '@'
})
that.sdjsflag = false
that.kgflag = true
@ -556,9 +704,9 @@
success(res) {
setTimeout(()=> {
xBlufi.notifySendCustomData({
customData: "11unlock"
customData: "11get"
})
},1500)
},3000)
},
fail(err) {
console.error('获取已连接蓝牙设备信息失败:',err)
@ -582,8 +730,98 @@
break;
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
console.log("1收到设备发来的自定义数据结果", options.data)
this.ver_data = this.parseCustomData(options.data)
break;
const inputString = options.data
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:
if (options.result) {
let uniqueDevicesList = Array.from(new Set(this.devicesList))
@ -604,27 +842,10 @@
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>
@ -969,12 +1190,13 @@
display: flex;
justify-content: space-between;
margin-top: 34rpx;
align-items: center;
// align-items: center;
.weeklist {
.kg {
font-size: 24rpx;
color: #999999;
font-weight: 600;
}
.weekday {