From 5da552d8035c161e4c3ebd60b47092f2b4148a2a Mon Sep 17 00:00:00 2001 From: JenniferW <1627055433@qq.com> Date: Mon, 15 Dec 2025 14:29:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/order/intention/search.vue | 164 +- .../intention/search搜索条件get请求.vue | 2755 +++++++++++++++++ 2 files changed, 2914 insertions(+), 5 deletions(-) create mode 100644 src/views/order/intention/search搜索条件get请求.vue diff --git a/src/views/order/intention/search.vue b/src/views/order/intention/search.vue index 766b2aa..df40f07 100644 --- a/src/views/order/intention/search.vue +++ b/src/views/order/intention/search.vue @@ -982,10 +982,101 @@ const triggerConditionSuggestions = (conditionText) => { suggestions.value = fieldValues.slice(0, 8); possibleFields.value = []; // 已有字段时不显示可能的字段 + } else { + // 字段无效,显示所有值 + const allValueSuggestions = allValues.value + .filter((item) => + String(item.value).toLowerCase().includes(conditionText.toLowerCase()) + ) + .map((item) => ({ + type: "value", + label: item.value, + value: item.value, + fieldKey: item.fieldKey, + fieldLabel: item.fieldLabel, + weight: item.weight, + })); + suggestions.value = allValueSuggestions.slice(0, 8); + possibleFields.value = []; } } else { - // 只有值,没有字段,使用原有逻辑 - handleInput(currentInput.value, { skipDifference: true }); + // 只有值,没有字段,直接查找匹配的建议(避免递归调用) + const cursorIndex = findCursorConditionIndex(); + const usedLabels = getUsedFieldLabels(cursorIndex); + + // 查找匹配的字段和值 + const fieldSuggestions = allFields.value + .filter( + (field) => + !usedLabels.has(field.label) && + field.label.toLowerCase().includes(conditionText.toLowerCase()) + ) + .map((field) => ({ + type: "field", + label: field.label, + value: field.key, + weight: 3, + })); + + const valueSuggestions = allValues.value + .filter((item) => + String(item.value).toLowerCase().includes(conditionText.toLowerCase()) + ) + .map((item) => ({ + type: "value", + label: item.value, + value: item.value, + fieldKey: item.fieldKey, + fieldLabel: item.fieldLabel, + weight: item.weight, + })); + + // 检查是否有值强烈匹配某个字段 + const valueFieldCounts = {}; + valueSuggestions.forEach((val) => { + if (!valueFieldCounts[val.fieldKey]) { + valueFieldCounts[val.fieldKey] = { + count: 0, + label: val.fieldLabel, + field: allFields.value.find((f) => f.key === val.fieldKey), + }; + } + valueFieldCounts[val.fieldKey].count += val.weight; + }); + + possibleFields.value = Object.values(valueFieldCounts) + .filter( + (item) => + item.count > 1 && item.field && !usedLabels.has(item.field.label) + ) + .sort((a, b) => b.count - a.count) + .map((item) => item.field); + + // 合并建议并按相关性排序 + let allSuggestions = [...fieldSuggestions, ...valueSuggestions]; + allSuggestions.sort((a, b) => { + if (b.weight !== a.weight) { + return b.weight - a.weight; + } + const aMatch = a.label.toLowerCase().indexOf(conditionText.toLowerCase()); + const bMatch = b.label.toLowerCase().indexOf(conditionText.toLowerCase()); + if (aMatch !== bMatch) { + return aMatch - bMatch; + } + return a.label.length - b.label.length; + }); + + // 去重并限制数量 + const uniqueSuggestions = []; + const seenLabels = new Set(); + allSuggestions.forEach((suggestion) => { + if (!seenLabels.has(suggestion.label)) { + seenLabels.add(suggestion.label); + uniqueSuggestions.push(suggestion); + } + }); + + suggestions.value = uniqueSuggestions.slice(0, 8); } }; @@ -1182,8 +1273,45 @@ const handleInput = (value, options = {}) => { const fetchSearchHints = async (keyword) => { if (!keyword) return; try { - const res = await searchHint({ keyword }); - const hintList = Array.isArray(res?.data) + // 先解析当前输入的条件 + const conditions = parseConditions(currentInput.value); + + // 构建 fieldConditions + const fieldConditions = conditions + .filter((condition) => condition.value) + .map((condition) => { + // 如果明确选择了字段(有 field 且 valid),使用 fieldName 和 fieldValue + if (condition.field && condition.valid) { + return { + fieldName: condition.field, // 使用 fieldKey + fieldValue: condition.value, // 对应的 value + keyword: "", + queryType: "FUZZY", + }; + } + + // 不确定输入的值是 label 还是 value,全部放 keyword + return { + fieldName: "", + fieldValue: "", + keyword: condition.value, + queryType: "FUZZY", + }; + }); + + const payload = { + fieldConditions, + inputWord: currentInput.value.trim(), + page: 0, + size: pageSize.value, + }; + const res = await searchHint(payload); + const pageData = res?.data ?? res ?? {}; + const hintList = Array.isArray(pageData?.content) + ? pageData.content + : Array.isArray(pageData) + ? pageData + : Array.isArray(res?.data) ? res.data : Array.isArray(res) ? res @@ -1351,7 +1479,8 @@ const selectSuggestion = (item) => { currentInput.value = parts.join(";").replace(/;;+/g, ";").trim(); // 检查是否添加了分号(选择值建议时会自动添加分号) - const hasAddedSemicolon = item.type === "value" && parts[targetIndex].trim().endsWith(";"); + const hasAddedSemicolon = + item.type === "value" && parts[targetIndex].trim().endsWith(";"); // 保持建议框显示,允许继续编辑 setTimeout(() => { @@ -1541,6 +1670,31 @@ const buildFieldConditionsPayload = () => { }); }; +// 为 searchHint 构建 fieldConditions +const buildFieldConditionsForHint = () => { + return parsedConditions.value + .filter((condition) => condition.value) + .map((condition) => { + // 如果明确选择了字段(有 field 且 valid),使用 fieldName 和 fieldValue + if (condition.field && condition.valid) { + return { + fieldName: condition.field, // 使用 fieldKey + fieldValue: condition.value, // 对应的 value + keyword: "", + queryType: "FUZZY", + }; + } + + // 不确定输入的值是 label 还是 value,全部放 keyword + return { + fieldName: "", + fieldValue: "", + keyword: condition.value, + queryType: "FUZZY", + }; + }); +}; + const executeSearch = async ({ page = currentPage.value } = {}) => { if (pendingSearchTimer.value) { clearTimeout(pendingSearchTimer.value); diff --git a/src/views/order/intention/search搜索条件get请求.vue b/src/views/order/intention/search搜索条件get请求.vue new file mode 100644 index 0000000..766b2aa --- /dev/null +++ b/src/views/order/intention/search搜索条件get请求.vue @@ -0,0 +1,2755 @@ + + + + + + + + 品号查询 + + + + + + + + + + + + + + + + 您输入的条件可能属于以下字段: + + + [字段] + {{ field.label }} + : + + + + 0 + ? 1 + possibleFields.length + : 0) + " + @keydown.enter.stop="selectSuggestion(item)" + @keydown.arrow-down.stop="navigateSuggestions('down')" + @keydown.arrow-up.stop="navigateSuggestions('up')" + tabindex="0" + > + [字段] + [值] + {{ item.label }} + : + + + + + + + + 查询 + + + + + + 以下商品列表中,关键差异信息: + + {{ item.label }} + 、 + + + + + + + {{ cond.fieldLabel }}: + {{ cond.value }} + + 精准 + + + + 清除所有 + + + + + + 选择精准查询参数: + + + {{ cond.fieldLabel }}: + {{ cond.value }} + + + + + + + + + + + 参数对比 + + + + + + {{ item.partName }} + + + 品号:{{ item.partNumber }} + + + 品号-规格型号: {{ item.partNumberSpec }} + + + 车型: {{ item.trainModel }} + + + + + + + + + + + + + + + + + 确定 + + + + + + + + + 参数对比 + + + + + + + + {{ isFullscreen ? "退出全屏" : "全屏" }} + + + + + + + + + + {{ showOnlyDifferences ? "显示全部" : "仅看不同项" }} + + + + + + + + + + + + + + + + + {{ column.label }} + + {{ + displayCompareList.find( + (i) => i.partNumber === column.label + )?.partName || "-" + }} + + + + + + + {{ scope.row[scope.column.property] || "-" }} + + + + + + + + + + + + 您选择的品号为:{{ selectedProductNumber }} + + + + 确定 + + + + + + + + 正式环境中提供语音输入检索功能,demo中仅做示意。 + + + + 我知道了 + + + + + + + + + + + +