小说网站前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.4 KiB

  1. <template>
  2. <div id="app" :style="{ backgroundColor: route.path.includes('chapter') ? '#e9e4d8' : '#f5f5f5' }">
  3. <AuthProvider>
  4. <AuthorApplicationProvider>
  5. <router-view />
  6. </AuthorApplicationProvider>
  7. </AuthProvider>
  8. </div>
  9. </template>
  10. <script>
  11. import { onMounted, watch } from 'vue';
  12. import { useRoute } from 'vue-router';
  13. import { routerEvents } from '@/router';
  14. import { useMainStore } from './store';
  15. import AuthProvider from '@/components/auth/AuthProvider.vue';
  16. import AuthorApplicationProvider from '@/components/auth/AuthorApplicationProvider.vue';
  17. export default {
  18. name: 'App',
  19. components: {
  20. AuthProvider,
  21. AuthorApplicationProvider
  22. },
  23. setup() {
  24. const route = useRoute();
  25. const store = useMainStore();
  26. // 立即初始化全局变量,确保路由守卫可以使用
  27. window.$store = store;
  28. window.routerEvents = routerEvents;
  29. // 监听路由变化,检查是否需要触发登录弹窗
  30. onMounted(() => {
  31. // 立即初始化登录状态,确保在路由守卫执行前已经正确恢复用户状态
  32. store.initializeAuth();
  33. // 如果有触发登录的事件,执行它
  34. if (typeof routerEvents.triggerLogin === 'function') {
  35. routerEvents.triggerLogin();
  36. routerEvents.triggerLogin = null;
  37. }
  38. // 输出调试信息
  39. if (window.$debug?.logUserState) {
  40. window.$debug.logUserState();
  41. }
  42. });
  43. // 每次路由变化时也检查一次
  44. watch(route, () => {
  45. if (typeof routerEvents.triggerLogin === 'function') {
  46. routerEvents.triggerLogin();
  47. routerEvents.triggerLogin = null;
  48. }
  49. });
  50. return {
  51. route
  52. }
  53. }
  54. };
  55. </script>
  56. <style lang="scss">
  57. @use '@/assets/styles/global.scss';
  58. html, body {
  59. margin: 0;
  60. padding: 0;
  61. height: 100%;
  62. font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;
  63. }
  64. #app {
  65. display: flex;
  66. flex-direction: column;
  67. min-height: 100vh;
  68. background-color: #f5f5f5;
  69. .main-content {
  70. flex: 1;
  71. padding: 20px;
  72. max-width: 1200px;
  73. margin: 0 auto;
  74. width: 100%;
  75. }
  76. }
  77. </style>