浇花器

This commit is contained in:
3321822538@qq.com 2025-05-19 16:32:27 +08:00
parent 39f3134e6b
commit e4fdabce18

View File

@ -13,7 +13,7 @@
如未找到想添加的设备点击重新搜索 如未找到想添加的设备点击重新搜索
</view> </view>
<view class="list"> <view class="list">
<view class="list_item" v-for="(item,index) in jiaohuaqi" :key="index"> <view class="list_item" v-for="(item,index) in jiaohuaqi" :key="index" :class="{ show: item.show }">
<image :src="item.modelPicture" mode=""></image> <image :src="item.modelPicture" mode=""></image>
<view class="cen"> <view class="cen">
<view class="name" style="color: #ccc;" v-if="item.userId && item.userId != userid"> <view class="name" style="color: #ccc;" v-if="item.userId && item.userId != userid">
@ -51,10 +51,7 @@
</view> </view>
<!-- 点击搜索 --> <!-- 点击搜索 -->
<view class="btnss" @click="btnss" v-if="flag"> <view class="btnss" @click="handleSearch" :class="{ 'searching': !flag }">
重新搜索
</view>
<view class="btnss" v-else>
重新搜索 重新搜索
</view> </view>
</view> </view>
@ -96,6 +93,15 @@
showNameDialog: false, showNameDialog: false,
customDeviceName: '', customDeviceName: '',
currentDevice: null, currentDevice: null,
searchTimer: null,
checkTimer: null,
isSearching: false,
searchTimeout: null,
throttleTimer: null,
lastSearchTime: 0,
searchInterval: 2000, // 2
displayQueue: [], //
processingQueue: false, //
} }
}, },
// //
@ -115,12 +121,17 @@
} }
}, },
onLoad() { onLoad() {
},
onShow() {
this.getmodel() this.getmodel()
this.getinfo() this.getinfo()
this.btnss() },
onShow() {
this.startSearch()
},
onHide() {
this.stopSearch()
},
onUnload() {
this.stopSearch()
}, },
methods: { methods: {
// //
@ -207,95 +218,138 @@
}; };
}, },
btnss() { //
uni.showLoading({ startSearch() {
title: '搜索中...', if (this.isSearching) return
mask: true this.isSearching = true
}); this.jiaohuaqi = []
this.jiaohuaqi = []; this.displayQueue = []
this.flag = false; this.processingQueue = false
const that = this; this.flag = false
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent);
xBlufi.notifyStartDiscoverBle({ 'isStart': true }); //
xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
xBlufi.notifyStartDiscoverBle({ 'isStart': true })
// 30
this.searchTimeout = setTimeout(() => {
this.stopSearch()
}, 30000)
},
//
stopSearch() {
this.isSearching = false
if (this.checkTimer) {
clearInterval(this.checkTimer)
this.checkTimer = null
}
if (this.searchTimeout) {
clearTimeout(this.searchTimeout)
this.searchTimeout = null
}
if (this.throttleTimer) {
clearTimeout(this.throttleTimer)
this.throttleTimer = null
}
xBlufi.notifyStartDiscoverBle({ 'isStart': false })
this.flag = true
},
//
processDisplayQueue() {
if (this.processingQueue || this.displayQueue.length === 0) return
this.processingQueue = true
const device = this.displayQueue.shift()
//
if (!this.jiaohuaqi.some(item => item.name === device.name)) {
this.jiaohuaqi.push(device)
}
//
setTimeout(() => { setTimeout(() => {
xBlufi.notifyStartDiscoverBle({ 'isStart': false }); this.processingQueue = false
if (that.devicesList.length > 0) { this.processDisplayQueue()
const data = { mac: that.arr }; }, 500) // 500ms
that.$u.post(`/app/getExistListByMacs`, data) },
.then(res => {
if (res.code === 200) { //
// MAC addToDisplayQueue(device) {
const updatedDevicesList = that.devicesList.map(item => { this.displayQueue.push(device)
const matchedData = res.data.find(val => item.name.slice(-12) === val.mac); if (!this.processingQueue) {
return matchedData ? { ...item, ...matchedData } : item; this.processDisplayQueue()
}); }
updatedDevicesList.forEach(val => { },
const mac = val.name.slice(-12);
const pre = val.name.slice(0, 5); //
const ssid = val.RSSI updateDeviceList(existList) {
const matched = that.getpipei(pre); const newDevices = this.devicesList.filter(item => {
const userid = val.userId || null; const mac = item.name.slice(-12)
that.jiaohuaqi.push({ return !this.jiaohuaqi.some(device => device.name === mac) &&
name: mac, !this.displayQueue.some(device => device.name === mac)
modelName: matched.modelName, })
modelPicture: matched.picture,
pre: pre, newDevices.forEach(item => {
userId: userid, const mac = item.name.slice(-12)
ssid:ssid const pre = item.name.slice(0, 5)
}); const ssid = item.RSSI
console.log(that.jiaohuaqi, '2222'); const matched = this.getpipei(pre)
}); const existDevice = existList.find(val => val.mac === mac)
}
}) const newDevice = {
.catch(error => { name: mac,
console.error('请求失败:', error); modelName: matched.modelName,
}) modelPicture: matched.picture,
.finally(() => { pre: pre,
uni.hideLoading(); userId: existDevice ? existDevice.userId : null,
that.flag = true; ssid: ssid
});
} else {
uni.hideLoading();
that.flag = true;
} }
}, 3000);
this.addToDisplayQueue(newDevice)
})
}, },
// //
funListenDeviceMsgEvent: function(options) { funListenDeviceMsgEvent: function(options) {
switch (options.type) { switch (options.type) {
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
if (!options.result) {
}
break
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS: case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
if (options.result) { if (options.result) {
const now = Date.now()
if (now - this.lastSearchTime < this.searchInterval) {
return
}
this.lastSearchTime = now
let devicesarr = [] let devicesarr = []
this.devicesList = options.data this.devicesList = options.data
options.data.forEach(item => { options.data.forEach(item => {
devicesarr.push(item.name.slice(-12)) devicesarr.push(item.name.slice(-12))
}) })
this.arr = devicesarr.join(',') this.arr = devicesarr.join(',')
}
break // 使
case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED: if (this.throttleTimer) {
console.log("连接回调:" + JSON.stringify(options)) clearTimeout(this.throttleTimer)
if (options.result) {
{
xBlufi.notifyInitBleEsp32({
deviceId: this.deviceId
})
this.deviceIds = options.data.deviceId
this.name = this.name
} }
} else {
this.throttleTimer = setTimeout(() => {
if (this.devicesList.length > 0) {
const data = { mac: this.arr }
this.$u.post(`/app/getExistListByMacs`, data)
.then(res => {
if (res.code === 200) {
this.updateDeviceList(res.data)
}
})
.catch(error => {
console.error('请求失败:', error)
})
}
}, 500) // 500ms
} }
break break
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
break;
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START: case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
if (!options.result) { if (!options.result) {
uni.showToast({ uni.showToast({
@ -305,12 +359,30 @@
}) })
this.flags = false this.flags = false
return return
} else {
} }
break break
} }
}, },
btnss() {
this.stopSearch()
this.jiaohuaqi = []
this.displayQueue = []
this.processingQueue = false
this.startSearch()
},
//
handleSearch() {
if (!this.flag) {
uni.showToast({
title: '请等待蓝牙搜索完成后再操作',
icon: 'none',
duration: 2000
})
return
}
this.btnss()
},
} }
} }
</script> </script>
@ -375,6 +447,12 @@
left: 50%; left: 50%;
transform: translateX(-50%); transform: translateX(-50%);
bottom: 106rpx; bottom: 106rpx;
transition: all 0.3s ease;
&.searching {
background: #E5E5E5;
color: #666666;
}
} }
.list { .list {
@ -382,6 +460,7 @@
border-radius: 20rpx; border-radius: 20rpx;
margin: auto; margin: auto;
margin-top: 72rpx; margin-top: 72rpx;
will-change: transform; //
.list_item { .list_item {
margin-top: 18rpx; margin-top: 18rpx;
@ -395,6 +474,21 @@
box-shadow: 0rpx 10rpx 64rpx 0rpx rgba(0, 0, 0, 0.08); box-shadow: 0rpx 10rpx 64rpx 0rpx rgba(0, 0, 0, 0.08);
padding: 18rpx 30rpx; padding: 18rpx 30rpx;
box-sizing: border-box; box-sizing: border-box;
animation: slideIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
opacity: 0;
transform: translateX(-100%);
will-change: transform, opacity; //
@keyframes slideIn {
from {
opacity: 0;
transform: translateX(-100%);
}
to {
opacity: 1;
transform: translateX(0);
}
}
image { image {
width: 94rpx; width: 94rpx;