Files
nl-blogs/client/src/App.vue

110 lines
3.3 KiB
Vue
Raw Normal View History

2026-01-15 13:51:44 +08:00
<template>
2026-01-20 16:45:23 +08:00
<!--
CRITICAL FIX: Removed 'overflow-hidden' from this root div.
'overflow-hidden' on an ancestor element breaks 'position: sticky'
in child components (like BlogDetail TOC) because it changes the
scrolling context.
-->
<div class="min-h-screen bg-art-bg text-art-text relative">
2026-01-20 11:12:01 +08:00
<!-- Star Background (Only for frontend) -->
<StarBackground v-if="!isAdminOrLogin" class="z-0" />
2026-01-16 11:06:59 +08:00
<!-- Global Noise (Only for frontend) -->
<div v-if="!isAdminOrLogin" class="fixed inset-0 pointer-events-none z-[60] bg-noise opacity-30 mix-blend-overlay"></div>
2026-01-20 11:12:01 +08:00
2026-01-15 13:51:44 +08:00
<!-- Toast Container -->
2026-01-20 11:12:01 +08:00
<div id="toast-container" class="toast-container relative z-[70]"></div>
2026-01-16 11:06:59 +08:00
<!-- Header (Hide on Admin & Login) -->
2026-01-20 19:59:50 +08:00
<Header v-if="!isAdminOrLogin" class="z-50" />
2026-01-20 11:12:01 +08:00
2026-01-16 11:06:59 +08:00
<!-- Mobile Menu (Hide on Admin & Login) -->
2026-01-20 19:59:50 +08:00
<MobileMenu v-if="!isAdminOrLogin" class="z-50" />
2026-01-20 11:12:01 +08:00
2026-01-15 13:51:44 +08:00
<!-- Main Content -->
2026-01-16 11:06:59 +08:00
<!-- Conditional classes: Apply max-w-7xl only for frontend pages -->
<main :class="[
isAdminOrLogin ? 'w-full h-full' : 'pt-32 pb-20 px-6 max-w-7xl mx-auto relative z-10'
]">
2026-01-15 13:51:44 +08:00
<router-view />
</main>
2026-01-20 11:12:01 +08:00
2026-01-16 11:06:59 +08:00
<!-- Footer (Hide on Admin & Login) -->
2026-01-20 11:12:01 +08:00
<Footer v-if="!isAdminOrLogin" class="relative z-10" />
2026-01-16 11:06:59 +08:00
<!-- Snippet Modal (Hide on Admin & Login) -->
2026-01-20 08:58:44 +08:00
<!-- SnippetModal is managed by Snippets.vue page, not here -->
2026-01-20 11:12:01 +08:00
2026-01-16 11:06:59 +08:00
<!-- Inquiry Modal (Hide on Admin & Login) -->
2026-01-20 11:12:01 +08:00
<InquiryModal v-if="!isAdminOrLogin" class="relative z-[80]" />
2026-01-15 13:51:44 +08:00
</div>
</template>
<script setup lang="ts">
2026-01-20 11:12:01 +08:00
import { computed, onMounted } from 'vue'
2026-01-16 11:06:59 +08:00
import { useRoute } from 'vue-router'
2026-01-15 13:51:44 +08:00
import Header from './components/Header.vue'
import MobileMenu from './components/MobileMenu.vue'
import Footer from './components/Footer.vue'
import InquiryModal from './components/InquiryModal.vue'
2026-01-20 16:45:23 +08:00
import StarBackground from './components/StarBackground.vue'
2026-01-20 11:12:01 +08:00
import { getPublicSettings } from './services/api'
2026-01-16 11:06:59 +08:00
const route = useRoute()
// Check if current route is Admin or Login page
const isAdminOrLogin = computed(() => {
const path = route.path
return path.startsWith('/admin') || path === '/login'
})
2026-01-20 11:12:01 +08:00
2026-01-20 16:45:23 +08:00
// 应用网站配置到页面标题和meta标签
2026-01-20 11:12:01 +08:00
const applySiteSettings = async () => {
try {
const settings = await getPublicSettings()
2026-01-20 16:45:23 +08:00
// 设置页面标题
if (settings.site_title) {
document.title = settings.site_title
}
2026-01-20 11:12:01 +08:00
// 更新meta标签
const updateMetaTag = (name: string, content: string) => {
if (!content) return
let meta = document.querySelector(`meta[name="${name}"]`)
if (!meta) {
meta = document.createElement('meta')
meta.setAttribute('name', name)
document.head.appendChild(meta)
}
meta.setAttribute('content', content)
}
// 更新description
if (settings.site_description) {
updateMetaTag('description', settings.site_description)
}
// 更新keywords
if (settings.site_keywords) {
updateMetaTag('keywords', settings.site_keywords)
}
// 更新author
if (settings.site_author) {
updateMetaTag('author', settings.site_author)
}
} catch (error) {
console.error('Failed to load site settings:', error)
// 使用默认标题,不抛出错误
}
}
onMounted(() => {
// 只在非管理页面应用设置
if (!isAdminOrLogin.value) {
applySiteSettings()
}
})
</script>