增加精准查询

This commit is contained in:
JenniferW 2025-08-20 14:58:06 +08:00
parent 31177c3022
commit 2c5f7c81d0
1 changed files with 149 additions and 38 deletions

View File

@ -132,13 +132,38 @@
@click.stop="focusConditionTag(index)"
>{{ cond.value }}</span
>
<el-icon class="tag-edit-icon" size="14"><Edit /></el-icon>
<!-- 将编辑图标替换为"精准"文字并添加点击事件 -->
<span
class="tag-precise"
@click.stop="addPreciseCondition(index)"
>精准</span
>
</el-tag>
<el-button link @click="clearAll" class="clear-button">
<el-icon><RefreshLeft /></el-icon>
清除所有
</el-button>
</div>
<!-- 精准查询参数展示区域 -->
<div v-if="preciseConditions.length > 0" class="precise-conditions">
<div class="precise-conditions-label">选择精准查询参数</div>
<div class="precise-tags">
<el-tag
v-for="(cond, index) in preciseConditions"
:key="'precise-' + index"
closable
type="primary"
@close="removePreciseCondition(index)"
class="precise-tag"
>
<span v-if="cond.field" class="tag-field"
>{{ cond.fieldLabel }}:</span
>
<span class="tag-value">{{ cond.value }}</span>
</el-tag>
</div>
</div>
</div>
<!-- 查询结果区域 -->
@ -340,6 +365,8 @@ const activePossibleFieldIndex = ref(-1);
//
const parsedConditions = ref([]);
//
const preciseConditions = ref([]);
const showResults = ref(false);
const filteredData = ref([]);
@ -978,25 +1005,38 @@ const parseConditions = (input) => {
return conditions;
};
//
const addPreciseCondition = (index) => {
const condition = parsedConditions.value[index];
//
const exists = preciseConditions.value.some(
(cond) => cond.field === condition.field && cond.value === condition.value
);
if (!exists) {
preciseConditions.value.push({ ...condition, originalIndex: index });
//
applyPreciseFilter();
}
};
//
const removePreciseCondition = (index) => {
preciseConditions.value.splice(index, 1);
//
applyPreciseFilter();
};
//
const handleSearch = () => {
//
parsedConditions.value = parseConditions(currentInput.value);
//
if (!currentInput.value.trim()) {
filteredData.value = mockData.map((item) => ({ ...item, selected: false }));
} else {
// selected
filteredData.value = filterData(parsedConditions.value).map((item) => ({
...item,
selected: false,
}));
}
//
preciseConditions.value = [];
//
totalItems.value = filteredData.value.length;
currentPage.value = 1;
//
applyPreciseFilter();
//
showResults.value = true;
@ -1006,6 +1046,36 @@ const handleSearch = () => {
possibleFields.value = [];
};
//
const applyPreciseFilter = () => {
//
let filtered = filterData(parsedConditions.value);
//
if (preciseConditions.value.length > 0) {
filtered = filtered.filter((item) => {
return preciseConditions.value.every((condition) => {
if (!condition.valid) return false;
if (condition.field) {
const fieldValue = item[condition.field];
return checkPreciseCondition(fieldValue, condition.value);
} else {
return allFields.some((field) => {
const fieldValue = item[field.key];
return checkPreciseCondition(fieldValue, condition.value);
});
}
});
});
}
//
filteredData.value = filtered.map((item) => ({ ...item, selected: false }));
totalItems.value = filteredData.value.length;
currentPage.value = 1;
};
//
const filterData = (conditions) => {
return mockData.filter((item) => {
@ -1028,7 +1098,7 @@ const filterData = (conditions) => {
});
};
//
//
const checkCondition = (fieldValue, conditionValue) => {
// null
const processedValue = fieldValue ?? "";
@ -1049,7 +1119,6 @@ const checkCondition = (fieldValue, conditionValue) => {
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(Number(processedValue), Number(value));
}
return op.func(String(processedValue), value);
}
@ -1060,9 +1129,19 @@ const checkCondition = (fieldValue, conditionValue) => {
.includes(processedCondition.toLowerCase());
};
//
const checkPreciseCondition = (fieldValue, conditionValue) => {
// null
const processedValue = fieldValue ?? "";
const processedCondition = conditionValue ?? "";
// 使
return String(processedValue) === processedCondition;
};
//
const removeCondition = (index) => {
const parts = currentInput.value.split(/[;]/); //
const parts = currentInput.value.split(/[;]/);
parts.splice(index, 1);
currentInput.value = parts
.join(";")
@ -1070,18 +1149,16 @@ const removeCondition = (index) => {
.trim();
parsedConditions.value = parseConditions(currentInput.value);
//
if (!currentInput.value.trim()) {
filteredData.value = mockData.map((item) => ({ ...item, selected: false }));
} else {
filteredData.value = filterData(parsedConditions.value).map((item) => ({
...item,
selected: false,
}));
//
const preciseIndex = preciseConditions.value.findIndex(
(cond) => cond.originalIndex === index
);
if (preciseIndex !== -1) {
preciseConditions.value.splice(preciseIndex, 1);
}
totalItems.value = filteredData.value.length;
currentPage.value = 1;
//
applyPreciseFilter();
//
if (selectedConditionIndex.value === index) {
@ -1093,6 +1170,7 @@ const removeCondition = (index) => {
const clearAll = () => {
currentInput.value = "";
parsedConditions.value = [];
preciseConditions.value = [];
filteredData.value = [];
totalItems.value = 0;
currentPage.value = 1;
@ -1165,10 +1243,10 @@ watch(
function toggleSelect(item) {
//
const selectedCount = filteredData.value.filter((i) => i.selected).length;
if (!item.selected && selectedCount >= 3) {
ElMessage.warning("最多只能选择3个卡片进行对比");
return;
}
// if (!item.selected && selectedCount >= 3) {
// ElMessage.warning("3");
// return;
// }
item.selected = !item.selected;
}
@ -1565,7 +1643,6 @@ function handleConfirm() {
.result-card-list {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 30px;
}
.result-card {
@ -1801,7 +1878,7 @@ function handleConfirm() {
.condition-tag {
cursor: pointer;
transition: all 0.2s;
padding-right: 30px !important;
padding-right: 60px !important; /* 增加右侧 padding 以容纳"精准"文字 */
position: relative;
}
@ -1826,18 +1903,52 @@ function handleConfirm() {
color: #1890ff;
}
.tag-edit-icon {
/* 精准查询相关样式 */
.tag-precise {
position: absolute;
right: 10px;
right: 20px; /* 为关闭按钮留出空间 */
top: 50%;
transform: translateY(-50%);
color: #409eff;
opacity: 0.7;
font-size: 12px;
cursor: pointer;
padding: 2px 4px;
border-radius: 2px;
background-color: rgba(64, 158, 255, 0.1);
transition: all 0.2s;
}
.tag-precise:hover {
background-color: rgba(64, 158, 255, 0.2);
color: #1890ff;
}
.precise-conditions {
margin: 15px 0;
}
.precise-conditions-label {
font-size: 14px;
color: #666;
margin-bottom: 8px;
font-weight: 500;
}
.precise-tags {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.precise-tag {
cursor: default;
padding-right: 30px !important;
position: relative;
}
.results-section {
/* 移除滚动条相关样式 */
padding: 0 10px 20px;
max-width: 1250px;
margin: 0 auto;
}
.no-results {