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">
|
|
|
|
|
|
<div class="app-root">
|
2025-12-25 16:53:56 +08:00
|
|
|
|
<RouterView />
|
2025-12-25 17:12:19 +08:00
|
|
|
|
<van-tabbar v-model="active" v-show="showTabbar">
|
2025-12-26 15:21:31 +08:00
|
|
|
|
<van-tabbar-item icon="notes" to="/calendar">
|
2025-12-25 17:12:19 +08:00
|
|
|
|
日历
|
|
|
|
|
|
</van-tabbar-item>
|
2025-12-26 15:21:31 +08:00
|
|
|
|
<van-tabbar-item icon="chart-trending-o" to="/statistics">
|
|
|
|
|
|
统计
|
|
|
|
|
|
</van-tabbar-item>
|
|
|
|
|
|
<van-tabbar-item icon="balance-list" to="/" @click="handleTabClick('/')">
|
2025-12-25 17:12:19 +08:00
|
|
|
|
账单
|
|
|
|
|
|
</van-tabbar-item>
|
2025-12-26 15:21:31 +08:00
|
|
|
|
<van-tabbar-item icon="records" to="/email" @click="handleTabClick('/email')">
|
2025-12-25 17:12:19 +08:00
|
|
|
|
邮件
|
|
|
|
|
|
</van-tabbar-item>
|
2025-12-26 15:21:31 +08:00
|
|
|
|
<van-tabbar-item icon="setting" to="/setting">
|
2025-12-25 17:12:19 +08:00
|
|
|
|
设置
|
|
|
|
|
|
</van-tabbar-item>
|
|
|
|
|
|
</van-tabbar>
|
2025-12-25 16:53:56 +08:00
|
|
|
|
</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
|
|
|
|
|
2025-12-25 17:30:29 +08:00
|
|
|
|
const updateVh = () => {
|
2025-12-25 17:20:50 +08:00
|
|
|
|
// 获取真实的视口高度(PWA 模式下准确)
|
|
|
|
|
|
const vh = window.innerHeight
|
|
|
|
|
|
// 设置 CSS 变量,让所有组件使用准确的视口高度
|
|
|
|
|
|
document.documentElement.style.setProperty('--vh', `${vh}px`)
|
2025-12-25 16:53:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
2025-12-25 17:30:29 +08:00
|
|
|
|
updateVh()
|
|
|
|
|
|
window.addEventListener('resize', updateVh)
|
2025-12-25 17:20:50 +08:00
|
|
|
|
// 监听 iOS Safari 视口变化
|
|
|
|
|
|
if (window.visualViewport) {
|
2025-12-25 17:30:29 +08:00
|
|
|
|
window.visualViewport.addEventListener('resize', updateVh)
|
2025-12-25 17:20:50 +08:00
|
|
|
|
}
|
2025-12-25 16:53:56 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
2025-12-25 17:30:29 +08:00
|
|
|
|
window.removeEventListener('resize', updateVh)
|
2025-12-25 17:20:50 +08:00
|
|
|
|
if (window.visualViewport) {
|
2025-12-25 17:30:29 +08:00
|
|
|
|
window.visualViewport.removeEventListener('resize', updateVh)
|
2025-12-25 17:20:50 +08:00
|
|
|
|
}
|
2025-12-25 16:53:56 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
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' ||
|
2025-12-26 15:21:31 +08:00
|
|
|
|
route.path === '/setting' ||
|
|
|
|
|
|
route.path === '/statistics'
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-25 16:53:56 +08:00
|
|
|
|
.app-root {
|
|
|
|
|
|
height: 100%;
|
2025-12-25 17:20:50 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
|
position: relative;
|
2025-12-25 17:46:02 +08:00
|
|
|
|
margin-top: max(0px, calc(env(safe-area-inset-top, 0px) * 0.75));
|
2025-12-25 17:20:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* TabBar 固定在底部 */
|
|
|
|
|
|
:deep(.van-tabbar) {
|
2025-12-25 17:28:06 +08:00
|
|
|
|
position: fixed !important;
|
|
|
|
|
|
bottom: 0 !important;
|
2025-12-25 17:20:50 +08:00
|
|
|
|
left: 0;
|
|
|
|
|
|
right: 0;
|
2025-12-25 17:28:06 +08:00
|
|
|
|
/* 重置所有 padding,然后只添加安全区域 */
|
|
|
|
|
|
padding: 0 !important;
|
|
|
|
|
|
padding-bottom: env(safe-area-inset-bottom, 0px) !important;
|
|
|
|
|
|
height: 50px !important;
|
|
|
|
|
|
min-height: 50px !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 确保 TabBar 项目居中 */
|
|
|
|
|
|
:deep(.van-tabbar-item) {
|
|
|
|
|
|
padding: 0 !important;
|
2025-12-25 16:53:56 +08:00
|
|
|
|
}
|
2025-12-25 14:15:43 +08:00
|
|
|
|
</style>
|