vue3.2/Vite/Ts92: 数据大屏自适应处理
·
Yin灏
目录结构
└─src
└─views
└─screen
└─index.vue
src/views/screen/index.vue
<template>
<div class="contianer">
<div class="screen" ref="screen">
<div class="top"></div>
<div class="bottom">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue";
import Top from "./components/top/index.vue";
let screen = ref<any>();
const getScale = (w = 1920, h = 1080) => {
const ww = window.innerWidth / w;
const wh = window.innerHeight / h;
return ww < wh ? ww : wh;
};
onMounted(() => {
screen.value.style.transform = `scale(${getScale()}) translate(-50%, -50%)`;
});
window.onresize = () => {
screen.value.style.transform = `scale(${getScale()}) translate(-50%, -50%)`;
};
</script>
<style scoped lang="scss">
.container {
width: 100vw;
height: 100vh;
background: url("./images/bg.png") no-repeat;
background-size: cover;
.screen {
position: fixed;
width: 1920px;
height: 1080px;
left: 50%;
top: 50%;
transform-origin: left top;
.top {
width: 100%;
height: 40px;
background: cyan;
}
.bottom {
display: flex;
.right {
flex: 1;
}
.left {
flex: 1;
}
.center {
flex: 2;
}
}
}
}
</style>