Files
EmailBill/Web/src/App.vue

139 lines
3.6 KiB
Vue
Raw Normal View History

2025-12-25 11:20:56 +08:00
<template>
2025-12-25 17:12:19 +08:00
<van-config-provider :theme="theme" class="app-provider">
<pre style="position:fixed; left:0; top:0; z-index:9999;
background:rgba(0,0,0,0.7); color:#0f0;
font-size:10px; max-height:50vh; overflow:auto;">
{{ log }}
</pre>
2025-12-25 17:12:19 +08:00
<div class="app-root">
<RouterView />
2025-12-25 17:12:19 +08:00
<van-tabbar v-model="active" v-show="showTabbar">
<van-tabbar-item icon="notes-o" to="/calendar">
日历
</van-tabbar-item>
<van-tabbar-item icon="balance-list-o" to="/" @click="handleTabClick('/')">
账单
</van-tabbar-item>
<van-tabbar-item icon="records-o" to="/email" @click="handleTabClick('/email')">
邮件
</van-tabbar-item>
<van-tabbar-item icon="setting-o" to="/setting">
设置
</van-tabbar-item>
</van-tabbar>
</div>
2025-12-25 11:20:56 +08:00
</van-config-provider>
</template>
<script setup>
import { RouterView, useRoute } from 'vue-router'
2025-12-25 13:27:23 +08:00
import { ref, onMounted, onUnmounted, computed } from 'vue'
2025-12-25 11:20:56 +08:00
const log = ref('')
const updateInfo = () => {
2025-12-25 17:20:50 +08:00
// 获取真实的视口高度PWA 模式下准确)
const vh = window.innerHeight
// 设置 CSS 变量,让所有组件使用准确的视口高度
document.documentElement.style.setProperty('--vh', `${vh}px`)
document.documentElement.style.setProperty('--vh-offset', `${vh}px`)
log.value = JSON.stringify({
innerHeight: window.innerHeight,
outerHeight: window.outerHeight,
documentElementClientHeight: document.documentElement.clientHeight,
viewport: window.visualViewport
? {
2025-12-25 17:12:19 +08:00
height: window.visualViewport.height,
offsetTop: window.visualViewport.offsetTop,
}
: null,
2025-12-25 17:20:50 +08:00
cssVarVh: getComputedStyle(document.documentElement).getPropertyValue('--vh'),
}, null, 2)
}
onMounted(() => {
updateInfo()
window.addEventListener('resize', updateInfo)
2025-12-25 17:20:50 +08:00
// 监听 iOS Safari 视口变化
if (window.visualViewport) {
window.visualViewport.addEventListener('resize', updateInfo)
}
})
onUnmounted(() => {
window.removeEventListener('resize', updateInfo)
2025-12-25 17:20:50 +08:00
if (window.visualViewport) {
window.visualViewport.removeEventListener('resize', updateInfo)
}
})
2025-12-25 16:44:34 +08:00
const route = useRoute()
2025-12-25 13:27:23 +08:00
// 根据路由判断是否显示Tabbar
const showTabbar = computed(() => {
2025-12-25 16:37:09 +08:00
return route.path === '/' ||
route.path === '/calendar' ||
route.path === '/email' ||
route.path === '/setting'
2025-12-25 13:27:23 +08:00
})
2025-12-25 11:20:56 +08:00
const active = ref(0)
const theme = ref('light')
// 检测系统深色模式
const updateTheme = () => {
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches
theme.value = isDark ? 'dark' : 'light'
}
// 监听系统主题变化
let mediaQuery
onMounted(() => {
updateTheme()
mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
mediaQuery.addEventListener('change', updateTheme)
})
onUnmounted(() => {
if (mediaQuery) {
mediaQuery.removeEventListener('change', updateTheme)
}
})
// 处理tab点击如果点击当前页面则滚动到顶部
const handleTabClick = (path) => {
if (route.path === path) {
window.scrollTo({ top: 0, behavior: 'smooth' })
}
}
</script>
2025-12-25 14:15:43 +08:00
<style scoped>
2025-12-25 17:12:19 +08:00
.app-provider {
2025-12-25 17:20:50 +08:00
/* 使用准确的视口高度 CSS 变量 */
height: var(--vh, 100vh);
width: 100%;
2025-12-25 17:12:19 +08:00
}
.app-root {
height: 100%;
2025-12-25 17:20:50 +08:00
width: 100%;
position: relative;
2025-12-25 17:12:19 +08:00
border: 2px solid red; /* 调试用红框 */
2025-12-25 17:20:50 +08:00
}
/* TabBar 固定在底部 */
:deep(.van-tabbar) {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding-bottom: 0 !important;
/* 移除可能的安全区域内边距 */
padding-bottom: constant(safe-area-inset-bottom) !important;
padding-bottom: env(safe-area-inset-bottom) !important;
}
2025-12-25 14:15:43 +08:00
</style>