浇花器

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 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>
<view class="cen">
<view class="name" style="color: #ccc;" v-if="item.userId && item.userId != userid">
@ -51,10 +51,7 @@
</view>
<!-- 点击搜索 -->
<view class="btnss" @click="btnss" v-if="flag">
重新搜索
</view>
<view class="btnss" v-else>
<view class="btnss" @click="handleSearch" :class="{ 'searching': !flag }">
重新搜索
</view>
</view>
@ -96,6 +93,15 @@
showNameDialog: false,
customDeviceName: '',
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() {
},
onShow() {
this.getmodel()
this.getinfo()
this.btnss()
},
onShow() {
this.startSearch()
},
onHide() {
this.stopSearch()
},
onUnload() {
this.stopSearch()
},
methods: {
//
@ -207,95 +218,138 @@
};
},
btnss() {
uni.showLoading({
title: '搜索中...',
mask: true
});
this.jiaohuaqi = [];
this.flag = false;
const that = this;
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent);
xBlufi.notifyStartDiscoverBle({ 'isStart': true });
//
startSearch() {
if (this.isSearching) return
this.isSearching = true
this.jiaohuaqi = []
this.displayQueue = []
this.processingQueue = false
this.flag = false
//
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(() => {
xBlufi.notifyStartDiscoverBle({ 'isStart': false });
if (that.devicesList.length > 0) {
const data = { mac: that.arr };
that.$u.post(`/app/getExistListByMacs`, data)
.then(res => {
if (res.code === 200) {
// MAC
const updatedDevicesList = that.devicesList.map(item => {
const matchedData = res.data.find(val => item.name.slice(-12) === val.mac);
return matchedData ? { ...item, ...matchedData } : item;
});
updatedDevicesList.forEach(val => {
const mac = val.name.slice(-12);
const pre = val.name.slice(0, 5);
const ssid = val.RSSI
const matched = that.getpipei(pre);
const userid = val.userId || null;
that.jiaohuaqi.push({
this.processingQueue = false
this.processDisplayQueue()
}, 500) // 500ms
},
//
addToDisplayQueue(device) {
this.displayQueue.push(device)
if (!this.processingQueue) {
this.processDisplayQueue()
}
},
//
updateDeviceList(existList) {
const newDevices = this.devicesList.filter(item => {
const mac = item.name.slice(-12)
return !this.jiaohuaqi.some(device => device.name === mac) &&
!this.displayQueue.some(device => device.name === mac)
})
newDevices.forEach(item => {
const mac = item.name.slice(-12)
const pre = item.name.slice(0, 5)
const ssid = item.RSSI
const matched = this.getpipei(pre)
const existDevice = existList.find(val => val.mac === mac)
const newDevice = {
name: mac,
modelName: matched.modelName,
modelPicture: matched.picture,
pre: pre,
userId: userid,
userId: existDevice ? existDevice.userId : null,
ssid: ssid
});
console.log(that.jiaohuaqi, '2222');
});
}
this.addToDisplayQueue(newDevice)
})
.catch(error => {
console.error('请求失败:', error);
})
.finally(() => {
uni.hideLoading();
that.flag = true;
});
} else {
uni.hideLoading();
that.flag = true;
}
}, 3000);
},
//
funListenDeviceMsgEvent: function(options) {
switch (options.type) {
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
if (!options.result) {
}
break
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
if (options.result) {
const now = Date.now()
if (now - this.lastSearchTime < this.searchInterval) {
return
}
this.lastSearchTime = now
let devicesarr = []
this.devicesList = options.data
options.data.forEach(item => {
devicesarr.push(item.name.slice(-12))
})
this.arr = devicesarr.join(',')
// 使
if (this.throttleTimer) {
clearTimeout(this.throttleTimer)
}
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)
}
break
case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
console.log("连接回调:" + JSON.stringify(options))
if (options.result) {
{
xBlufi.notifyInitBleEsp32({
deviceId: this.deviceId
})
this.deviceIds = options.data.deviceId
this.name = this.name
.catch(error => {
console.error('请求失败:', error)
})
}
} else {
}, 500) // 500ms
}
break
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
break;
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
if (!options.result) {
uni.showToast({
@ -305,12 +359,30 @@
})
this.flags = false
return
} else {
}
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>
@ -375,6 +447,12 @@
left: 50%;
transform: translateX(-50%);
bottom: 106rpx;
transition: all 0.3s ease;
&.searching {
background: #E5E5E5;
color: #666666;
}
}
.list {
@ -382,6 +460,7 @@
border-radius: 20rpx;
margin: auto;
margin-top: 72rpx;
will-change: transform; //
.list_item {
margin-top: 18rpx;
@ -395,6 +474,21 @@
box-shadow: 0rpx 10rpx 64rpx 0rpx rgba(0, 0, 0, 0.08);
padding: 18rpx 30rpx;
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 {
width: 94rpx;