|
@@ -1,5 +1,5 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <div class="mobile-layout" :class="{ 'is-tablet': isTablet }">
|
|
|
|
|
|
|
+ <div class="mobile-layout">
|
|
|
<Header />
|
|
<Header />
|
|
|
<main class="mobile-layout-main">
|
|
<main class="mobile-layout-main">
|
|
|
<slot />
|
|
<slot />
|
|
@@ -12,21 +12,21 @@
|
|
|
import Header from '~/components/mobile/Header.vue'
|
|
import Header from '~/components/mobile/Header.vue'
|
|
|
import Footer from '~/components/mobile/Footer.vue'
|
|
import Footer from '~/components/mobile/Footer.vue'
|
|
|
|
|
|
|
|
-const { width } = useWindowSize()
|
|
|
|
|
-
|
|
|
|
|
-// 平板断点: 768px - 1024px
|
|
|
|
|
-const isTablet = computed(() => width.value >= 768 && width.value <= 1024)
|
|
|
|
|
|
|
+const setRem = () => {
|
|
|
|
|
+ if (!process.client) return
|
|
|
|
|
+ const screenWidth = document.documentElement.clientWidth;
|
|
|
|
|
+ const baseFontSize = screenWidth / 10;
|
|
|
|
|
+ document.documentElement.style.fontSize = baseFontSize + 'px';
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-// 平板模式下增加内边距 (与 header 高度匹配)
|
|
|
|
|
-const mainPadding = computed(() => {
|
|
|
|
|
- const topPadding = isTablet.value ? '70px' : '54px' // header + gap
|
|
|
|
|
- return `${topPadding} ${isTablet.value ? '32px' : '16px'} ${isTablet.value ? '32px' : '16px'}`
|
|
|
|
|
|
|
+onMounted(() => {
|
|
|
|
|
+ setRem()
|
|
|
|
|
+ window.addEventListener('resize', setRem, { passive: true })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-// 平板模式下 Header 高度
|
|
|
|
|
-const headerHeight = computed(() => isTablet.value ? '60px' : '44px')
|
|
|
|
|
-
|
|
|
|
|
-provide('headerHeight', headerHeight)
|
|
|
|
|
|
|
+onBeforeUnmount(() => {
|
|
|
|
|
+ if (process.client) window.removeEventListener('resize', setRem)
|
|
|
|
|
+})
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
<style scoped lang="scss">
|
|
@@ -42,15 +42,7 @@ provide('headerHeight', headerHeight)
|
|
|
.mobile-layout-main {
|
|
.mobile-layout-main {
|
|
|
flex: 1;
|
|
flex: 1;
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
- padding: v-bind(mainPadding);
|
|
|
|
|
|
|
+ padding: 54px 16px 16px;
|
|
|
box-sizing: border-box;
|
|
box-sizing: border-box;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-// 平板模式样式
|
|
|
|
|
-.mobile-layout.is-tablet {
|
|
|
|
|
- .mobile-layout-main {
|
|
|
|
|
- max-width: 1024px;
|
|
|
|
|
- margin: 0 auto;
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
</style>
|
|
</style>
|