tag同步清除优化

This commit is contained in:
JenniferW 2025-12-22 11:06:14 +08:00
parent 0c7f19c33f
commit a6c0293205
1 changed files with 103 additions and 65 deletions

View File

@ -1323,13 +1323,19 @@ const handleInput = (value, options = {}) => {
//
if (lastPart !== currentPart) {
//
const editedPart = currentPart;
const editedPart = currentPart.trim();
//
const oldConditionIndex = cursorIndex;
//
const newParts = currentParts.filter(
(_, index) => index !== cursorIndex
);
//
if (editedPart) {
newParts.push(editedPart);
}
const newValue = newParts.join(";");
// 使
@ -1341,9 +1347,51 @@ const handleInput = (value, options = {}) => {
// 使 skipReorder
currentInput.value = newValue;
// 使
// 使
parsedConditions.value = parseConditions(newValue);
//
if (preciseConditions.value.length > 0) {
//
const preciseIndex = preciseConditions.value.findIndex(
(cond) => cond.originalIndex === oldConditionIndex
);
if (preciseIndex !== -1) {
//
if (editedPart) {
//
const editedCondition = parseConditions(editedPart)[0];
if (editedCondition) {
//
const newIndex = parsedConditions.value.findIndex(
(c) =>
c.field === editedCondition.field &&
c.value === editedCondition.value &&
c.fieldLabel === editedCondition.fieldLabel
);
if (newIndex !== -1) {
//
preciseConditions.value[preciseIndex] = {
...preciseConditions.value[preciseIndex],
...editedCondition,
originalIndex: newIndex,
};
} else {
//
preciseConditions.value.splice(preciseIndex, 1);
}
} else {
//
preciseConditions.value.splice(preciseIndex, 1);
}
} else {
//
preciseConditions.value.splice(preciseIndex, 1);
}
}
//
syncPreciseConditionsIndex();
}
//
suggestions.value = [];
@ -1366,6 +1414,11 @@ const handleInput = (value, options = {}) => {
}, 100);
});
// 使
if (newValue.trim()) {
triggerRealTimeSearch();
}
//
const finalPart = editedPart;
if (finalPart && !options.skipFetch) {
@ -1398,6 +1451,27 @@ const handleInput = (value, options = {}) => {
return;
}
// parsedConditions tag
const newConditions = parseConditions(normalizedValue);
parsedConditions.value = newConditions;
//
if (preciseConditions.value.length > 0) {
preciseConditions.value = preciseConditions.value.filter((preciseCond) => {
//
const exists = newConditions.some(
(cond) =>
cond.field === preciseCond.field &&
cond.value === preciseCond.value &&
cond.fieldLabel === preciseCond.fieldLabel
);
return exists;
});
}
//
syncPreciseConditionsIndex();
updateSuggestionsFromValue(normalizedValue);
if (options.skipFetch) {
return;
@ -1413,26 +1487,11 @@ const handleInput = (value, options = {}) => {
const fetchSearchHints = async (keyword) => {
if (!keyword) return;
try {
//
// currentInput.value 使
parsedConditions.value = parseConditions(currentInput.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
// fieldConditions使
const fieldConditions = parsedConditions.value
.filter((condition) => {
// ":"
return condition.value || (condition.fieldLabel && condition.field);
@ -1527,7 +1586,12 @@ const fetchSearchHints = async (keyword) => {
// ""
// 使
// partscursorIndexactiveIndex 使
const parts = currentInput.value.split(/[;]/);
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;
@ -1991,40 +2055,26 @@ const syncPreciseConditionsIndex = () => {
const buildFieldConditionsPayload = () => {
const preciseIndexSet = getPreciseIndexSet();
//
const cursorIndex = findCursorConditionIndex();
const parts = currentInput.value.split(/[;]/);
const activeIndex =
cursorIndex >= 0 && cursorIndex < parts.length
? cursorIndex
: parts.length - 1;
// currentInput.value 使
const latestConditions = parseConditions(currentInput.value);
//
let conditionsToProcess = [...parsedConditions.value];
if (activeIndex >= 0 && activeIndex < conditionsToProcess.length - 1) {
const [editedCondition] = conditionsToProcess.splice(activeIndex, 1);
conditionsToProcess.push(editedCondition);
}
return conditionsToProcess
return latestConditions
.filter((condition) => {
// ":"
return condition.value || (condition.fieldLabel && condition.field);
})
.map((condition, index) => {
//
const originalIndex =
activeIndex >= 0 && activeIndex < parsedConditions.value.length - 1
? index === conditionsToProcess.length - 1
? activeIndex
: parsedConditions.value.findIndex(
//
const originalIndex = parsedConditions.value.findIndex(
(c) =>
c.fieldLabel === condition.fieldLabel &&
c.value === condition.value &&
c.field === condition.field
)
: index;
const queryType = preciseIndexSet.has(originalIndex) ? "EXACT" : "FUZZY";
);
// 使
const finalIndex = originalIndex !== -1 ? originalIndex : index;
const queryType = preciseIndexSet.has(finalIndex) ? "EXACT" : "FUZZY";
// 1 +
if (condition.valid && condition.field && condition.value) {
@ -2072,22 +2122,10 @@ const buildFieldConditionsPayload = () => {
// searchHint fieldConditions
const buildFieldConditionsForHint = () => {
//
const cursorIndex = findCursorConditionIndex();
const parts = currentInput.value.split(/[;]/);
const activeIndex =
cursorIndex >= 0 && cursorIndex < parts.length
? cursorIndex
: parts.length - 1;
// currentInput.value 使
const latestConditions = parseConditions(currentInput.value);
//
let conditionsToProcess = [...parsedConditions.value];
if (activeIndex >= 0 && activeIndex < conditionsToProcess.length - 1) {
const [editedCondition] = conditionsToProcess.splice(activeIndex, 1);
conditionsToProcess.push(editedCondition);
}
return conditionsToProcess
return latestConditions
.filter((condition) => {
// ":"
return condition.value || (condition.fieldLabel && condition.field);