diff --git a/src/api/system/instruction.js b/src/api/system/instruction.js index 889994b..3f6b43e 100644 --- a/src/api/system/instruction.js +++ b/src/api/system/instruction.js @@ -19,11 +19,21 @@ export function executeInstructionWithForce(data) { }) } -export function getHistory(type, limit) { +/** + * 获取历史消息记录 + * @param type request | response + * @param limit 条数上限 + * @param keyword 可选,搜索关键词;传则后端在全部数据中过滤后返回 + */ +export function getHistory(type, limit, keyword) { + const params = { type, limit } + if (keyword != null && String(keyword).trim() !== '') { + params.keyword = String(keyword).trim() + } return request({ url: '/jarvis/instruction/history', method: 'get', - params: { type, limit } + params }) } diff --git a/src/views/system/jd-instruction/index.vue b/src/views/system/jd-instruction/index.vue index 3ffdee4..6566ed6 100644 --- a/src/views/system/jd-instruction/index.vue +++ b/src/views/system/jd-instruction/index.vue @@ -70,20 +70,34 @@ + 搜索匹配: + + (在全部数据中匹配)
- 历史请求(最近 {{ historyLimit }} 条) + {{ historySearchKeyword.trim() ? `历史请求(关键词匹配 共 ${displayRequestList.length} 条)` : `历史请求(最近 ${historyLimit} 条)` }} 刷新
-
-
+
+
+
+ +
-
+
{{ extractTime(item) }}
- 历史响应(最近 {{ historyLimit }} 条) + {{ historySearchKeyword.trim() ? `历史响应(关键词匹配 共 ${displayResponseList.length} 条)` : `历史响应(最近 ${historyLimit} 条)` }}
-
-
+
+
+
+ +
-
+
{{ extractTime(item) }}
@@ -178,6 +195,11 @@ export default { responseHistory: [], historyLoading: false, historyLimit: 50, + historySearchKeyword: '', // 历史记录搜索关键词(有值时请求后端在全部数据中搜索) + searchRequestList: [], // 服务端返回的请求搜索结果 + searchResponseList: [], // 服务端返回的响应搜索结果 + historySearchLoading: false, + historySearchTimer: null, // 防抖定时器 // 验证码相关 verifyDialogVisible: false, verifyCode: '', @@ -188,6 +210,19 @@ export default { } }, computed: { + // 当前展示的请求列表:有搜索关键词时用服务端搜索结果,否则用本地已加载的 requestHistory + displayRequestList() { + return this.historySearchKeyword.trim() ? this.searchRequestList : this.requestHistory + }, + displayResponseList() { + return this.historySearchKeyword.trim() ? this.searchResponseList : this.responseHistory + }, + displayRequestLoading() { + return !!this.historySearchKeyword.trim() && this.historySearchLoading + }, + displayResponseLoading() { + return !!this.historySearchKeyword.trim() && this.historySearchLoading + }, // 生成完整消息,用三个空行分隔 fullMessage() { if (!this.resultList || this.resultList.length === 0) return '' @@ -390,6 +425,48 @@ export default { this.$modal.msgError('加载历史记录失败') }) }, + // 搜索框输入:防抖后请求后端在全部历史数据中搜索 + onHistorySearchInput() { + if (this.historySearchTimer) clearTimeout(this.historySearchTimer) + const kw = (this.historySearchKeyword || '').trim() + if (!kw) { + this.searchRequestList = [] + this.searchResponseList = [] + return + } + this.historySearchTimer = setTimeout(() => { + this.loadHistorySearch(kw) + }, 300) + }, + // 按关键词在全部数据中搜索(后端接口) + loadHistorySearch(keyword) { + if (!keyword || !keyword.trim()) { + this.searchRequestList = [] + this.searchResponseList = [] + return + } + this.historySearchLoading = true + const limit = 500 + Promise.all([ + getHistory('request', limit, keyword), + getHistory('response', limit, keyword) + ]).then(([reqRes, respRes]) => { + this.historySearchLoading = false + if (reqRes && reqRes.code === 200) { + this.searchRequestList = reqRes.data || [] + } else { + this.searchRequestList = [] + } + if (respRes && respRes.code === 200) { + this.searchResponseList = respRes.data || [] + } else { + this.searchResponseList = [] + } + }).catch(() => { + this.historySearchLoading = false + this.$modal.msgError('搜索历史记录失败') + }) + }, extractTime(item) { if (!item) return '' const idx = item.indexOf(' | ') @@ -811,6 +888,16 @@ export default { font-weight: 500; } +.history-search-label { + margin-left: 16px; +} + +.history-search-tip { + font-size: 12px; + color: #909399; + margin-left: 8px; +} + /* 历史消息容器 */ .history-container { display: flex;