步骤二优化

This commit is contained in:
JenniferW 2025-08-14 16:24:32 +08:00
parent 5ad4767667
commit 889400c9ab
1 changed files with 39 additions and 42 deletions

View File

@ -330,7 +330,7 @@ const selectedCompareList = computed(() =>
// - query.vue
const compareTableData = computed(() => {
if (selectedCompareList.value.length <= 1) return [];
if (selectedCompareList.value.length === 0) return [];
//
const paramsToCompare = [
@ -566,28 +566,34 @@ const allValues = ref([]);
const initializeValues = () => {
const values = [];
allFields.forEach((field) => {
const uniqueValues = [...new Set(mockData.map((item) => item[field.key]))];
const uniqueValues = [
...new Set(
mockData.map((item) => item[field.key] ?? "") // null
),
];
uniqueValues.forEach((value) => {
values.push({
value: String(value),
fieldKey: field.key,
fieldLabel: field.label,
weight: fieldValueMap[field.key]?.includes(String(value)) ? 2 : 1,
});
//
if (value !== "") {
values.push({
value: String(value),
fieldKey: field.key,
fieldLabel: field.label,
weight: fieldValueMap[field.key]?.includes(String(value)) ? 2 : 1,
});
}
});
});
allValues.value = values;
};
// query.vue
const getCurrentInputPart = () => {
const parts = currentInput.value.split(";");
const parts = currentInput.value.split(/[;]/);
return parts[parts.length - 1].trim();
};
const handleKeydown = (e) => {
//
if (e.key === ";" || e.keyCode === 186) {
if (e.key === ";" || e.key === "" || e.keyCode === 186) {
handleSemicolon(e);
}
};
@ -616,7 +622,7 @@ const findCursorConditionIndex = () => {
const cursorPos = inputEl.selectionStart;
const inputValue = currentInput.value;
const parts = inputValue.split(";");
const parts = inputValue.split(/[;]/);
let currentLength = 0;
for (let i = 0; i < parts.length; i++) {
@ -1001,9 +1007,7 @@ const selectSuggestion = (item) => {
}
} else {
//
parts[targetIndex] = targetPart
? `${targetPart}${item.label}`
: item.label;
parts[targetIndex] = item.label;
}
}
@ -1096,7 +1100,7 @@ const hideSuggestions = () => {
const parseConditions = (input) => {
const conditions = [];
const parts = input
.split(";")
.split(/[;]/) //
.map((part) => part.trim())
.filter((part) => part);
@ -1175,7 +1179,11 @@ const filterData = (conditions) => {
//
const checkCondition = (fieldValue, conditionValue) => {
//
// null
const processedValue = fieldValue ?? "";
const processedCondition = conditionValue ?? "";
// 使processedValueprocessedCondition
const operators = [
{ symbol: ">=", func: (a, b) => a >= b },
{ symbol: "<=", func: (a, b) => a <= b },
@ -1185,30 +1193,29 @@ const checkCondition = (fieldValue, conditionValue) => {
{ symbol: "=", func: (a, b) => a == b },
];
// 使
for (const op of operators) {
if (conditionValue.startsWith(op.symbol)) {
const value = conditionValue.substring(op.symbol.length).trim();
//
if (!isNaN(Number(fieldValue)) && !isNaN(Number(value))) {
return op.func(Number(fieldValue), Number(value));
if (processedCondition.startsWith(op.symbol)) {
const value = processedCondition.substring(op.symbol.length).trim();
if (!isNaN(Number(processedValue)) && !isNaN(Number(value))) {
return op.func(Number(processedValue), Number(value));
}
//
return op.func(String(fieldValue), value);
return op.func(String(processedValue), value);
}
}
//
return String(fieldValue)
return String(processedValue)
.toLowerCase()
.includes(conditionValue.toLowerCase());
.includes(processedCondition.toLowerCase());
};
//
const removeCondition = (index) => {
const parts = currentInput.value.split(";");
const parts = currentInput.value.split(/[;]/); //
parts.splice(index, 1);
currentInput.value = parts.join(";").replace(/;;+/g, ";").trim();
currentInput.value = parts
.join(";")
.replace(/[;]+/g, ";")
.trim();
parsedConditions.value = parseConditions(currentInput.value);
filteredData.value = filterData(parsedConditions.value).map((item) => ({
...item,
@ -1257,15 +1264,6 @@ onMounted(() => {
showSuggestions.value = false;
}
});
//
if (props.form.selectedCarType) {
// 使
currentInput.value = `车型:${props.form.selectedCarType}`;
setTimeout(() => {
handleSearch();
}, 100);
}
});
//
@ -1830,11 +1828,10 @@ function onNextStep() {
background: #f5f7fa !important;
}
// query.vue
.search-box-container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
padding: 0 20px;
}
.search-box {
@ -1982,8 +1979,8 @@ function onNextStep() {
}
.results-section {
margin-top: 30px;
overflow: hidden;
padding: 0 10px;
}
.results-table {