Skip to content

Commit c039283

Browse files
committed
feat: SQL模式检索结果替换
1 parent 3284fb9 commit c039283

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

bklog/web/src/views/retrieve-v2/search-bar/index.vue

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ const isFilterSecFocused = computed(
116116
() => isGloalUsage.value
117117
&& store.state.retrieve.catchFieldCustomConfig.fixedFilterAddition,
118118
);
119-
const indexItem = computed(() => store.state.indexItem);
120-
const keyword = computed(() => indexItem.value.keyword);
121-
const addition = computed(() => indexItem.value.addition);
119+
// const indexItem = computed(() => store.state.indexItem);
120+
const keyword = computed(() => {
121+
const value = store.state.indexItem.keyword;
122+
return value;
123+
});
124+
const addition = computed(() => store.state.indexItem.addition);
122125
const searchMode = computed(() => (!isGloalUsage.value
123126
? SEARCH_MODE_DIC[localModeActiveIndex.value]
124127
: SEARCH_MODE_DIC[store.state.storage[BK_LOG_STORAGE.SEARCH_TYPE]] ?? 'ui'),
@@ -181,14 +184,49 @@ watch(
181184
},
182185
);
183186
187+
// 监听 computed keyword 的变化
184188
watch(
185-
keyword,
186-
() => {
187-
sqlQueryValue.value = keyword.value;
189+
() => keyword.value,
190+
(newValue, oldValue) => {
191+
if (newValue !== sqlQueryValue.value) {
192+
sqlQueryValue.value = newValue;
193+
}
194+
},
195+
{ immediate: true },
196+
);
197+
198+
// 额外监听 store 中的 keyword 变化(深度监听)
199+
watch(
200+
() => store.state.indexItem.keyword,
201+
(newValue, oldValue) => {
202+
if (newValue !== sqlQueryValue.value) {
203+
sqlQueryValue.value = newValue;
204+
}
188205
},
189206
{ immediate: true },
190207
);
191208
209+
// 监听 aiQueryResult 的变化,当 AI 分析完成时,强制同步 sqlQueryValue
210+
watch(
211+
() => props.aiQueryResult?.queryString,
212+
(newQueryString, oldQueryString) => {
213+
// 当 AI 分析结果返回时(从 undefined/null 变为有值,或者值发生变化),强制同步 sqlQueryValue
214+
// 这样可以确保即使用户在 AI 分析过程中输入了内容,最终也会被 AI 结果覆盖
215+
if (newQueryString) {
216+
// 使用 nextTick 确保 store 中的 keyword 已经更新
217+
nextTick(() => {
218+
const storeKeyword = store.state.indexItem.keyword;
219+
// 如果 store 中的 keyword 与 AI 结果一致,或者 AI 结果刚返回(oldQueryString 为空),则强制同步
220+
if (storeKeyword === newQueryString || !oldQueryString) {
221+
if (sqlQueryValue.value !== newQueryString) {
222+
sqlQueryValue.value = newQueryString;
223+
}
224+
}
225+
});
226+
}
227+
},
228+
);
229+
192230
watch(clearSearchValueNum, () => {
193231
handleClearBtnClick();
194232
});

bklog/web/src/views/retrieve-v3/search-bar/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,6 @@ export default defineComponent({
328328
explain = '',
329329
} = contentObj;
330330

331-
aiQueryResult.value.parseResult = parseResult;
332-
aiQueryResult.value.explain = explain;
333-
334331
const queryParams = { search_mode: 'sql' };
335332
let needReplace = false;
336333
if (startTime && endTime) {
@@ -358,6 +355,9 @@ export default defineComponent({
358355
store.dispatch('requestIndexSetQuery');
359356
});
360357
}
358+
359+
aiQueryResult.value.parseResult = parseResult;
360+
aiQueryResult.value.explain = explain;
361361
} catch (e) {
362362
console.error(e);
363363
bkMessage({

0 commit comments

Comments
 (0)