This commit is contained in:
JenniferW 2025-12-19 13:53:11 +08:00
parent 87b9e02019
commit f0e269145f
1 changed files with 35 additions and 2 deletions

View File

@ -1364,10 +1364,14 @@ const fetchSearchHints = async (keyword) => {
mergeFieldMetadata(hintList);
// 从返回的数据中提取字段信息用于"可能属于的字段"下拉框
// 只有在没有明确字段时(当前输入不包含冒号)才显示可能字段
// 优先根据光标位置确定当前正在编辑的条件,再决定使用哪一段文本
const parts = currentInput.value.split(/[;;]/);
const currentPart = parts[parts.length - 1]?.trim() || "";
const cursorIndex = findCursorConditionIndex();
const activeIndex =
cursorIndex >= 0 && cursorIndex < parts.length
? cursorIndex
: parts.length - 1;
const currentPart = parts[activeIndex]?.trim() || "";
const isEditingExistingField =
cursorIndex >= 0 && cursorIndex < parts.length - 1;
@ -1425,11 +1429,40 @@ const fetchSearchHints = async (keyword) => {
? currentPart.split(":").slice(1).join(":").trim()
: currentPart;
const valueQueryLower = (valueQuery || "").toLowerCase();
// 如果当前条件已经选定字段(例如 "车型:"),则只展示该字段对应的值
let activeFieldKey = "";
if (currentPart.includes(":")) {
const fieldLabel = currentPart.split(":")[0].trim();
// 先从本地字段缓存中找
const localField = allFields.value.find(
(f) => f.label === fieldLabel || f.key === fieldLabel
);
if (localField) {
activeFieldKey = localField.key;
} else {
// 再从接口返回的字段中找
const apiField = hintList.find(
(item) =>
item.fieldName === fieldLabel ||
item.fieldKey === fieldLabel ||
item.label === fieldLabel
);
if (apiField) {
activeFieldKey = apiField.fieldKey || apiField.key || "";
}
}
}
const matchedValueSuggestions = [];
const fallbackValueSuggestions = [];
hintList.forEach((item) => {
if (!Array.isArray(item.fieldValues)) return;
const fieldKey = item.fieldKey || item.key || "";
// 若已经识别出当前正在编辑的字段,则只保留该字段的值
if (activeFieldKey && fieldKey !== activeFieldKey) return;
const fieldLabel = item.fieldName || item.label || item.fieldLabel || "";
item.fieldValues.forEach((val) => {
const strVal =