App.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <div class="app-container" ref="appContainer">
  3. <div class="content-wrapper" ref="contentWrapper">
  4. <router-view />
  5. </div>
  6. </div>
  7. </template>
  8. <script setup lang="ts">
  9. import { ref, onMounted, onUnmounted } from 'vue'
  10. const appContainer = ref<HTMLElement>()
  11. const contentWrapper = ref<HTMLElement>()
  12. const DESIGN_WIDTH = 3840
  13. const DESIGN_HEIGHT = 2160
  14. const updateScale = () => {
  15. if (!appContainer.value || !contentWrapper.value) return
  16. const containerWidth = appContainer.value.clientWidth
  17. const containerHeight = appContainer.value.clientHeight
  18. const scaleX = containerWidth / DESIGN_WIDTH
  19. const scaleY = containerHeight / DESIGN_HEIGHT
  20. const scale = Math.min(scaleX, scaleY)
  21. // 计算居中位移
  22. const offsetX = (containerWidth - DESIGN_WIDTH * scale) / 2
  23. const offsetY = (containerHeight - DESIGN_HEIGHT * scale) / 2
  24. contentWrapper.value.style.transform = `translate(${offsetX}px, ${offsetY}px) scale(${scale})`
  25. contentWrapper.value.style.transformOrigin = 'left top'
  26. contentWrapper.value.style.width = `${DESIGN_WIDTH}px`
  27. contentWrapper.value.style.height = `${DESIGN_HEIGHT}px`
  28. }
  29. onMounted(() => {
  30. updateScale()
  31. window.addEventListener('resize', updateScale)
  32. })
  33. onUnmounted(() => {
  34. window.removeEventListener('resize', updateScale)
  35. })
  36. </script>
  37. <style>
  38. /* 全局样式 */
  39. * {
  40. margin: 0;
  41. padding: 0;
  42. box-sizing: border-box;
  43. }
  44. body {
  45. font-family: 'Arial', sans-serif;
  46. background-color: #000;
  47. color: #00ff88;
  48. overflow: hidden;
  49. }
  50. .app-container {
  51. width: 100vw;
  52. height: 100vh;
  53. display: flex;
  54. align-items: flex-start;
  55. justify-content: flex-start;
  56. overflow: hidden;
  57. background-color: #000;
  58. }
  59. .content-wrapper {
  60. transition: transform 0.3s ease;
  61. }
  62. </style>