fix: 修复前端切换页面时logo跟标题闪烁的问题
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { RouterView, useRouter, useRoute } from 'vue-router'
|
||||
import { onMounted } from 'vue'
|
||||
import { onMounted, watch } from 'vue'
|
||||
import Toast from '@/components/common/Toast.vue'
|
||||
import { getPublicSettings } from '@/api/auth'
|
||||
import { useAppStore } from '@/stores'
|
||||
import { getSetupStatus } from '@/api/setup'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const appStore = useAppStore()
|
||||
|
||||
/**
|
||||
* Update favicon dynamically
|
||||
@@ -24,6 +25,19 @@ function updateFavicon(logoUrl: string) {
|
||||
link.href = logoUrl
|
||||
}
|
||||
|
||||
// Watch for site settings changes and update favicon/title
|
||||
watch(() => appStore.siteLogo, (newLogo) => {
|
||||
if (newLogo) {
|
||||
updateFavicon(newLogo)
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
watch(() => appStore.siteName, (newName) => {
|
||||
if (newName) {
|
||||
document.title = `${newName} - AI API Gateway`
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
onMounted(async () => {
|
||||
// Check if setup is needed
|
||||
try {
|
||||
@@ -36,21 +50,8 @@ onMounted(async () => {
|
||||
// If setup endpoint fails, assume normal mode and continue
|
||||
}
|
||||
|
||||
try {
|
||||
const settings = await getPublicSettings()
|
||||
|
||||
// Update favicon if logo is set
|
||||
if (settings.site_logo) {
|
||||
updateFavicon(settings.site_logo)
|
||||
}
|
||||
|
||||
// Update page title if site name is set
|
||||
if (settings.site_name) {
|
||||
document.title = `${settings.site_name} - AI API Gateway`
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load public settings for favicon:', error)
|
||||
}
|
||||
// Load public settings into appStore (will be cached for other components)
|
||||
await appStore.fetchPublicSettings()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user