fix: 修复系统设置的动态注入问题
- 创建 useSiteSettings composable 在应用启动时加载系统设置 - 从 window.__SITE_CONFIG__(后端注入)和 localStorage 初始化设置 - 修复 favicon 更新逻辑,正确移除旧 favicon 并添加新的 - 在路由守卫中设置页面标题,格式为 '页面名 - 网站名' - 简化 admin.vue 和 admin-sidebar 组件,使用统一的设置管理 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
<script lang="ts" setup>
|
||||
import { Boxes, Code, CreditCard, DollarSign, FileLock, Gauge, GitBranch, HardDrive, Hash, Key, KeyRound, Mail, Megaphone, MessageSquare, Monitor, Network, Plug, ScrollText, Settings, Shield, Smartphone, Users, Variable } from 'lucide-vue-next'
|
||||
import { computed, onMounted, onUnmounted, reactive } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, reactive, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import NavTeam from '@/components/app-sidebar/nav-team.vue'
|
||||
import TeamSwitcher from '@/components/app-sidebar/team-switcher.vue'
|
||||
import NavFooter from '@/components/admin-sidebar/nav-footer.vue'
|
||||
import { useSiteSettings } from '@/composables/use-site-settings'
|
||||
|
||||
const { t } = useI18n()
|
||||
const { siteSettings } = useSiteSettings()
|
||||
|
||||
const user = reactive({
|
||||
name: t('nav.admin'),
|
||||
@@ -16,48 +18,32 @@ const user = reactive({
|
||||
role: 'admin',
|
||||
})
|
||||
|
||||
const siteSettings = reactive({
|
||||
name: t('nav.adminDashboard'),
|
||||
logo: '',
|
||||
})
|
||||
|
||||
const teams = reactive([
|
||||
{
|
||||
name: t('nav.adminDashboard'),
|
||||
logo: Code,
|
||||
logo: Code as any,
|
||||
},
|
||||
])
|
||||
|
||||
function loadSystemSettings() {
|
||||
const storedSettings = localStorage.getItem('systemSettings')
|
||||
if (storedSettings) {
|
||||
try {
|
||||
const parsed = JSON.parse(storedSettings)
|
||||
if (parsed.site_name) {
|
||||
siteSettings.name = parsed.site_name
|
||||
teams[0].name = parsed.site_name
|
||||
}
|
||||
if (parsed.site_logo) {
|
||||
siteSettings.logo = parsed.site_logo
|
||||
teams[0].logo = parsed.site_logo
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error('Failed to parse systemSettings from localStorage', e)
|
||||
}
|
||||
// 监听系统设置变化
|
||||
watch(() => siteSettings.siteName, (newName) => {
|
||||
if (newName) {
|
||||
teams[0].name = newName
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function handleSettingsChange(event: CustomEvent) {
|
||||
const settings = event.detail
|
||||
if (settings.site_name) {
|
||||
siteSettings.name = settings.site_name
|
||||
teams[0].name = settings.site_name
|
||||
}
|
||||
if (settings.site_logo) {
|
||||
siteSettings.logo = settings.site_logo
|
||||
teams[0].logo = settings.site_logo
|
||||
watch(() => siteSettings.siteLogo, (newLogo) => {
|
||||
if (newLogo) {
|
||||
teams[0].logo = newLogo
|
||||
}
|
||||
})
|
||||
|
||||
// 初始化时设置
|
||||
if (siteSettings.siteName) {
|
||||
teams[0].name = siteSettings.siteName
|
||||
}
|
||||
if (siteSettings.siteLogo) {
|
||||
teams[0].logo = siteSettings.siteLogo
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
@@ -74,13 +60,9 @@ onMounted(() => {
|
||||
console.error('Failed to parse user from localStorage', e)
|
||||
}
|
||||
}
|
||||
|
||||
loadSystemSettings()
|
||||
window.addEventListener('system-settings-changed', handleSettingsChange as EventListener)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('system-settings-changed', handleSettingsChange as EventListener)
|
||||
})
|
||||
|
||||
const navMain = computed(() => [
|
||||
|
||||
Reference in New Issue
Block a user