@@ -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 );
122125const 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 的变化
184188watch (
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+
192230watch (clearSearchValueNum, () => {
193231 handleClearBtnClick ();
194232});
0 commit comments