mobile.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <div class="mobile-layout" :class="{ 'is-tablet': isTablet }">
  3. <Header />
  4. <main class="mobile-layout-main">
  5. <slot />
  6. </main>
  7. <Footer />
  8. </div>
  9. </template>
  10. <script setup>
  11. import Header from '~/components/mobile/Header.vue'
  12. import Footer from '~/components/mobile/Footer.vue'
  13. const { width } = useWindowSize()
  14. // 平板断点: 768px - 1024px
  15. const isTablet = computed(() => width.value >= 768 && width.value <= 1024)
  16. // 平板模式下增加内边距 (与 header 高度匹配)
  17. const mainPadding = computed(() => {
  18. const topPadding = isTablet.value ? '70px' : '54px' // header + gap
  19. return `${topPadding} ${isTablet.value ? '32px' : '16px'} ${isTablet.value ? '32px' : '16px'}`
  20. })
  21. // 平板模式下 Header 高度
  22. const headerHeight = computed(() => isTablet.value ? '60px' : '44px')
  23. provide('headerHeight', headerHeight)
  24. </script>
  25. <style scoped lang="scss">
  26. .mobile-layout {
  27. width: 100%;
  28. min-height: 100vh;
  29. background-color: #030014;
  30. display: flex;
  31. flex-direction: column;
  32. box-sizing: border-box;
  33. }
  34. .mobile-layout-main {
  35. flex: 1;
  36. width: 100%;
  37. padding: v-bind(mainPadding);
  38. box-sizing: border-box;
  39. }
  40. // 平板模式样式
  41. .mobile-layout.is-tablet {
  42. .mobile-layout-main {
  43. max-width: 1024px;
  44. margin: 0 auto;
  45. }
  46. }
  47. </style>