diff --git a/frontend/src/main.ts b/frontend/src/main.ts index d778cd0..bf61760 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -2,6 +2,7 @@ import { createApp } from 'vue' import { createPinia } from 'pinia' import router from './router' import App from './App.vue' +import { useSiteSettingsStore } from './stores/siteSettings' // 引入 Ant Design Vue 样式 import 'ant-design-vue/dist/reset.css' @@ -9,9 +10,22 @@ import 'ant-design-vue/dist/reset.css' import './styles/index.scss' const app = createApp(App) +const pinia = createPinia() -app.use(createPinia()) +app.use(pinia) app.use(router) +// 初始化网站设置并设置标题 +const siteSettingsStore = useSiteSettingsStore() +siteSettingsStore.loadSiteSettings().then(() => { + document.title = siteSettingsStore.siteName || 'DesignHub' +}).catch(() => { + // 如果加载失败,尝试从 localStorage 读取 + const siteName = localStorage.getItem('siteName') + if (siteName) { + document.title = siteName + } +}) + app.mount('#app') diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index a018980..4dae471 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -1,6 +1,7 @@ import { createRouter, createWebHistory } from 'vue-router' import type { RouteRecordRaw } from 'vue-router' import { useAuthStore } from '@/stores/auth' +import { useSiteSettingsStore } from '@/stores/siteSettings' const routes: RouteRecordRaw[] = [ { @@ -228,8 +229,10 @@ const router = createRouter({ // 路由守卫 router.beforeEach(async (to, from, next) => { - // 设置页面标题 - document.title = `${to.meta.title || ''} - DesignHub` + // 设置页面标题(使用配置的网站名称) + const siteSettingsStore = useSiteSettingsStore() + const siteName = siteSettingsStore.siteName || 'DesignHub' + document.title = to.meta.title ? `${to.meta.title} - ${siteName}` : siteName // 身份验证逻辑 const authStore = useAuthStore()