Spaces:
Sleeping
Sleeping
refactor(HistoryDatabase): dynamically calculate container height based on card expansion state
Browse files- Introduced a computed property to adjust the container's minimum height based on the number of cards and expansion state.
- Removed static min-height styles to enhance responsiveness and visual consistency.
frontend/src/components/HistoryDatabase.vue
CHANGED
|
@@ -17,7 +17,7 @@
|
|
| 17 |
</div>
|
| 18 |
|
| 19 |
<!-- 卡片容器 -->
|
| 20 |
-
<div class="cards-container" :class="{ expanded: isExpanded }">
|
| 21 |
<div
|
| 22 |
v-for="(project, index) in projects"
|
| 23 |
:key="project.simulation_id"
|
|
@@ -91,7 +91,7 @@
|
|
| 91 |
</template>
|
| 92 |
|
| 93 |
<script setup>
|
| 94 |
-
import { ref, onMounted, onUnmounted } from 'vue'
|
| 95 |
import { useRouter } from 'vue-router'
|
| 96 |
import { getSimulationHistory } from '../api/simulation'
|
| 97 |
|
|
@@ -113,6 +113,26 @@ const CARD_WIDTH = 280
|
|
| 113 |
const CARD_HEIGHT = 280
|
| 114 |
const CARD_GAP = 24
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
// 获取卡片样式
|
| 117 |
const getCardStyle = (index) => {
|
| 118 |
const total = projects.value.length
|
|
@@ -441,13 +461,9 @@ onUnmounted(() => {
|
|
| 441 |
display: flex;
|
| 442 |
justify-content: center;
|
| 443 |
align-items: flex-start;
|
| 444 |
-
min-height: 420px;
|
| 445 |
padding: 0 40px;
|
| 446 |
transition: min-height 700ms cubic-bezier(0.23, 1, 0.32, 1);
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
.cards-container.expanded {
|
| 450 |
-
min-height: 620px;
|
| 451 |
}
|
| 452 |
|
| 453 |
/* 项目卡片 */
|
|
|
|
| 17 |
</div>
|
| 18 |
|
| 19 |
<!-- 卡片容器 -->
|
| 20 |
+
<div class="cards-container" :class="{ expanded: isExpanded }" :style="containerStyle">
|
| 21 |
<div
|
| 22 |
v-for="(project, index) in projects"
|
| 23 |
:key="project.simulation_id"
|
|
|
|
| 91 |
</template>
|
| 92 |
|
| 93 |
<script setup>
|
| 94 |
+
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
| 95 |
import { useRouter } from 'vue-router'
|
| 96 |
import { getSimulationHistory } from '../api/simulation'
|
| 97 |
|
|
|
|
| 113 |
const CARD_HEIGHT = 280
|
| 114 |
const CARD_GAP = 24
|
| 115 |
|
| 116 |
+
// 动态计算容器高度样式
|
| 117 |
+
const containerStyle = computed(() => {
|
| 118 |
+
if (!isExpanded.value) {
|
| 119 |
+
// 折叠态:固定高度
|
| 120 |
+
return { minHeight: '420px' }
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// 展开态:根据卡片数量动态计算高度
|
| 124 |
+
const total = projects.value.length
|
| 125 |
+
if (total === 0) {
|
| 126 |
+
return { minHeight: '280px' }
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
const rows = Math.ceil(total / CARDS_PER_ROW)
|
| 130 |
+
// 计算实际需要的高度:行数 * 卡片高度 + (行数-1) * 间距 + 额外padding
|
| 131 |
+
const expandedHeight = rows * CARD_HEIGHT + (rows - 1) * CARD_GAP + 40
|
| 132 |
+
|
| 133 |
+
return { minHeight: `${expandedHeight}px` }
|
| 134 |
+
})
|
| 135 |
+
|
| 136 |
// 获取卡片样式
|
| 137 |
const getCardStyle = (index) => {
|
| 138 |
const total = projects.value.length
|
|
|
|
| 461 |
display: flex;
|
| 462 |
justify-content: center;
|
| 463 |
align-items: flex-start;
|
|
|
|
| 464 |
padding: 0 40px;
|
| 465 |
transition: min-height 700ms cubic-bezier(0.23, 1, 0.32, 1);
|
| 466 |
+
/* min-height 由 JS 动态计算,根据卡片数量自适应 */
|
|
|
|
|
|
|
|
|
|
| 467 |
}
|
| 468 |
|
| 469 |
/* 项目卡片 */
|