参数对比优化

This commit is contained in:
JenniferW 2025-08-20 15:26:35 +08:00
parent 2c5f7c81d0
commit 6724caa51c
1 changed files with 103 additions and 16 deletions

View File

@ -173,6 +173,7 @@
class="result-card-list-wrap" class="result-card-list-wrap"
style="position: relative" style="position: relative"
> >
<!-- 参数对比按钮 - 随滚动条移动 -->
<el-button <el-button
v-if="selectedCompareList.length > 0" v-if="selectedCompareList.length > 0"
type="warning" type="warning"
@ -252,13 +253,25 @@
<el-dialog <el-dialog
v-model="compareDialogVisible" v-model="compareDialogVisible"
title="参数对比" title="参数对比"
width="80%" width="1200px"
top="40px" top="40px"
:close-on-click-modal="false" :close-on-click-modal="false"
> >
<!-- 表格对比区图片放在表头下方 --> <!-- 仅看不同项选项 -->
<div class="compare-filter-options" style="margin-bottom: 16px">
<el-radio-group v-model="showOnlyDifferences">
<el-radio :label="false">显示所有项</el-radio>
<el-radio :label="true">仅看不同项</el-radio>
</el-radio-group>
</div>
<!-- 表格对比区添加横向滚动 -->
<div class="compare-table-wrap"> <div class="compare-table-wrap">
<el-table :data="compareTableData" border style="width: 100%"> <el-table
:data="filteredCompareTableData"
border
style="width: 100%; min-width: 900px"
>
<el-table-column <el-table-column
prop="param" prop="param"
label="参数" label="参数"
@ -274,6 +287,7 @@
:prop="item.productNumber" :prop="item.productNumber"
align="center" align="center"
header-align="center" header-align="center"
min-width="200"
> >
<template #header="{ column }"> <template #header="{ column }">
<div <div
@ -291,6 +305,19 @@
}}</span> }}</span>
</div> </div>
</template> </template>
<!-- 单元格内容不同的值标红 -->
<template #default="scope">
<span
:class="{
'different-value': isValueDifferent(
scope.row.param,
scope.row[scope.column.property]
),
}"
>
{{ scope.row[scope.column.property] || "-" }}
</span>
</template>
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
@ -397,24 +424,74 @@ const compareDialogVisible = ref(false);
const selectedCompareList = computed(() => const selectedCompareList = computed(() =>
filteredData.value.filter((i) => i.selected) filteredData.value.filter((i) => i.selected)
); );
//
const showOnlyDifferences = ref(false);
//
const parameterDifferences = ref({});
// //
const confirmDialogVisible = ref(false); const confirmDialogVisible = ref(false);
// //
const compareTableData = computed(() => { const compareTableData = computed(() => {
if (selectedCompareList.value.length === 0) return []; if (selectedCompareList.value.length === 0) {
parameterDifferences.value = {};
return [];
}
//
const differences = {};
// //
return paramsToCompare.map((param) => { const result = paramsToCompare.map((param) => {
const row = { param }; const row = { param };
const values = [];
//
selectedCompareList.value.forEach((item) => { selectedCompareList.value.forEach((item) => {
row[item.productNumber] = item[fieldMap[param]] || "-"; const value = item[fieldMap[param]] || "-";
row[item.productNumber] = value;
values.push(value);
}); });
//
const allSame = values.every((v) => v === values[0]);
differences[param] = !allSame;
return row; return row;
}); });
//
parameterDifferences.value = differences;
return result;
}); });
// ""
const filteredCompareTableData = computed(() => {
if (!showOnlyDifferences.value) {
return compareTableData.value;
}
//
return compareTableData.value.filter(
(row) => parameterDifferences.value[row.param]
);
});
//
const isValueDifferent = (param, value) => {
// false
if (!parameterDifferences.value[param]) return false;
//
const values = selectedCompareList.value.map(
(item) => item[fieldMap[param]] || "-"
);
//
return value !== values[0];
};
// //
const allValues = ref([]); const allValues = ref([]);
@ -1243,10 +1320,6 @@ watch(
function toggleSelect(item) { function toggleSelect(item) {
// //
const selectedCount = filteredData.value.filter((i) => i.selected).length; const selectedCount = filteredData.value.filter((i) => i.selected).length;
// if (!item.selected && selectedCount >= 3) {
// ElMessage.warning("3");
// return;
// }
item.selected = !item.selected; item.selected = !item.selected;
} }
@ -1719,13 +1792,15 @@ function handleConfirm() {
} }
.compare-table-wrap { .compare-table-wrap {
margin-top: 16px; margin-top: 16px;
overflow-x: auto; /* 允许横向滚动 */
max-width: 100%; /* 限制最大宽度 */
} }
/* 参数对比按钮样式 - 随滚动条移动 */
.compare-btn-float { .compare-btn-float {
/* 关键修改:相对于滚动容器固定定位 */ position: fixed; /* 修改为fixed定位相对于视口固定 */
position: sticky; top: 20px;
top: 20px; /* 距离滚动容器顶部的距离 */
right: 20px; right: 20px;
z-index: 10; z-index: 100; /* 提高层级确保可见 */
width: 52px; width: 52px;
height: 52px; height: 52px;
display: flex; display: flex;
@ -1738,7 +1813,6 @@ function handleConfirm() {
transition: all 0.25s ease; transition: all 0.25s ease;
font-size: 13px; font-size: 13px;
line-height: 1.3; line-height: 1.3;
margin-left: auto; /* 右对齐 */
} }
.compare-btn-float:hover { .compare-btn-float:hover {
@ -1889,6 +1963,7 @@ function handleConfirm() {
.tag-field { .tag-field {
font-weight: 500; font-weight: 500;
font-weight: 500;
} }
.tag-value { .tag-value {
@ -2010,6 +2085,18 @@ function handleConfirm() {
padding: 20px 0; padding: 20px 0;
} }
/* 新增:不同参数值的样式 */
.different-value {
color: #ff4d4f; /* 红色 */
font-weight: 500;
}
/* 新增:对比筛选选项样式 */
.compare-filter-options {
text-align: right;
padding-right: 10px;
}
@media (max-width: 768px) { @media (max-width: 768px) {
.search-box { .search-box {
flex-direction: column; flex-direction: column;