参数对比bug修复

This commit is contained in:
JenniferW 2025-11-26 15:21:49 +08:00
parent 88abfab093
commit e90d6f9544
1 changed files with 80 additions and 20 deletions

View File

@ -420,6 +420,7 @@ import {
compare, compare,
} from "@/api/order"; } from "@/api/order";
import { ElMessage, ElEmpty, ElDialog } from "element-plus"; import { ElMessage, ElEmpty, ElDialog } from "element-plus";
import { Search, RefreshLeft, Microphone } from "@element-plus/icons-vue";
const { proxy } = getCurrentInstance(); const { proxy } = getCurrentInstance();
const { display_field } = proxy.useDict("display_field"); const { display_field } = proxy.useDict("display_field");
@ -461,6 +462,8 @@ const fieldValueMap = ref({});
const allValues = ref([]); const allValues = ref([]);
const hintTimer = ref(null); const hintTimer = ref(null);
const pendingSearchTimer = ref(null); const pendingSearchTimer = ref(null);
const differenceTimer = ref(null);
const selectedItems = ref(new Map());
// //
const showVoicePopup = ref(false); const showVoicePopup = ref(false);
@ -483,20 +486,20 @@ const currentPageData = computed(() => {
}); });
// //
const selectedCount = computed(() => { const selectedCount = computed(() => selectedItems.value.size);
return filteredData.value.filter((item) => item.selected).length;
});
// //
const selectedProductNumber = computed(() => { const selectedProductNumber = computed(() => {
const selected = filteredData.value.find((item) => item.selected); if (selectedItems.value.size !== 1) return "";
return selected ? selected.partNumber : ""; const iterator = selectedItems.value.values().next();
const first = iterator.value;
return first ? first.partNumber : "";
}); });
// //
const compareDialogVisible = ref(false); const compareDialogVisible = ref(false);
const selectedCompareList = computed(() => const selectedCompareList = computed(() =>
filteredData.value.filter((i) => i.selected) Array.from(selectedItems.value.values())
); );
// //
const showOnlyDifferences = ref(false); const showOnlyDifferences = ref(false);
@ -540,6 +543,8 @@ const sortedCompareList = computed(() => {
const compareTableData = ref([]); const compareTableData = ref([]);
const diffFieldKeys = ref(new Set()); const diffFieldKeys = ref(new Set());
const getItemKey = (item) => item?.id ?? item?.partNumber ?? item?.uuid ?? "";
const getDictLabel = (dictRef, value) => { const getDictLabel = (dictRef, value) => {
if (!dictRef) return null; if (!dictRef) return null;
const list = dictRef.value ?? []; const list = dictRef.value ?? [];
@ -666,7 +671,7 @@ const addDiffFieldToInput = (field) => {
// //
setTimeout(() => { setTimeout(() => {
handleInput(currentInput.value); handleInput(currentInput.value, { skipDifference: true });
triggerRealTimeSearch(); triggerRealTimeSearch();
// //
@ -706,7 +711,7 @@ const handleSemicolon = (e) => {
// //
setTimeout(() => { setTimeout(() => {
// //
handleInput(currentInput.value); handleInput(currentInput.value, { skipDifference: true });
// //
triggerRealTimeSearch(); triggerRealTimeSearch();
}, 0); }, 0);
@ -843,7 +848,7 @@ const triggerConditionSuggestions = (conditionText) => {
} }
} else { } else {
// 使 // 使
handleInput(currentInput.value); handleInput(currentInput.value, { skipDifference: true });
} }
}; };
@ -1012,6 +1017,14 @@ const updateSuggestionsFromValue = (value) => {
const handleInput = (value, options = {}) => { const handleInput = (value, options = {}) => {
const normalizedValue = value ?? ""; const normalizedValue = value ?? "";
updateSuggestionsFromValue(normalizedValue); updateSuggestionsFromValue(normalizedValue);
if (!normalizedValue.trim()) {
keyDiffFields.value = [];
showKeyDiffHint.value = false;
if (differenceTimer.value) {
clearTimeout(differenceTimer.value);
differenceTimer.value = null;
}
}
if (options.skipFetch) { if (options.skipFetch) {
return; return;
} }
@ -1020,6 +1033,9 @@ const handleInput = (value, options = {}) => {
if (currentPart) { if (currentPart) {
scheduleSearchHint(currentPart); scheduleSearchHint(currentPart);
} }
if (!options.skipDifference && normalizedValue.trim()) {
scheduleDifferenceFetch();
}
}; };
const fetchSearchHints = async (keyword) => { const fetchSearchHints = async (keyword) => {
@ -1032,7 +1048,7 @@ const fetchSearchHints = async (keyword) => {
? res ? res
: []; : [];
mergeFieldMetadata(hintList); mergeFieldMetadata(hintList);
updateSuggestionsFromValue(currentInput.value, { skipFetch: true }); updateSuggestionsFromValue(currentInput.value);
} catch (error) { } catch (error) {
console.error("searchHint error:", error); console.error("searchHint error:", error);
} }
@ -1048,6 +1064,16 @@ const scheduleSearchHint = (keyword) => {
}, 300); }, 300);
}; };
const scheduleDifferenceFetch = () => {
if (differenceTimer.value) {
clearTimeout(differenceTimer.value);
}
if (!currentInput.value.trim()) return;
differenceTimer.value = setTimeout(() => {
fetchDifferenceRecommendations();
}, 500);
};
// - 4 // - 4
const selectPossibleField = (field) => { const selectPossibleField = (field) => {
// //
@ -1078,7 +1104,7 @@ const selectPossibleField = (field) => {
// //
setTimeout(() => { setTimeout(() => {
handleInput(currentInput.value); handleInput(currentInput.value, { skipDifference: true });
// //
triggerRealTimeSearch(); triggerRealTimeSearch();
}, 0); }, 0);
@ -1174,7 +1200,7 @@ const selectSuggestion = (item) => {
// //
setTimeout(() => { setTimeout(() => {
handleInput(currentInput.value); handleInput(currentInput.value, { skipDifference: true });
// //
triggerRealTimeSearch(); triggerRealTimeSearch();
}, 0); }, 0);
@ -1358,10 +1384,25 @@ const executeSearch = async ({ page = currentPage.value } = {}) => {
const pageData = res?.data ?? res ?? {}; const pageData = res?.data ?? res ?? {};
const list = pageData?.content ?? []; const list = pageData?.content ?? [];
filteredData.value = list.map((item) => ({ const mappedList = list.map((item) => {
...item, const key = getItemKey(item);
selected: false, const isSelected = key ? selectedItems.value.has(key) : false;
})); return {
...item,
selected: isSelected,
};
});
const updatedSelectedMap = new Map(selectedItems.value);
mappedList.forEach((item) => {
const key = getItemKey(item);
if (key && updatedSelectedMap.has(key)) {
updatedSelectedMap.set(key, { ...item, selected: true });
}
});
selectedItems.value = updatedSelectedMap;
filteredData.value = mappedList;
totalItems.value = pageData?.totalElements ?? list.length; totalItems.value = pageData?.totalElements ?? list.length;
const serverPage = pageData?.number ?? Math.max(page - 1, 0); const serverPage = pageData?.number ?? Math.max(page - 1, 0);
currentPage.value = serverPage + 1; currentPage.value = serverPage + 1;
@ -1480,6 +1521,7 @@ const handleSearch = async () => {
// //
preciseConditions.value = []; preciseConditions.value = [];
selectedItems.value = new Map();
// //
await executeSearch({ page: 1 }); await executeSearch({ page: 1 });
@ -1496,6 +1538,7 @@ const triggerRealTimeSearch = () => {
if (currentInput.value.trim()) { if (currentInput.value.trim()) {
parsedConditions.value = parseConditions(currentInput.value); parsedConditions.value = parseConditions(currentInput.value);
scheduleSearchExecution(1); scheduleSearchExecution(1);
scheduleDifferenceFetch();
} }
}; };
@ -1509,9 +1552,6 @@ const removeCondition = (index) => {
.trim(); .trim();
parsedConditions.value = parseConditions(currentInput.value); parsedConditions.value = parseConditions(currentInput.value);
//
updateKeyDiffHint();
// //
const preciseIndex = preciseConditions.value.findIndex( const preciseIndex = preciseConditions.value.findIndex(
(cond) => cond.originalIndex === index (cond) => cond.originalIndex === index
@ -1522,6 +1562,7 @@ const removeCondition = (index) => {
// //
executeSearch({ page: 1 }); executeSearch({ page: 1 });
scheduleDifferenceFetch();
// //
if (selectedConditionIndex.value === index) { if (selectedConditionIndex.value === index) {
@ -1544,6 +1585,11 @@ const clearAll = () => {
// //
keyDiffFields.value = []; keyDiffFields.value = [];
showKeyDiffHint.value = false; showKeyDiffHint.value = false;
selectedItems.value = new Map();
if (differenceTimer.value) {
clearTimeout(differenceTimer.value);
differenceTimer.value = null;
}
if (searchInput.value) { if (searchInput.value) {
searchInput.value.focus(); searchInput.value.focus();
@ -1610,7 +1656,21 @@ watch(
// //
function toggleSelect(item) { function toggleSelect(item) {
item.selected = !item.selected; const key = getItemKey(item);
if (!key) return;
const nextMap = new Map(selectedItems.value);
const isSelected = nextMap.has(key);
if (isSelected) {
nextMap.delete(key);
item.selected = false;
} else {
const snapshot = { ...item, selected: true };
nextMap.set(key, snapshot);
item.selected = true;
}
selectedItems.value = nextMap;
} }
// //