mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-23 23:53:55 +08:00
调整搜索实现-从前端过滤改为后端查询
This commit is contained in:
@@ -382,4 +382,24 @@ export default {
|
||||
});
|
||||
}).send();
|
||||
},
|
||||
|
||||
// 搜索智能体
|
||||
searchAgent(keyword, searchType, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/agent/search`)
|
||||
.method('GET')
|
||||
.data({
|
||||
keyword: keyword,
|
||||
searchType: searchType // searchType: 'name' 或 'mac'
|
||||
})
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.networkFail(() => {
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.searchAgent(keyword, searchType, callback);
|
||||
});
|
||||
}).send();
|
||||
},
|
||||
}
|
||||
|
||||
@@ -408,18 +408,8 @@ export default {
|
||||
// 保存搜索历史
|
||||
this.saveSearchHistory(searchValue);
|
||||
|
||||
try {
|
||||
// 创建不区分大小写的正则表达式
|
||||
const regex = new RegExp(searchValue, "i");
|
||||
// 触发搜索事件,将正则表达式传递给父组件
|
||||
this.$emit("search", regex);
|
||||
} catch (error) {
|
||||
console.error("正则表达式创建失败:", error);
|
||||
this.$message.error({
|
||||
message: this.$t("message.error"),
|
||||
showClose: true,
|
||||
});
|
||||
}
|
||||
// 触发搜索事件,将搜索关键词传递给父组件
|
||||
this.$emit("search", searchValue);
|
||||
|
||||
// 搜索完成后让输入框失去焦点,从而触发blur事件隐藏搜索历史
|
||||
if (this.$refs.searchInput) {
|
||||
|
||||
@@ -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