2025-02-14 23:14:54 +08:00
|
|
|
<template>
|
|
|
|
<NavBar/>
|
2025-02-26 18:27:47 +08:00
|
|
|
<div class="main-container">
|
2025-02-16 22:03:53 +08:00
|
|
|
<router-view />
|
|
|
|
</div>
|
2025-02-14 23:14:54 +08:00
|
|
|
|
|
|
|
<LoadingSpinner v-if="store.state.loading.isLoading"/>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
import {onMounted, watch} from 'vue'
|
|
|
|
import {useStore} from 'vuex'
|
|
|
|
import NavBar from "./components/NavBar.vue";
|
|
|
|
import LoadingSpinner from "./components/LoadingSpinner.vue";
|
|
|
|
import AuthService from "../services/auth.js";
|
|
|
|
|
|
|
|
const store = useStore()
|
|
|
|
|
|
|
|
// 根据主题更新 body 上的类
|
|
|
|
const updateGlobalTheme = (theme) => {
|
|
|
|
if (!(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
|
|
|
document.body.classList.add('theme-light')
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (theme === 'light') {
|
|
|
|
document.body.classList.add('theme-light')
|
|
|
|
} else {
|
|
|
|
document.body.classList.remove('theme-light')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 挂载时根据 store 中的主题状态更新全局样式
|
2025-02-21 19:52:33 +08:00
|
|
|
onMounted(async () => {
|
|
|
|
if (await AuthService.getToken()) {
|
2025-02-14 23:14:54 +08:00
|
|
|
AuthService.setSelfInfo();
|
2025-02-21 19:52:33 +08:00
|
|
|
} else {
|
|
|
|
AuthService.logout();
|
2025-02-14 23:14:54 +08:00
|
|
|
}
|
2025-03-07 18:26:36 +08:00
|
|
|
updateGlobalTheme(store.state.theme);
|
|
|
|
|
2025-02-14 23:14:54 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
// 监听 Vuex 主题状态的变化,更新全局样式
|
|
|
|
watch(
|
|
|
|
() => store.state.theme,
|
|
|
|
(newTheme) => {
|
|
|
|
updateGlobalTheme(newTheme)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
</script>
|
2025-02-26 18:27:47 +08:00
|
|
|
<style>
|
|
|
|
#app {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-content: center;
|
|
|
|
}
|
|
|
|
.main-container {
|
|
|
|
flex: 1;
|
|
|
|
flex-direction: column;
|
|
|
|
margin-top: 60px;
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
align-items: center;
|
|
|
|
align-content: center;
|
|
|
|
}
|
|
|
|
</style>
|