From 01b64ea54af24de0c4adcba67f01287904073102 Mon Sep 17 00:00:00 2001 From: JenniferW <1627055433@qq.com> Date: Mon, 22 Dec 2025 10:11:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/order/intention/search.vue | 69 +++++++++++++++++++++------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/src/views/order/intention/search.vue b/src/views/order/intention/search.vue index e842f75..58875bc 100644 --- a/src/views/order/intention/search.vue +++ b/src/views/order/intention/search.vue @@ -1414,27 +1414,69 @@ const fetchSearchHints = async (keyword) => { if (!keyword) return; try { // 先解析当前输入的条件 - const conditions = parseConditions(currentInput.value); + parsedConditions.value = parseConditions(currentInput.value); - // 构建 fieldConditions - const fieldConditions = conditions - .filter((condition) => condition.value) + // 检测当前正在编辑的条件索引 + const cursorIndex = findCursorConditionIndex(); + const parts = currentInput.value.split(/[;;]/); + const activeIndex = + cursorIndex >= 0 && cursorIndex < parts.length + ? cursorIndex + : parts.length - 1; + + // 如果正在编辑中间的条件,需要重新排序:将正在编辑的条件移到最后一个位置 + let conditionsToProcess = [...parsedConditions.value]; + if (activeIndex >= 0 && activeIndex < conditionsToProcess.length - 1) { + const [editedCondition] = conditionsToProcess.splice(activeIndex, 1); + conditionsToProcess.push(editedCondition); + } + + // 构建 fieldConditions,参考 buildFieldConditionsPayload 的处理方式 + const fieldConditions = conditionsToProcess + .filter((condition) => { + // 保留有值的条件,或者有字段名但没有值的条件(如 "车型:") + return condition.value || (condition.fieldLabel && condition.field); + }) .map((condition) => { - // 如果明确选择了字段(有 field 且 valid),使用 fieldName 和 fieldValue - if (condition.field && condition.valid) { + // 1)字段 + 值:结构化查询 + if (condition.valid && condition.field && condition.value) { return { - fieldName: condition.field, // 使用 fieldKey - fieldValue: condition.value, // 对应的 value + fieldName: condition.field, + fieldValue: condition.value, keyword: "", queryType: "FUZZY", }; } - // 不确定输入的值是 label 还是 value,全部放 keyword + // 2)只有字段(如 "车型:"):fieldName 为字段 key,fieldValue 为空 + if (condition.valid && condition.field && !condition.value) { + return { + fieldName: condition.field, + fieldValue: "", + keyword: "", + queryType: "FUZZY", + }; + } + + // 3)只有值(如直接选了某个值,没有字段) + if (!condition.field && condition.value && !condition.fieldLabel) { + return { + fieldName: "", + fieldValue: condition.value, + keyword: "", + queryType: "FUZZY", + }; + } + + // 4)其它情况(例如纯手输、无法识别字段),作为关键字查询 + const keyword = condition.fieldLabel + ? `${condition.fieldLabel}:${condition.value}`.replace(/:$/, "") + : condition.value; + return { fieldName: "", fieldValue: "", - keyword: condition.value, + keyword, queryType: "FUZZY", }; }); @@ -1475,12 +1517,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;