feat: token
This commit is contained in:
22
src/main.ts
22
src/main.ts
@@ -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中可使用,Dialog,Message 等全局组件
|
||||
|
||||
Reference in New Issue
Block a user