feat: 更换字体v,以及页面加载之前就设置字体 #96
This commit is contained in:
29
src/main.ts
29
src/main.ts
@@ -16,6 +16,35 @@ import './style/style.scss'
|
||||
// 全局svg组件
|
||||
import 'virtual:svg-icons-register'
|
||||
|
||||
// 在应用初始化时尽早设置主题和字体,避免页面加载时的闪烁
|
||||
(function initializeThemeAndFont() {
|
||||
try {
|
||||
// 从localStorage获取全局配置
|
||||
const globalConfigStr = localStorage.getItem('globalConfig')
|
||||
|
||||
if (globalConfigStr) {
|
||||
const storageData = JSON.parse(globalConfigStr)
|
||||
// 根据persist策略,数据存储在globalConfig属性下
|
||||
const globalConfig = storageData.globalConfig || storageData
|
||||
|
||||
// 设置主题
|
||||
if (globalConfig.theme?.name) {
|
||||
const html = document.documentElement
|
||||
html.setAttribute('data-theme', globalConfig.theme.name)
|
||||
}
|
||||
|
||||
// 设置字体
|
||||
if (globalConfig.theme?.font) {
|
||||
// 更新CSS变量
|
||||
document.documentElement.style.setProperty('--app-font-family', `"${globalConfig.theme.font}", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif`)
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.warn('Failed to set initial theme and font:', e)
|
||||
}
|
||||
})()
|
||||
|
||||
const app = createApp(App)
|
||||
const pinia = createPinia()
|
||||
pinia.use(piniaPluginPersist)
|
||||
|
||||
Reference in New Issue
Block a user