完善 命令发送 初步

This commit is contained in:
3321822538@qq.com 2024-10-24 18:00:12 +08:00
parent b3da673f96
commit f6c4e7d835
2 changed files with 342 additions and 116 deletions

View File

@ -6,12 +6,12 @@
<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="(values, key, index) in list" :key="key"> <view class="list_val" v-for="(values, key, index) in list" :key="key">
<view class="lt" @click="btnitem(key)"> <view class="lt" @click="btnitem(key,index,values)">
<view class="one">{{ formattedTime(values[0], values[1]) }}</view> <view class="one">{{ formattedTime(values[0], values[1]) }}</view>
<view class="two">P{{ index + 1 }} <text></text> {{ formatTime(values[2]) }}</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="values[3]" active-color="#48893B" inactive-color="#BDBCBC"></u-switch> <u-switch v-model="values[3]" @change="btnchange(key,index,values)" active-color="#48893B" inactive-color="#BDBCBC"></u-switch>
</view> </view>
</view> </view>
</view> </view>
@ -22,7 +22,7 @@
设置浇水 设置浇水
</view> </view>
<view class="ts"> <view class="ts">
距离下次浇水时间还有20小时41分 距离下次浇水时间还有{{xctime}}
</view> </view>
<view class="shifen" @click="show = true"> <view class="shifen" @click="show = true">
<text>{{hour}}</text> <text>{{minutekq}}</text> <text>{{hour}}</text> <text>{{minutekq}}</text>
@ -48,10 +48,13 @@
<!-- 定时时长 --> <!-- 定时时长 -->
<u-picker v-model="shows" mode="time" :params="params" @confirm="confirms"></u-picker> <u-picker v-model="shows" mode="time" :params="params" @confirm="confirms"></u-picker>
<view class="mask" style="z-index: 9999;" v-if="kgflag"></view>
</view> </view>
</template> </template>
<script> <script>
var xBlufi = require("@/components/blufi/xBlufi.js")
export default { export default {
data() { data() {
return { return {
@ -86,7 +89,14 @@
hour:'--', hour:'--',
minutekq:'--', minutekq:'--',
list:{}, list:{},
checkedStatus: {} checkedStatus: {},
deviceindex:'',
devicemiao:'',
deviceflag:'',
devicehour:'',
deviceminute:'',
kgflag:false,
xctime:''
} }
}, },
// //
@ -105,22 +115,115 @@
} }
}, },
onLoad(option) { onLoad(option) {
this.list = JSON.parse(option.list) // this.list = JSON.parse(option.list)
for (let key in this.list) { // for (let key in this.list) {
if (this.list.hasOwnProperty(key)) { // if (this.list.hasOwnProperty(key)) {
// // //
let arr = this.list[key]; // let arr = this.list[key];
// // //
if (arr[arr.length - 1] === 0) { // if (arr[arr.length - 1] === 0) {
arr[arr.length - 1] = false; // arr[arr.length - 1] = false;
} else if (arr[arr.length - 1] === 1) { // } else if (arr[arr.length - 1] === 1) {
arr[arr.length - 1] = true; // arr[arr.length - 1] = true;
} // }
} // }
} // }
console.log(this.list); // console.log(this.list);
},
onShow() {
xBlufi.initXBlufi(1)
xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
uni.getNetworkType({
success(res) {
if (res.networkType !== 'none') {
uni.getConnectedBluetoothDevices({
success(res) {
setTimeout(()=> {
xBlufi.notifySendCustomData({
customData: "11get"
})
},1000)
},
fail(err) {
console.error('获取已连接蓝牙设备信息失败:',err)
}
})
} else {
console.log('手机未连接网络')
}
}
})
}, },
methods:{ methods:{
//
btnchange(key,index,values){
this.kgflag = true
this.btnitem(key,index,values)
this.btnqx()
this.deviceindex = index
this.devicehour = values[0]
this.deviceminute = values[1]
this.devicemiao = values[2]
if (this.list.hasOwnProperty(key)) {
const array = this.list[key]
const lastIndex = array.length - 1
const lastElement = array[lastIndex]
const lastElements = array[lastIndex]
array[lastIndex] = !lastElement
if (lastElements) {
this.deviceflag = 0
} else {
this.deviceflag = 1
}
}
let cucun = '11num' + this.deviceindex + '@' + this.devicehour + '@' + this.deviceminute + '@' + this.devicemiao + '@' + this.deviceflag + '@'
uni.getNetworkType({
success(res) {
if (res.networkType !== 'none') {
uni.getConnectedBluetoothDevices({
success(res) {
xBlufi.notifySendCustomData({
customData: cucun
})
},
fail(err) {
console.error('获取已连接蓝牙设备信息失败:',err)
}
})
} else {
console.log('手机未连接网络')
}
}
})
setTimeout(()=>{
this.kgflag = false
},1000)
},
//
btnitem(key,index,values){
this.deviceindex = index
this.timeflag = true
this.hour = values[0]
this.minutekq = values[1]
const totalSeconds = values[2]
const minutes = Math.floor(totalSeconds / 60)
const seconds = totalSeconds % 60
const formattedMinutes = minutes < 10 ? '0' + minutes : minutes.toString()
const formattedSeconds = seconds < 10 ? '0' + seconds : seconds.toString()
this.minute = formattedMinutes
this.second = formattedSeconds
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
}
}
},
formattedTime(minutes, seconds) { formattedTime(minutes, seconds) {
// //
const formattedMinutes = String(minutes).padStart(2, '0'); const formattedMinutes = String(minutes).padStart(2, '0');
@ -134,29 +237,164 @@
const remainingSeconds = seconds % 60; const remainingSeconds = seconds % 60;
return `${minutes}${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`; return `${minutes}${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`;
}, },
//
btnitem(){
this.timeflag = true
},
// //
btnqx(){ btnqx(){
this.timeflag = false this.timeflag = false
this.hour = '--'
this.minutekq = '--'
this.minute = '--'
this.second = '--'
}, },
// //
btnqd(){ btnqd(){
this.timeflag = false this.timeflag = false
this.hour = '--'
this.minutekq = '--'
this.minute = '--'
this.second = '--'
let cucun = '11num' + this.deviceindex + '@' + this.devicehour + '@' + this.deviceminute + '@' + this.devicemiao + '@' + this.deviceflag + '@'
uni.getNetworkType({
success(res) {
if (res.networkType !== 'none') {
uni.getConnectedBluetoothDevices({
success(res) {
xBlufi.notifySendCustomData({
customData: cucun
})
setTimeout(()=> {
xBlufi.notifySendCustomData({
customData: "11get"
})
},1000)
},
fail(err) {
console.error('获取已连接蓝牙设备信息失败:',err)
}
})
} else {
console.log('手机未连接网络')
}
}
})
}, },
// //
confirm(e){ confirm(e){
this.hour = e.hour this.hour = e.hour
this.minutekq = e.minute this.minutekq = e.minute
this.devicehour = e.hour
this.deviceminute = e.minute
}, },
// //
confirms(e){ confirms(e){
this.minute = e.minute this.minute = e.minute
this.second = e.second this.second = e.second
} this.devicemiao = Number(this.minute) * 60 + Number(this.second)
console.log(this.devicemiao);
},
funListenDeviceMsgEvent: function(options) {
switch (options.type) {
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
if (!options.result) {
uni.showModal({
title: '很抱歉提醒你!',
content: '小程序与设备异常断开',
showCancel: false,
//
success: function(res) {
uni.hideLoading()
uni.removeStorage({key:'device_key'})
}
})
}
break;
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
console.log("1收到设备发来的自定义数据结果", options.data)
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.list = pSetObjects //
const ver_Data = this.list
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}`
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;
}
}
}
break
}
},
} }
} }

View File

@ -57,13 +57,13 @@
</image> 手动浇水 </image> 手动浇水
</view> </view>
<view class="shengyu"> <view class="shengyu">
剩余5分钟 剩余{{ sdminutes ? sdminutes + ':' : '' }}{{ sdseconds ? sdseconds : '--' }}
</view> </view>
</view> </view>
</view> </view>
<view class="deviceweek"> <view class="deviceweek">
<view class="weeklist"> <view class="weeklist">
<view class="kg" v-if="ver_data.p_set5[3] == 1"> <view class="kg" v-if="ver_data.p_set0[3] == 0">
OFF OFF
</view> </view>
<view class="kg" style="color: #48893B;" v-else> <view class="kg" style="color: #48893B;" v-else>
@ -78,7 +78,7 @@
</view> </view>
</view> </view>
<view class="weeklist"> <view class="weeklist">
<view class="kg" v-if="ver_data.p_set4[3] == 1"> <view class="kg" v-if="ver_data.p_set1[3] == 0">
OFF OFF
</view> </view>
<view class="kg" style="color: #48893B;" v-else> <view class="kg" style="color: #48893B;" v-else>
@ -93,7 +93,7 @@
</view> </view>
</view> </view>
<view class="weeklist"> <view class="weeklist">
<view class="kg" v-if="ver_data.p_set3[3] == 1"> <view class="kg" v-if="ver_data.p_set2[3] == 0">
OFF OFF
</view> </view>
<view class="kg" style="color: #48893B;" v-else> <view class="kg" style="color: #48893B;" v-else>
@ -108,7 +108,7 @@
</view> </view>
</view> </view>
<view class="weeklist"> <view class="weeklist">
<view class="kg" v-if="ver_data.p_set2[3] == 1"> <view class="kg" v-if="ver_data.p_set3[3] == 0">
OFF OFF
</view> </view>
<view class="kg" style="color: #48893B;" v-else> <view class="kg" style="color: #48893B;" v-else>
@ -123,7 +123,7 @@
</view> </view>
</view> </view>
<view class="weeklist"> <view class="weeklist">
<view class="kg" v-if="ver_data.p_set1[3] == 1"> <view class="kg" v-if="ver_data.p_set4[3] == 0">
OFF OFF
</view> </view>
<view class="kg" style="color: #48893B;" v-else> <view class="kg" style="color: #48893B;" v-else>
@ -138,7 +138,7 @@
</view> </view>
</view> </view>
<view class="weeklist"> <view class="weeklist">
<view class="kg" v-if="ver_data.p_set0[3] == 1"> <view class="kg" v-if="ver_data.p_set5[3] == 0">
OFF OFF
</view> </view>
<view class="kg" style="color: #48893B;" v-else> <view class="kg" style="color: #48893B;" v-else>
@ -225,7 +225,7 @@
<view class="toptit"> <view class="toptit">
选择浇水时长 选择浇水时长
</view> </view>
<view class="container" @click="showjs = true"> <view class="container" @click="btnshowjs">
<view class="">{{minute}}</view> <view class="">{{minute}}</view>
<text>:</text> <text>:</text>
<view class="">{{second}}</view> <view class="">{{second}}</view>
@ -250,19 +250,15 @@
<script> <script>
var xBlufi = require("@/components/blufi/xBlufi.js") var xBlufi = require("@/components/blufi/xBlufi.js")
import TimePicker from '@/components/TimePicker/index.vue'
export default { export default {
components: {
TimePicker
},
data() { data() {
return { return {
one:false, one:false,
ones:true, ones:true,
two:false, two:false,
twos:true, twos:true,
yschecked: '', yschecked: true,
etchecked: '', etchecked:true,
kgflag: false, kgflag: false,
activeshu: 0, activeshu: 0,
xuanzeflag: false, xuanzeflag: false,
@ -291,7 +287,9 @@
xctime:'--', xctime:'--',
sctimejs:'--', sctimejs:'--',
xctimesc:'--', xctimesc:'--',
xctimesj:'' xctimesj:'',
sdminutes:'',
sdseconds:''
} }
}, },
// //
@ -332,11 +330,15 @@
}, },
onShow() { onShow() {
this.getinfo() this.getinfo()
}, this.getshuju()
mounted() {
}, },
methods: { methods: {
//
btnshowjs(){
this.showjs = true
},
formattedTime(minutes, seconds) { formattedTime(minutes, seconds) {
// //
const formattedMinutes = String(minutes).padStart(2, '0'); const formattedMinutes = String(minutes).padStart(2, '0');
@ -379,74 +381,7 @@
} }
}) })
}, },
//
kq(){
uni.getNetworkType({
success(res) {
if (res.networkType !== 'none') {
uni.getConnectedBluetoothDevices({
success(res) {
setTimeout(()=> {
xBlufi.notifySendCustomData({
customData:'11open'
})
},1500)
},
fail(err) {
console.error('获取已连接蓝牙设备信息失败:',err)
}
})
} else {
console.log('手机未连接网络')
}
}
})
},
gb(){
uni.getNetworkType({
success(res) {
if (res.networkType !== 'none') {
uni.getConnectedBluetoothDevices({
success(res) {
setTimeout(()=> {
xBlufi.notifySendCustomData({
customData:'11close'
})
},1500)
},
fail(err) {
console.error('获取已连接蓝牙设备信息失败:',err)
}
})
} else {
console.log('手机未连接网络')
}
}
})
},
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
uni.getNetworkType({ uni.getNetworkType({
@ -471,6 +406,7 @@
} }
}) })
}, },
//
btnyushuis(){ btnyushuis(){
let that = this let that = this
uni.getNetworkType({ uni.getNetworkType({
@ -495,7 +431,7 @@
} }
}) })
}, },
// //
btnertong(){ btnertong(){
let that = this let that = this
uni.getNetworkType({ uni.getNetworkType({
@ -520,6 +456,7 @@
} }
}) })
}, },
//
btnertongs(){ btnertongs(){
let that = this let that = this
uni.getNetworkType({ uni.getNetworkType({
@ -570,6 +507,7 @@
btnqx(){ btnqx(){
this.sdjsflag = false this.sdjsflag = false
}, },
//
btnqd(){ btnqd(){
if(this.minute == '--' || this.second == '--'){ if(this.minute == '--' || this.second == '--'){
uni.showToast({ uni.showToast({
@ -588,6 +526,7 @@
xBlufi.notifySendCustomData({ xBlufi.notifySendCustomData({
customData: "11time@" + that.jstime + '@' customData: "11time@" + that.jstime + '@'
}) })
that.startTimer(that.jstime)
that.sdjsflag = false that.sdjsflag = false
that.kgflag = true that.kgflag = true
},1500) },1500)
@ -603,8 +542,32 @@
}) })
} }
}, },
//
startTimer(totalSeconds) {
let remainingSeconds = totalSeconds
console.log(remainingSeconds,'000');
const timer = setInterval(() => {
//
const minutes = Math.floor(remainingSeconds / 60).toString()
const secs = (remainingSeconds % 60).toString()
//
this.sdseconds = secs.padStart(2, '0')
// 0
this.sdminutes = minutes.padStart(2, '0')
//
remainingSeconds--;
// 0
if (remainingSeconds <= 0) {
clearInterval(timer)
this.btnkq()
this.sdminutes = ''
this.sdseconds = ''
}
}, 1000)
},
// //
btnkq() { btnkq() {
let that = this let that = this
uni.getNetworkType({ uni.getNetworkType({
@ -681,7 +644,7 @@
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS: case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
if (options.result) { if (options.result) {
let devicesarr = options.data let devicesarr = options.data
console.log(devicesarr,'111') // console.log(devicesarr,'111')
devicesarr.forEach(device => { devicesarr.forEach(device => {
const mac = device.name.substring(4) const mac = device.name.substring(4)
if (device.name.slice(5, 17) == this.mac) { if (device.name.slice(5, 17) == this.mac) {
@ -740,10 +703,12 @@
showObject.showArray = value.split(',').map(Number); showObject.showArray = value.split(',').map(Number);
} else if (key.startsWith('p_set')) { } else if (key.startsWith('p_set')) {
const numbers = value.split(',').map(Number); const numbers = value.split(',').map(Number);
pSetObjects[key] = numbers; pSetObjects[key] = numbers
} }
}) })
this.ver_data = pSetObjects // this.ver_data = pSetObjects //
console.log(this.ver_data,'002002002')
this.showobj = showObject // this.showobj = showObject //
if(this.showobj.showArray[1] == 1){ if(this.showobj.showArray[1] == 1){
this.yschecked = false this.yschecked = false
@ -814,12 +779,13 @@
this.sctimejs = timesc.slice(0,-3) this.sctimejs = timesc.slice(0,-3)
let xcjs = nextTime.toTimeString().split(' ')[0] let xcjs = nextTime.toTimeString().split(' ')[0]
this.xctimesj = xcjs.slice(0,-3) this.xctimesj = xcjs.slice(0,-3)
console.log(xcjs,'121212',this.formattedTime(this.ver_data.p_set5[0],this.ver_data.p_set5[1]))
// console.log(':', nextTimeDiff ? `${nextTimeDiff.hours}${nextTimeDiff.minutes}` : ''); // console.log(':', nextTimeDiff ? `${nextTimeDiff.hours}${nextTimeDiff.minutes}` : '');
// console.log(':', nextTime ? nextTime.toTimeString().split(' ')[0] : ''); // console.log(':', nextTime ? nextTime.toTimeString().split(' ')[0] : '');
// console.log(':', nextWaterDuration || ''); // console.log(':', nextWaterDuration || '');
// console.log(':', prevTimeDiff ? `${prevTimeDiff.hours}${prevTimeDiff.minutes}` : ''); // console.log(':', prevTimeDiff ? `${prevTimeDiff.hours}${prevTimeDiff.minutes}` : '');
// console.log(':', prevTime ? prevTime.toTimeString().split(' ')[0] : '') // console.log(':', prevTime ? prevTime.toTimeString().split(' ')[0] : '')
break break
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP: case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
@ -843,8 +809,30 @@
} }
}, },
//
getshuju(){
const intervalId = setInterval(() => {
uni.getNetworkType({
success(res) {
if (res.networkType !== 'none') {
uni.getConnectedBluetoothDevices({
success(res) {
setTimeout(()=> {
xBlufi.notifySendCustomData({
customData: "11get"
})
},1000)
},
fail(err) {
console.error('获取已连接蓝牙设备信息失败:',err)
}
})
}
}
})
console.log("定时器每分钟执行一次");
}, 60000)
}
} }
} }