调整搜索实现-从前端过滤改为后端查询

This commit is contained in:
LJH-rgsze
2026-01-05 10:10:17 +08:00
parent 9c111b2d5e
commit e25ca3d1d3
8 changed files with 118 additions and 34 deletions
+19 -22
View File
@@ -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; // 更新设备列表