feat: 优化卡片尺寸计算逻辑,调整样式以适应不同屏幕宽度

This commit is contained in:
傅光孟 2026-04-16 10:23:45 +08:00
parent dfd438844c
commit cd29296c1a
2 changed files with 24 additions and 26 deletions

View File

@ -124,7 +124,7 @@
</template>
<script setup>
import { ref, reactive, onMounted, computed } from 'vue';
import { ref, reactive, onMounted, onUnmounted, computed } from 'vue';
import { useRouter } from 'vue-router';
import { getYqcompanyList, getYqCheck } from '/@/api/api';
import { ElMessage } from 'element-plus';
@ -247,40 +247,38 @@ function handleCommand(value) {
//
const boxRef = ref(null);
const style = reactive({
width: 285,
height: 162,
const cardConfig = reactive({
baseWidth: 285,
aspectRatio: 162 / 285,
margin: 20,
});
const containerWidth = ref(0);
const styleWidth = computed(() => {
console.log('output >>>>> boxRef.value?.clientWidth >= 1440',boxRef.value?.clientWidth);
if (boxRef.value?.clientWidth >= 1080) {
const width = (boxRef.value?.clientWidth - 3 * style.margin) / 4;
style.width = width;
const calcCardWidth = (parentWidth) => {
if (parentWidth >= 1080) {
return Math.floor((parentWidth - 3 * cardConfig.margin) / 4);
}
return cardConfig.baseWidth;
};
return Math.floor(style.width);
});
const calcCardHeight = (cardWidth) => Math.floor(cardWidth * cardConfig.aspectRatio);
const styleHeight = computed(() => {
if (boxRef.value?.clientWidth >= 1080) {
const width = (boxRef.value?.clientWidth - 3 * style.margin) / 4;
style.height = (width / 285) * 162;
}
const styleWidth = computed(() => calcCardWidth(containerWidth.value));
const styleHeight = computed(() => calcCardHeight(styleWidth.value));
return Math.floor(style.height);
});
const updateCardSize = () => {
containerWidth.value = boxRef.value?.clientWidth ?? 0;
};
//
onMounted(() => {
// NextLoading.done();
getData();
window.addEventListener('resize', () => {
style.width = 285;
style.height = 162;
});
updateCardSize();
window.addEventListener('resize', updateCardSize);
});
onUnmounted(() => {
window.removeEventListener('resize', updateCardSize);
});
</script>

View File

@ -296,11 +296,11 @@ input::placeholder {
justify-content: center;
flex-direction: column;
align-items: center;
padding: 30px 32px 32px;
}
.list {
width: 70vw;
min-width: 1000px;
width: 100%;
height: 70vh;
overflow: auto;