feat: token

This commit is contained in:
ygx
2025-12-27 12:57:38 +08:00
parent d760e8f6cc
commit 7a5fa1f4ea
4 changed files with 95 additions and 10 deletions

View File

@@ -45,8 +45,10 @@ async function appInit() {
// iframe 嵌入模式:从 URL 参数中提取 token 并自动登录
const urlParams = getUrlQueryParams()
const systemStore = useSystemStore()
if (urlParams.token) {
const systemStore = useSystemStore()
// URL 中有 token保存到本地
systemStore.setItem(SystemStoreEnum.USER_INFO, {
[SystemStoreUserInfoEnum.USER_TOKEN]: urlParams.token,
[SystemStoreUserInfoEnum.TOKEN_NAME]: 'token',
@@ -54,22 +56,32 @@ async function appInit() {
[SystemStoreUserInfoEnum.USER_NAME]: 'iframe-user',
[SystemStoreUserInfoEnum.NICK_NAME]: 'iframe-user',
})
console.log('[GoView] iframe 模式:已从 URL 参数中获取 token 并初始化')
console.log('[GoView] iframe 模式:已从 URL 参数中获取 token 并保存到本地')
} else {
console.warn('[GoView] iframe 模式:未在 URL 中检测到 token 参数')
// URL 中没有 token,从本地读取
const localToken = systemStore.getUserInfo?.[SystemStoreUserInfoEnum.USER_TOKEN]
if (localToken) {
console.log('[GoView] iframe 模式:已从本地存储读取 token')
} else {
console.warn('[GoView] iframe 模式URL 和本地都没有 token')
}
}
// iframe 嵌入模式:从 URL 参数中提取 mode 并设置主题
const designStore = useDesignStore()
if (urlParams.mode) {
const designStore = useDesignStore()
// URL 中有 mode设置主题并保存到本地
const isDark = urlParams.mode === 'dark'
const themeName = isDark ? ThemeEnum.DARK : ThemeEnum.LIGHT
// 如果主题不同则设置并持久化到localStorage
if (designStore.themeName !== themeName) {
designStore.setTheme(isDark)
console.log(`[GoView] iframe 模式:已设置主题为 ${urlParams.mode} 并存储到本地`)
}
} else {
// URL 中没有 mode使用本地已保存的主题
console.log(`[GoView] iframe 模式:使用本地主题 ${designStore.themeName}`)
}
// 解决路由守卫Axios中可使用DialogMessage 等全局组件