From f3b289d16c3439bb2fc2856039f13e7a064eb2ee Mon Sep 17 00:00:00 2001 From: JenniferW <1627055433@qq.com> Date: Mon, 22 Dec 2025 13:45:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/order/intention/search.vue | 60 +++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/src/views/order/intention/search.vue b/src/views/order/intention/search.vue index e012893..ef1a75e 100644 --- a/src/views/order/intention/search.vue +++ b/src/views/order/intention/search.vue @@ -1114,6 +1114,15 @@ const triggerConditionSuggestions = (conditionText) => { suggestions.value = uniqueSuggestions.slice(0, 8); } + + // 无论是字段还是值,只要光标移动到某个条件,都实时调用 searchHint, + // 使用当前这一段文本作为 keyword,且不依赖之前的本地缓存 + if (conditionText && conditionText.trim()) { + // 允许本次 smart 接口返回覆盖本地字段/值缓存 + disableLocalSuggestions.value = false; + fieldsFromApi.value = false; + scheduleSearchHint(conditionText.trim()); + } }; // 根据当前输入更新建议列表(不触发远程请求) @@ -1490,8 +1499,36 @@ const fetchSearchHints = async (keyword) => { // 始终基于最新的 currentInput.value 解析条件,确保使用最新的条件顺序 parsedConditions.value = parseConditions(currentInput.value); - // 构建 fieldConditions,使用最新的条件顺序 - const fieldConditions = parsedConditions.value + // 检测当前正在编辑的条件索引 + const cursorIndex = findCursorConditionIndex(); + const parts = currentInput.value.split(/[;;]/); + const activeIndex = + cursorIndex >= 0 && cursorIndex < parts.length + ? cursorIndex + : parts.length - 1; + + // 如果正在编辑中间的条件,需要重新排序:将正在编辑的条件移到最后一个位置 + let conditionsToProcess = [...parsedConditions.value]; + let reorderedInputWord = currentInput.value.trim(); + + if (activeIndex >= 0 && activeIndex < conditionsToProcess.length - 1) { + // 正在编辑中间的条件,需要重新排序 + const [editedCondition] = conditionsToProcess.splice(activeIndex, 1); + conditionsToProcess.push(editedCondition); + + // 重新构建 inputWord,将被编辑的条件移到最后一个位置 + const reorderedParts = parts + .map((p) => p.trim()) + .filter((p) => p); + if (activeIndex < reorderedParts.length) { + const [editedPart] = reorderedParts.splice(activeIndex, 1); + reorderedParts.push(editedPart); + reorderedInputWord = reorderedParts.join(";"); + } + } + + // 构建 fieldConditions,使用重新排序后的条件顺序 + const fieldConditions = conditionsToProcess .filter((condition) => { // 保留有值的条件,或者有字段名但没有值的条件(如 "车型:") return condition.value || (condition.fieldLabel && condition.field); @@ -1552,7 +1589,7 @@ const fetchSearchHints = async (keyword) => { const payload = { fieldConditions, - inputWord: currentInput.value.trim(), + inputWord: reorderedInputWord, page: 0, size: pageSize.value, }; @@ -1586,12 +1623,7 @@ const fetchSearchHints = async (keyword) => { // 从返回的数据中提取字段信息用于"可能属于的字段"下拉框 // 优先根据光标位置确定当前正在编辑的条件,再决定使用哪一段文本 - const parts = currentInput.value.split(/[;;]/); - const cursorIndex = findCursorConditionIndex(); - const activeIndex = - cursorIndex >= 0 && cursorIndex < parts.length - ? cursorIndex - : parts.length - 1; + // 注意:parts、cursorIndex、activeIndex 已在函数开始处声明,这里直接使用 const currentPart = parts[activeIndex]?.trim() || ""; const isEditingExistingField = cursorIndex >= 0 && cursorIndex < parts.length - 1; @@ -1876,8 +1908,14 @@ const selectSuggestion = (item) => { parts[targetIndex] = `${fieldPart}${item.label}`; } } else { - // 无字段时直接处理值 - parts[targetIndex] = item.label; + // 无字段时,如果值建议项包含字段信息,自动补充字段名 + if (item.fieldLabel) { + // 自动补充字段名和冒号 + parts[targetIndex] = `${item.fieldLabel}:${item.label}`; + } else { + // 如果没有字段信息,直接使用值 + parts[targetIndex] = item.label; + } } // 核心:值选择后自动添加分号(避免重复添加)