mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-24 16:13:54 +08:00
调整搜索实现-从前端过滤改为后端查询
This commit is contained in:
@@ -119,34 +119,31 @@ export default {
|
||||
handleDeviceManage() {
|
||||
this.$router.push('/device-management');
|
||||
},
|
||||
handleSearch(regex) {
|
||||
handleSearch(keyword) {
|
||||
this.isSearching = true;
|
||||
this.searchRegex = regex;
|
||||
this.applySearchFilter();
|
||||
this.isLoading = true;
|
||||
// 检测MAC地址格式:包含4个冒号
|
||||
const isMac = /(:.*?){4}/.test(keyword);
|
||||
const searchType = isMac ? 'mac' : 'name';
|
||||
Api.agent.searchAgent(keyword, searchType, ({ data }) => {
|
||||
if (data?.data) {
|
||||
this.devices = data.data.map(item => ({
|
||||
...item,
|
||||
agentId: item.id
|
||||
}));
|
||||
}
|
||||
this.isLoading = false;
|
||||
}, (error) => {
|
||||
console.error('搜索智能体失败:', error);
|
||||
this.isLoading = false;
|
||||
this.$message.error(this.$t('message.searchFailed'));
|
||||
});
|
||||
},
|
||||
handleSearchReset() {
|
||||
this.isSearching = false;
|
||||
this.searchRegex = null;
|
||||
this.devices = [...this.originalDevices];
|
||||
this.fetchAgentList();
|
||||
},
|
||||
applySearchFilter() {
|
||||
if (!this.isSearching || !this.searchRegex) {
|
||||
this.devices = [...this.originalDevices];
|
||||
return;
|
||||
}
|
||||
|
||||
this.devices = this.originalDevices.filter(device => {
|
||||
// 搜索智能体名称
|
||||
if (this.searchRegex.test(device.agentName)) {
|
||||
return true;
|
||||
}
|
||||
// 搜索关联设备的MAC地址
|
||||
if (device.macAddresses && device.macAddresses.length > 0) {
|
||||
return device.macAddresses.some(macAddress => this.searchRegex.test(macAddress));
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
// 搜索更新智能体列表
|
||||
handleSearchResult(filteredList) {
|
||||
this.devices = filteredList; // 更新设备列表
|
||||
|
||||
Reference in New Issue
Block a user