<template>
  <div class="page-container" :style="styles">
    <router-view />
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue';
// 设计稿尺寸
const baseWidth = 1920;
const baseHeight = 1080;

// 动态样式
const styles = ref({
  width: `${baseWidth}px`,
  height: `${baseHeight}px`,
  transform: `scale(1) translate(-50%, -50%)`,
});

// 计算缩放比例
function calcScale() {
  const scaleW = window.innerWidth / baseWidth;
  const scaleH = window.innerHeight / baseHeight;

  styles.value = {
    width: `${baseWidth}px`,
    height: `${baseHeight}px`,
    transform: `scale(${Math.min(scaleW, scaleH)}) translate(-50%, -50%)`,
  };
}

calcScale();

// 监听窗口大小变化
onMounted(() => {
  window.addEventListener('resize', calcScale);
});

onBeforeUnmount(() => {
  window.removeEventListener('resize', calcScale);
});
</script>

<style lang="less">
.page-container {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  overflow: hidden;
  transform-origin: 0 0;
  font-family: 'Microsoft YaHei', sans-serif;
  font-size: 14px;
  color: #fff;
  user-select: none;
}

/* 隐藏滚动条 */
::-webkit-scrollbar {
  display: none;
}
</style>
