Files
EmailBill/Web/src/App.vue

73 lines
1.8 KiB
Vue
Raw Normal View History

2025-12-25 11:20:56 +08:00
<template>
<van-config-provider :theme="theme">
<RouterView />
<van-tabbar v-model="active" v-show="showTabbar" safe-area-inset-bottom>
2025-12-25 11:20:56 +08:00
<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>
</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 route = useRoute()
2025-12-25 13:27:23 +08:00
// 根据路由判断是否显示Tabbar
const showTabbar = computed(() => {
return route.path !== '/login'
})
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>
/* 仅在移动设备上添加底部安全区域适配 */
@media only screen and (max-width: 768px) {
:deep(.van-tabbar) {
/* 为小白条添加额外高度 */
2025-12-25 16:27:03 +08:00
padding-bottom: 10px;
}
}
2025-12-25 14:15:43 +08:00
</style>