浇花器
This commit is contained in:
parent
08a9c27934
commit
f9341f88ee
|
@ -3,6 +3,10 @@
|
||||||
<u-navbar :is-back="true" title='定时管理' title-color="#000" :border-bottom="false" :background="bgc" id="navbar">
|
<u-navbar :is-back="true" title='定时管理' title-color="#000" :border-bottom="false" :background="bgc" 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>
|
||||||
|
|
||||||
|
<!-- 加载提示 -->
|
||||||
|
<u-loading-page :loading="isLoading" loading-text="数据同步中..."></u-loading-page>
|
||||||
|
|
||||||
<view class="" v-if="pre == 'WATER'">
|
<view class="" v-if="pre == 'WATER'">
|
||||||
<view class="list" v-if="list.length > 0 || list != null">
|
<view class="list" v-if="list.length > 0 || list != null">
|
||||||
<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">
|
||||||
|
@ -33,7 +37,7 @@
|
||||||
</view>
|
</view>
|
||||||
<view class="shifen" @click="shows = true">
|
<view class="shifen" @click="shows = true">
|
||||||
<text>{{minute}}分</text> <text>{{second}}秒</text>
|
<text>{{minute}}分</text> <text>{{second}}秒</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="anniu">
|
<view class="anniu">
|
||||||
<view class="qx" @click="btnqx">
|
<view class="qx" @click="btnqx">
|
||||||
取消
|
取消
|
||||||
|
@ -45,9 +49,9 @@
|
||||||
</view>
|
</view>
|
||||||
<view class="mask" v-if="timeflag"></view>
|
<view class="mask" v-if="timeflag"></view>
|
||||||
<!-- 定时时间 -->
|
<!-- 定时时间 -->
|
||||||
<u-picker v-model="show" mode="time" :params="paramss" @confirm="confirm"></u-picker>
|
<u-picker v-model="show" mode="time" :params="paramss" :defaultTime="defaultTime" @confirm="confirm"></u-picker>
|
||||||
<!-- 定时时长 -->
|
<!-- 定时时长 -->
|
||||||
<u-picker v-model="shows" mode="time" :params="params" @confirm="confirms"></u-picker>
|
<u-picker v-model="shows" mode="time" :params="params" :defaultTime="defaultTimeLength" @confirm="confirms"></u-picker>
|
||||||
|
|
||||||
<view class="mask" style="z-index: 9999;" v-if="kgflag"></view>
|
<view class="mask" style="z-index: 9999;" v-if="kgflag"></view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -124,7 +128,20 @@
|
||||||
shi:'',
|
shi:'',
|
||||||
fen:'',
|
fen:'',
|
||||||
miao:'',
|
miao:'',
|
||||||
tian:''
|
tian: '',
|
||||||
|
isLoading: false, // 加载状态
|
||||||
|
retryCount: 0, // 重试次数
|
||||||
|
maxRetries: 3, // 最大重试次数
|
||||||
|
lastOperation: null, // 最后一次操作
|
||||||
|
// 添加默认时间设置
|
||||||
|
defaultTime: {
|
||||||
|
hour: '00',
|
||||||
|
minute: '00'
|
||||||
|
},
|
||||||
|
defaultTimeLength: {
|
||||||
|
minute: '00',
|
||||||
|
second: '00'
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 分享到好友(会话)
|
// 分享到好友(会话)
|
||||||
|
@ -181,35 +198,83 @@
|
||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 点击开关是否开启
|
// 显示加载
|
||||||
btnchange(key, index, values) {
|
showLoading() {
|
||||||
this.kgflag = true
|
this.isLoading = true;
|
||||||
this.btnitem(key, index, values)
|
},
|
||||||
this.btnqx()
|
|
||||||
this.deviceindex = index
|
// 隐藏加载
|
||||||
this.devicehour = values[0]
|
hideLoading() {
|
||||||
this.deviceminute = values[1]
|
this.isLoading = false;
|
||||||
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 + '@'
|
|
||||||
xBlufi.notifySendCustomData({
|
|
||||||
customData: cucun
|
|
||||||
})
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.kgflag = false
|
this.isLoading = false;
|
||||||
}, 1000)
|
}, 500);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 重试机制
|
||||||
|
async retryOperation() {
|
||||||
|
if (this.retryCount < this.maxRetries) {
|
||||||
|
this.retryCount++;
|
||||||
|
await this.delay(1000);
|
||||||
|
if (this.lastOperation) {
|
||||||
|
this.lastOperation();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.hideLoading();
|
||||||
|
uni.showToast({
|
||||||
|
title: '操作失败,请重试',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
this.retryCount = 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 延时函数
|
||||||
|
delay(ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
},
|
||||||
|
|
||||||
|
// 点击开关是否开启
|
||||||
|
async btnchange(key, index, values) {
|
||||||
|
try {
|
||||||
|
this.showLoading();
|
||||||
|
this.kgflag = true;
|
||||||
|
this.btnitem(key, index, values);
|
||||||
|
this.btnqx();
|
||||||
|
this.deviceindex = index;
|
||||||
|
this.devicehour = values[0] || 0; // 添加默认值
|
||||||
|
this.deviceminute = values[1] || 0;
|
||||||
|
this.devicemiao = values[2] || 0;
|
||||||
|
|
||||||
|
if (this.list.hasOwnProperty(key)) {
|
||||||
|
const array = this.list[key];
|
||||||
|
const lastIndex = array.length - 1;
|
||||||
|
const lastElement = array[lastIndex];
|
||||||
|
array[lastIndex] = !lastElement;
|
||||||
|
this.deviceflag = lastElement ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let cucun = '11num' + this.deviceindex + '@' + this.devicehour + '@' + this.deviceminute + '@' + this.devicemiao + '@' + this.deviceflag + '@';
|
||||||
|
this.lastOperation = () => {
|
||||||
|
xBlufi.notifySendCustomData({
|
||||||
|
customData: cucun
|
||||||
|
});
|
||||||
|
};
|
||||||
|
this.lastOperation();
|
||||||
|
|
||||||
|
await this.delay(1000);
|
||||||
|
xBlufi.notifySendCustomData({
|
||||||
|
customData: "11get"
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.kgflag = false;
|
||||||
|
this.hideLoading();
|
||||||
|
}, 2000);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('btnchange error:', error);
|
||||||
|
this.retryOperation();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 点击设置定时时间
|
// 点击设置定时时间
|
||||||
|
@ -259,65 +324,96 @@
|
||||||
this.second = '--'
|
this.second = '--'
|
||||||
},
|
},
|
||||||
// 确定选择设置定时时间
|
// 确定选择设置定时时间
|
||||||
btnqd() {
|
async btnqd() {
|
||||||
this.timeflag = false
|
try {
|
||||||
this.hour = '--'
|
this.showLoading();
|
||||||
this.minutekq = '--'
|
this.timeflag = false;
|
||||||
this.minute = '--'
|
this.hour = '--';
|
||||||
this.second = '--'
|
this.minutekq = '--';
|
||||||
let cucun = '11num' + this.deviceindex + '@' + this.devicehour + '@' + this.deviceminute + '@' + this.devicemiao + '@' + this.deviceflag + '@'
|
this.minute = '--';
|
||||||
xBlufi.notifySendCustomData({
|
this.second = '--';
|
||||||
customData: cucun
|
|
||||||
})
|
let cucun = '11num' + this.deviceindex + '@' + this.devicehour + '@' + this.deviceminute + '@' + this.devicemiao + '@' + this.deviceflag + '@';
|
||||||
setTimeout(() => {
|
this.lastOperation = () => {
|
||||||
|
xBlufi.notifySendCustomData({
|
||||||
|
customData: cucun
|
||||||
|
});
|
||||||
|
};
|
||||||
|
this.lastOperation();
|
||||||
|
|
||||||
|
await this.delay(1000);
|
||||||
xBlufi.notifySendCustomData({
|
xBlufi.notifySendCustomData({
|
||||||
customData: "11get"
|
customData: "11get"
|
||||||
})
|
});
|
||||||
}, 1000)
|
|
||||||
},
|
|
||||||
btnbc(){
|
|
||||||
if(this.shi >= 24){
|
|
||||||
uni.showToast({
|
|
||||||
title: '最大值为23时',
|
|
||||||
icon: 'none',
|
|
||||||
duration:2000
|
|
||||||
})
|
|
||||||
}else if(this.fen >= 60){
|
|
||||||
uni.showToast({
|
|
||||||
title: '最大值为59分钟',
|
|
||||||
icon: 'none',
|
|
||||||
duration:2000
|
|
||||||
})
|
|
||||||
}else{
|
|
||||||
this.timeflag = false
|
|
||||||
let cucun = '11num0' + '@' + this.shi + '@' + this.fen + '@' + this.miao + '@' + this.tian + '@'
|
|
||||||
xBlufi.notifySendCustomData({
|
|
||||||
customData: cucun
|
|
||||||
})
|
|
||||||
uni.showToast({
|
|
||||||
title: '保存成功',
|
|
||||||
icon: 'success',
|
|
||||||
duration:2000
|
|
||||||
})
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
this.hideLoading();
|
||||||
|
}, 2000);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('btnqd error:', error);
|
||||||
|
this.retryOperation();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 保存抽水泵设置
|
||||||
|
async btnbc() {
|
||||||
|
try {
|
||||||
|
if(this.shi >= 24){
|
||||||
|
uni.showToast({
|
||||||
|
title: '最大值为23时',
|
||||||
|
icon: 'none',
|
||||||
|
duration:2000
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
} else if(this.fen >= 60){
|
||||||
|
uni.showToast({
|
||||||
|
title: '最大值为59分钟',
|
||||||
|
icon: 'none',
|
||||||
|
duration:2000
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.showLoading();
|
||||||
|
this.timeflag = false;
|
||||||
|
let cucun = '11num0' + '@' + this.shi + '@' + this.fen + '@' + this.miao + '@' + this.tian + '@';
|
||||||
|
this.lastOperation = () => {
|
||||||
xBlufi.notifySendCustomData({
|
xBlufi.notifySendCustomData({
|
||||||
customData: "11get"
|
customData: cucun
|
||||||
})
|
});
|
||||||
}, 1000)
|
};
|
||||||
|
this.lastOperation();
|
||||||
|
|
||||||
|
await this.delay(1000);
|
||||||
|
xBlufi.notifySendCustomData({
|
||||||
|
customData: "11get"
|
||||||
|
});
|
||||||
|
|
||||||
|
uni.showToast({
|
||||||
|
title: '保存成功',
|
||||||
|
icon: 'success',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.hideLoading();
|
||||||
|
}, 2000);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('btnbc error:', error);
|
||||||
|
this.retryOperation();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 定时浇水时间
|
// 定时浇水时间
|
||||||
confirm(e) {
|
confirm(e) {
|
||||||
this.hour = e.hour
|
this.hour = e.hour || '00'
|
||||||
this.minutekq = e.minute
|
this.minutekq = e.minute || '00'
|
||||||
this.devicehour = e.hour
|
this.devicehour = e.hour || '00'
|
||||||
this.deviceminute = e.minute
|
this.deviceminute = e.minute || '00'
|
||||||
},
|
},
|
||||||
// 定时浇水时长
|
// 定时浇水时长
|
||||||
confirms(e) {
|
confirms(e) {
|
||||||
this.minute = e.minute
|
this.minute = e.minute || '00'
|
||||||
this.second = e.second
|
this.second = e.second || '00'
|
||||||
this.devicemiao = Number(this.minute) * 60 + Number(this.second)
|
this.devicemiao = (Number(this.minute) * 60 + Number(this.second)) || 0
|
||||||
console.log(this.devicemiao)
|
console.log(this.devicemiao)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -325,117 +421,71 @@
|
||||||
switch (options.type) {
|
switch (options.type) {
|
||||||
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
|
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
|
||||||
if (!options.result) {
|
if (!options.result) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '蓝牙连接异常',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
|
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
|
||||||
console.log("1收到设备发来的自定义数据结果:", options.data)
|
try {
|
||||||
const inputString = options.data.slice(0, -1) + ";"
|
console.log("收到设备发来的自定义数据结果:", options.data);
|
||||||
console.log(inputString, '12121212100')
|
const inputString = options.data.slice(0, -1) + ";";
|
||||||
if (this.pre == 'WATER') {
|
|
||||||
const pairs = inputString.split(';')
|
if (this.pre == 'WATER') {
|
||||||
const showObject = {}
|
const pairs = inputString.split(';');
|
||||||
const pSetObjects = {}
|
const pSetObjects = {};
|
||||||
pairs.forEach(pair => {
|
|
||||||
const [key, value] = pair.split(':')
|
pairs.forEach(pair => {
|
||||||
if (key === 'show') {
|
if (!pair) return;
|
||||||
showObject.showArray = value.split(',').map(Number)
|
const [key, value] = pair.split(':');
|
||||||
} else if (key.startsWith('p_set')) {
|
if (key && key.startsWith('p_set') && value) {
|
||||||
const numbers = value.split(',').map(Number)
|
try {
|
||||||
pSetObjects[key] = numbers
|
const numbers = value.split(',').map(num => {
|
||||||
}
|
const parsed = parseInt(num);
|
||||||
})
|
return isNaN(parsed) ? 0 : parsed;
|
||||||
this.list = pSetObjects //六个浇水时间段
|
});
|
||||||
|
pSetObjects[key] = numbers;
|
||||||
const ver_Data = this.list
|
} catch (e) {
|
||||||
|
console.error('数据解析错误:', e);
|
||||||
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) // 注意这里要反过来算
|
if (Object.keys(pSetObjects).length > 0) {
|
||||||
prevTime = timeDate
|
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) + ";"
|
||||||
this.xctime = `${nextTimeDiff.hours}时${nextTimeDiff.minutes}分`
|
// 去除末尾的分号并分割字符串
|
||||||
for (let key in this.list) {
|
const parts = input.replace(";", "").split(":")
|
||||||
if (this.list.hasOwnProperty(key)) {
|
// 获取时间部分并分割
|
||||||
// 获取当前数组
|
const timeParts = parts[1].split(",")
|
||||||
let arr = this.list[key]
|
// 解析为对象
|
||||||
// 判断数组的最后一个元素,并进行替换
|
this.csbobj = {
|
||||||
if (arr[arr.length - 1] === 0) {
|
hour: parseInt(timeParts[0]), // 小时
|
||||||
arr[arr.length - 1] = false
|
minute: parseInt(timeParts[1]), // 分钟
|
||||||
} else if (arr[arr.length - 1] === 1) {
|
second: parseInt(timeParts[2]), // 秒
|
||||||
arr[arr.length - 1] = true
|
day: parseInt(timeParts[3]) // 天数
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
console.log(this.csbobj);
|
||||||
|
this.shi = this.csbobj.hour
|
||||||
|
this.fen = this.csbobj.minute
|
||||||
|
this.miao = this.csbobj.second
|
||||||
|
this.tian = this.csbobj.day
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const input = options.data.slice(0, -1) + ";"
|
this.hideLoading();
|
||||||
// 去除末尾的分号并分割字符串
|
} catch (error) {
|
||||||
const parts = input.replace(";", "").split(":")
|
console.error('数据处理错误:', error);
|
||||||
// 获取时间部分并分割
|
this.retryOperation();
|
||||||
const timeParts = parts[1].split(",")
|
|
||||||
// 解析为对象
|
|
||||||
this.csbobj = {
|
|
||||||
hour: parseInt(timeParts[0]), // 小时
|
|
||||||
minute: parseInt(timeParts[1]), // 分钟
|
|
||||||
second: parseInt(timeParts[2]), // 秒
|
|
||||||
day: parseInt(timeParts[3]) // 天数
|
|
||||||
}
|
|
||||||
console.log(this.csbobj);
|
|
||||||
this.shi = this.csbobj.hour
|
|
||||||
this.fen = this.csbobj.minute
|
|
||||||
this.miao = this.csbobj.second
|
|
||||||
this.tian = this.csbobj.day
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,12 @@
|
||||||
MAC:{{item.mac == undefined ? item.name.slice(-12) : item.mac}}
|
MAC:{{item.mac == undefined ? item.name.slice(-12) : item.mac}}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="add" @click="btnadd(item)" v-if="item.userId == undefined">
|
<view class="add" style="color: #ccc;border: 1px solid #ccc;" v-if="item.userId">
|
||||||
添加
|
|
||||||
</view>
|
|
||||||
<view class="add" style="color: #ccc;border: 1px solid #ccc;" v-else>
|
|
||||||
已添加
|
已添加
|
||||||
</view>
|
</view>
|
||||||
|
<view class="add" @click="btnadd(item)" v-else>
|
||||||
|
添加
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -56,6 +56,18 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 自定义名称弹框 -->
|
||||||
|
<u-popup v-model="showNameDialog" mode="center" border-radius="14" width="600rpx">
|
||||||
|
<view class="custom-name-dialog">
|
||||||
|
<view class="dialog-title">设备名称</view>
|
||||||
|
<u-input v-model="customDeviceName" placeholder="请输入设备名称" />
|
||||||
|
<view class="dialog-btns">
|
||||||
|
<view class="btn cancel" @click="showNameDialog = false">取消</view>
|
||||||
|
<view class="btn confirm" @click="confirmAddDevice">确定</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</u-popup>
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -77,7 +89,10 @@
|
||||||
userid: '',
|
userid: '',
|
||||||
arr: '',
|
arr: '',
|
||||||
jiaohuaqi: [],
|
jiaohuaqi: [],
|
||||||
getpre:[]
|
getpre: [],
|
||||||
|
showNameDialog: false,
|
||||||
|
customDeviceName: '',
|
||||||
|
currentDevice: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 分享到好友(会话)
|
// 分享到好友(会话)
|
||||||
|
@ -124,19 +139,34 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
// 点击添加添加绑定设备
|
|
||||||
|
// 点击添加按钮
|
||||||
btnadd(e) {
|
btnadd(e) {
|
||||||
console.log(e, '0101');
|
this.currentDevice = e;
|
||||||
let mac = e.slice(-12)
|
this.customDeviceName = e.modelName || '未知设备'; // 默认使用型号名称
|
||||||
|
this.showNameDialog = true;
|
||||||
|
},
|
||||||
|
// 确认添加设备
|
||||||
|
confirmAddDevice() {
|
||||||
|
if (!this.customDeviceName.trim()) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请输入设备名称',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mac = this.currentDevice.name.slice(-12);
|
||||||
let data = {
|
let data = {
|
||||||
mac: mac,
|
mac: mac,
|
||||||
userId: this.userid,
|
userId: this.userid,
|
||||||
pre: e.slice(0, 5)
|
pre: this.currentDevice.pre,
|
||||||
|
deviceName: this.customDeviceName
|
||||||
}
|
}
|
||||||
console.log(data);
|
|
||||||
this.$u.post(`/app/bandDevice`, data).then((res) => {
|
this.$u.post(`/app/bandDevice`, data).then((res) => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
|
@ -144,6 +174,7 @@
|
||||||
icon: 'success',
|
icon: 'success',
|
||||||
duration: 3000
|
duration: 3000
|
||||||
})
|
})
|
||||||
|
this.showNameDialog = false;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.navigateBack()
|
uni.navigateBack()
|
||||||
}, 2000)
|
}, 2000)
|
||||||
|
@ -156,75 +187,73 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getmodel() {
|
getmodel() {
|
||||||
this.$u.get(`/app/getAllModelList`).then(res => {
|
this.$u.get(`/app/getAllModelList`).then(res => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
this.getpre = res.data;
|
this.getpre = res.data
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getpipei(pre) {
|
getpipei(pre) {
|
||||||
// 添加默认返回值防止undefined
|
// 添加默认返回值防止undefined
|
||||||
return this.getpre.find(item => item.pre == pre) || {
|
return this.getpre.find(item => item.pre == pre) || {
|
||||||
modelName: '未知型号',
|
modelName: '未知型号',
|
||||||
picture: ''
|
picture: ''
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
btnss() {
|
btnss() {
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: '搜索中...',
|
title: '搜索中...',
|
||||||
mask: true
|
mask: true
|
||||||
});
|
});
|
||||||
|
this.jiaohuaqi = [];
|
||||||
this.jiaohuaqi = [];
|
this.flag = false;
|
||||||
this.flag = false;
|
const that = this;
|
||||||
const that = this;
|
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent);
|
||||||
|
xBlufi.notifyStartDiscoverBle({ 'isStart': true });
|
||||||
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent);
|
setTimeout(() => {
|
||||||
xBlufi.notifyStartDiscoverBle({ 'isStart': true });
|
xBlufi.notifyStartDiscoverBle({ 'isStart': false });
|
||||||
|
if (that.devicesList.length > 0) {
|
||||||
setTimeout(() => {
|
const data = { mac: that.arr };
|
||||||
xBlufi.notifyStartDiscoverBle({ 'isStart': false });
|
that.$u.post(`/app/getExistListByMacs`, data)
|
||||||
|
.then(res => {
|
||||||
if (that.devicesList.length > 0) {
|
if (res.code === 200) {
|
||||||
const data = { mac: that.arr };
|
// 创建MAC地址映射表
|
||||||
|
const updatedDevicesList = that.devicesList.map(item => {
|
||||||
this.$u.post(`/app/getExistListByMacs`, data).then(res => {
|
const matchedData = res.data.find(val => item.name.slice(-12) === val.mac);
|
||||||
if (res.code == 200) {
|
return matchedData ? { ...item, ...matchedData } : item;
|
||||||
// 创建MAC地址映射表
|
});
|
||||||
const macMap = new Map(res.data.map(item => [item.mac, item]));
|
updatedDevicesList.forEach(val => {
|
||||||
|
const mac = val.name.slice(-12);
|
||||||
that.devicesList.forEach(val => {
|
const pre = val.name.slice(0, 5);
|
||||||
const mac = val.name.slice(-12);
|
const matched = that.getpipei(pre);
|
||||||
if (macMap.has(mac)) {
|
const userid = val.userId || null;
|
||||||
that.jiaohuaqi.push(macMap.get(mac));
|
that.jiaohuaqi.push({
|
||||||
console.log(that.jiaohuaqi,'1111');
|
name: mac,
|
||||||
} else {
|
modelName: matched.modelName,
|
||||||
const pre = val.name.slice(0, 5);
|
modelPicture: matched.picture,
|
||||||
const matched = that.getpipei(pre);
|
pre: pre,
|
||||||
that.jiaohuaqi.push({
|
userId: userid
|
||||||
name: mac,
|
});
|
||||||
modelName: matched.modelName,
|
console.log(that.jiaohuaqi, '2222');
|
||||||
modelPicture: matched.picture
|
});
|
||||||
});
|
}
|
||||||
console.log(that.jiaohuaqi,'2222');
|
})
|
||||||
}
|
.catch(error => {
|
||||||
});
|
console.error('请求失败:', error);
|
||||||
|
})
|
||||||
uni.hideLoading();
|
.finally(() => {
|
||||||
} else {
|
uni.hideLoading();
|
||||||
uni.hideLoading();
|
that.flag = true;
|
||||||
}
|
});
|
||||||
});
|
} else {
|
||||||
} else {
|
uni.hideLoading();
|
||||||
uni.hideLoading();
|
that.flag = true;
|
||||||
}
|
}
|
||||||
|
}, 3000);
|
||||||
that.flag = true;
|
},
|
||||||
}, 3000);
|
|
||||||
},
|
|
||||||
|
|
||||||
// 获取附近蓝牙设备列表
|
// 获取附近蓝牙设备列表
|
||||||
funListenDeviceMsgEvent: function(options) {
|
funListenDeviceMsgEvent: function(options) {
|
||||||
|
@ -281,6 +310,12 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
|
/deep/ .u-input__input{
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
padding-left: 10rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
/deep/ .u-title {
|
/deep/ .u-title {
|
||||||
margin-bottom: 22rpx;
|
margin-bottom: 22rpx;
|
||||||
}
|
}
|
||||||
|
@ -414,4 +449,41 @@
|
||||||
padding-left: 48rpx;
|
padding-left: 48rpx;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.custom-name-dialog {
|
||||||
|
background: #fff;
|
||||||
|
padding: 40rpx;
|
||||||
|
|
||||||
|
.dialog-title {
|
||||||
|
font-size: 32rpx;
|
||||||
|
color: #333;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-btns {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-top: 40rpx;
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
width: 240rpx;
|
||||||
|
height: 80rpx;
|
||||||
|
line-height: 80rpx;
|
||||||
|
text-align: center;
|
||||||
|
border-radius: 40rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
|
||||||
|
&.cancel {
|
||||||
|
background: #f5f5f5;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.confirm {
|
||||||
|
background: #48893B;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
|
@ -370,7 +370,8 @@
|
||||||
imgflag:true,
|
imgflag:true,
|
||||||
ver:'',
|
ver:'',
|
||||||
pre:'',
|
pre:'',
|
||||||
csbobj:{}
|
csbobj:{},
|
||||||
|
disconnectTimer: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 分享到好友(会话)
|
// 分享到好友(会话)
|
||||||
|
@ -423,10 +424,12 @@
|
||||||
onHide() {
|
onHide() {
|
||||||
// 页面隐藏时清除定时器
|
// 页面隐藏时清除定时器
|
||||||
this.clearTimer()
|
this.clearTimer()
|
||||||
|
this.clearDisconnectTimer()
|
||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
// 页面卸载时清除定时器
|
// 页面卸载时清除定时器
|
||||||
this.clearTimer()
|
this.clearTimer()
|
||||||
|
this.clearDisconnectTimer()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 点击进行设备录入
|
// 点击进行设备录入
|
||||||
|
@ -560,6 +563,7 @@
|
||||||
|
|
||||||
// 雨水感应开启
|
// 雨水感应开启
|
||||||
btnyushui() {
|
btnyushui() {
|
||||||
|
this.handleUserAction()
|
||||||
this.one = false
|
this.one = false
|
||||||
this.ones = true
|
this.ones = true
|
||||||
if(this.vardataflag != 3){
|
if(this.vardataflag != 3){
|
||||||
|
@ -583,6 +587,7 @@
|
||||||
},
|
},
|
||||||
// 雨水感应关闭
|
// 雨水感应关闭
|
||||||
btnyushuis() {
|
btnyushuis() {
|
||||||
|
this.handleUserAction()
|
||||||
this.one = false
|
this.one = false
|
||||||
this.ones = true
|
this.ones = true
|
||||||
if(this.vardataflag != 3){
|
if(this.vardataflag != 3){
|
||||||
|
@ -606,6 +611,7 @@
|
||||||
},
|
},
|
||||||
// 点击儿童锁开启
|
// 点击儿童锁开启
|
||||||
btnertong() {
|
btnertong() {
|
||||||
|
this.handleUserAction()
|
||||||
this.two = false
|
this.two = false
|
||||||
this.twos = true
|
this.twos = true
|
||||||
if(this.vardataflag != 3){
|
if(this.vardataflag != 3){
|
||||||
|
@ -629,6 +635,7 @@
|
||||||
},
|
},
|
||||||
// 点击儿童锁关闭
|
// 点击儿童锁关闭
|
||||||
btnertongs() {
|
btnertongs() {
|
||||||
|
this.handleUserAction()
|
||||||
this.two = false
|
this.two = false
|
||||||
this.twos = true
|
this.twos = true
|
||||||
if(this.vardataflag != 3){
|
if(this.vardataflag != 3){
|
||||||
|
@ -664,6 +671,7 @@
|
||||||
|
|
||||||
// 点击选择浇水时间
|
// 点击选择浇水时间
|
||||||
confirm(e) {
|
confirm(e) {
|
||||||
|
this.handleUserAction()
|
||||||
this.minute = e.minute
|
this.minute = e.minute
|
||||||
this.second = e.second
|
this.second = e.second
|
||||||
this.jstime = Number(e.second) + Number(e.minute * 60)
|
this.jstime = Number(e.second) + Number(e.minute * 60)
|
||||||
|
@ -671,6 +679,7 @@
|
||||||
|
|
||||||
// 点击跳转到定时页面
|
// 点击跳转到定时页面
|
||||||
btntime() {
|
btntime() {
|
||||||
|
this.handleUserAction()
|
||||||
if(this.vardataflag != 3){
|
if(this.vardataflag != 3){
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '蓝牙未连接',
|
title: '蓝牙未连接',
|
||||||
|
@ -687,6 +696,7 @@
|
||||||
|
|
||||||
// 点击取消手动浇水
|
// 点击取消手动浇水
|
||||||
btnqx() {
|
btnqx() {
|
||||||
|
this.handleUserAction()
|
||||||
this.sdjsflag = false
|
this.sdjsflag = false
|
||||||
this.sdminutes = ''
|
this.sdminutes = ''
|
||||||
this.sdseconds = ''
|
this.sdseconds = ''
|
||||||
|
@ -696,6 +706,7 @@
|
||||||
},
|
},
|
||||||
// 确定选择时间
|
// 确定选择时间
|
||||||
btnqd() {
|
btnqd() {
|
||||||
|
this.handleUserAction()
|
||||||
if (this.minute == '--' || this.second == '--') {
|
if (this.minute == '--' || this.second == '--') {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '请选择浇水时长',
|
title: '请选择浇水时长',
|
||||||
|
@ -743,6 +754,7 @@
|
||||||
|
|
||||||
// 关闭手动浇水
|
// 关闭手动浇水
|
||||||
btnkq() {
|
btnkq() {
|
||||||
|
this.handleUserAction()
|
||||||
console.log('关闭')
|
console.log('关闭')
|
||||||
if(this.vardataflag != 3){
|
if(this.vardataflag != 3){
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
|
@ -770,6 +782,7 @@
|
||||||
},
|
},
|
||||||
// 开启手动浇水
|
// 开启手动浇水
|
||||||
btngb() {
|
btngb() {
|
||||||
|
this.handleUserAction()
|
||||||
console.log('开启')
|
console.log('开启')
|
||||||
if(this.vardataflag != 3){
|
if(this.vardataflag != 3){
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
|
@ -873,6 +886,7 @@
|
||||||
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
|
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
|
||||||
if (!options.result) {
|
if (!options.result) {
|
||||||
this.vardataflag = 1
|
this.vardataflag = 1
|
||||||
|
this.clearDisconnectTimer()
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
|
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
|
||||||
|
@ -885,11 +899,13 @@
|
||||||
if (options.result == true){
|
if (options.result == true){
|
||||||
this.datalist = '1'
|
this.datalist = '1'
|
||||||
this.vardataflag = 3
|
this.vardataflag = 3
|
||||||
|
this.initDisconnectTimer()
|
||||||
xBlufi.notifyInitBleEsp32({
|
xBlufi.notifyInitBleEsp32({
|
||||||
deviceId: this.deviceId
|
deviceId: this.deviceId
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
this.vardataflag = 1
|
this.vardataflag = 1
|
||||||
|
this.clearDisconnectTimer()
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
|
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
|
||||||
|
@ -1085,6 +1101,60 @@
|
||||||
this.xctimesj = nextTime ? nextTime.toTimeString().slice(0, 5) : '无下次浇水时间';
|
this.xctimesj = nextTime ? nextTime.toTimeString().slice(0, 5) : '无下次浇水时间';
|
||||||
console.log('下次浇水时间', this.xctimesj, '距离下次浇水时间', this.xctime, '上次浇水时间', this.sctimejs);
|
console.log('下次浇水时间', this.xctimesj, '距离下次浇水时间', this.xctime, '上次浇水时间', this.sctimejs);
|
||||||
},
|
},
|
||||||
|
// 初始化断开蓝牙定时器
|
||||||
|
initDisconnectTimer() {
|
||||||
|
this.clearDisconnectTimer()
|
||||||
|
this.disconnectTimer = setTimeout(() => {
|
||||||
|
if(this.vardataflag === 3) {
|
||||||
|
console.log('一分钟无操作,断开蓝牙连接')
|
||||||
|
this.disconnectBluetooth()
|
||||||
|
}
|
||||||
|
}, 60000) // 60秒 = 1分钟
|
||||||
|
},
|
||||||
|
|
||||||
|
// 重置断开蓝牙定时器
|
||||||
|
resetDisconnectTimer() {
|
||||||
|
this.initDisconnectTimer()
|
||||||
|
},
|
||||||
|
|
||||||
|
// 清除断开蓝牙定时器
|
||||||
|
clearDisconnectTimer() {
|
||||||
|
if(this.disconnectTimer) {
|
||||||
|
clearTimeout(this.disconnectTimer)
|
||||||
|
this.disconnectTimer = null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 断开蓝牙连接
|
||||||
|
disconnectBluetooth() {
|
||||||
|
if(this.deviceId) {
|
||||||
|
wx.closeBLEConnection({
|
||||||
|
deviceId: this.deviceId,
|
||||||
|
success: () => {
|
||||||
|
console.log('蓝牙连接已断开')
|
||||||
|
this.vardataflag = 1
|
||||||
|
this.datalist = ''
|
||||||
|
uni.showToast({
|
||||||
|
title: '蓝牙已断开连接',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
xBlufi.notifyConnectBle({
|
||||||
|
isStart: false,
|
||||||
|
deviceId: this.deviceId,
|
||||||
|
name: this.name
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 监听用户操作的方法
|
||||||
|
handleUserAction() {
|
||||||
|
if(this.vardataflag === 3) {
|
||||||
|
this.resetDisconnectTimer()
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user