<template>
  <div class="page-container" :style="styles">
    <el-config-provider :locale="zhCn">
       <router-view />
    </el-config-provider>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue';
import zhCn from 'element-plus/es/locale/lang/zh-cn'
// 设计稿尺寸
const baseWidth = 1920;
const baseHeight = 1080;

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

// 计算缩放比例
function calcScale() {
  const { clientWidth, clientHeight } = document.documentElement;
  // const scaleW = window.innerWidth / baseWidth;
  // const scaleH = window.innerHeight / baseHeight;
  const scale = clientHeight / baseHeight;

  styles.value = {
    position: 'absolute',
      left: '50%',
      top: '50%',
      width: `${clientWidth * (1/scale)}px`,
      height: `${baseHeight}px`,
      overflow: "hidden",
      boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
      transform: `scale(${scale}) translate(-50%, -50%)`,
      transformOrigin: "0 0",
  };
}

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>
