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