diff --git a/cwd-admin/src/router/index.ts b/cwd-admin/src/router/index.ts index d63c1c2..5018f05 100644 --- a/cwd-admin/src/router/index.ts +++ b/cwd-admin/src/router/index.ts @@ -71,7 +71,8 @@ export const router = createRouter({ }); router.beforeEach((to, from, next) => { - const defaultTitle = 'CWD 评论系统'; + const storedTitle = localStorage.getItem('cwd_admin_site_title'); + const defaultTitle = storedTitle || 'CWD 评论系统'; if (to.meta && to.meta.title) { document.title = (to.meta.title + ' - ' + defaultTitle) as string; } else { diff --git a/cwd-admin/src/views/LayoutView/index.vue b/cwd-admin/src/views/LayoutView/index.vue index f9685b7..1199ccc 100644 --- a/cwd-admin/src/views/LayoutView/index.vue +++ b/cwd-admin/src/views/LayoutView/index.vue @@ -179,6 +179,7 @@ import packageJson from "../../../package.json"; const DOMAIN_STORAGE_KEY = "cwd_admin_domain_filter"; const API_BASE_URL_KEY = "cwd_admin_api_base_url"; +const SITE_TITLE_KEY = "cwd_admin_site_title"; const router = useRouter(); const route = useRoute(); @@ -191,7 +192,7 @@ const apiVersion = ref(""); const checkedApiBaseUrl = ref(""); const apiVersionError = ref(""); const versionModalVisible = ref(false); -const layoutTitle = ref("CWD 评论系统"); +const layoutTitle = ref(localStorage.getItem(SITE_TITLE_KEY) || "CWD 评论系统"); const themeTitle = computed(() => { if (theme.value === "light") return "明亮模式"; @@ -255,16 +256,29 @@ async function loadVersion() { } } +function updateTitle(newTitle: string) { + layoutTitle.value = newTitle; + localStorage.setItem(SITE_TITLE_KEY, newTitle); + const pageTitle = route.meta.title; + if (pageTitle) { + document.title = `${pageTitle} - ${newTitle}`; + } else { + document.title = newTitle; + } +} + async function loadDisplaySettings() { try { const res = await fetchAdminDisplaySettings(); - layoutTitle.value = res.layoutTitle || "CWD 评论系统"; + const title = res.layoutTitle || "CWD 评论系统"; + updateTitle(title); } catch { - layoutTitle.value = "CWD 评论系统"; + // 忽略错误,保持当前值或默认值 } } provide("domainFilter", domainFilter); +provide("updateSiteTitle", updateTitle); onMounted(() => { loadDomains(); diff --git a/cwd-admin/src/views/SettingsView/index.vue b/cwd-admin/src/views/SettingsView/index.vue index 70bf3ec..e4446e4 100644 --- a/cwd-admin/src/views/SettingsView/index.vue +++ b/cwd-admin/src/views/SettingsView/index.vue @@ -510,7 +510,7 @@