diff --git a/src/api/axios.ts b/src/api/axios.ts
index 8ee1797..c55d929 100644
--- a/src/api/axios.ts
+++ b/src/api/axios.ts
@@ -40,7 +40,12 @@ axiosInstance.interceptors.request.use(
const userInfo = info[SystemStoreEnum.USER_INFO]
if (userInfo && userInfo[SystemStoreUserInfoEnum.USER_TOKEN]) {
config.headers['authorization'] = userInfo[SystemStoreUserInfoEnum.USER_TOKEN]
+ console.log('[GoView] 请求拦截器:添加 authorization 头:', userInfo[SystemStoreUserInfoEnum.USER_TOKEN])
+ } else {
+ console.warn('[GoView] 请求拦截器:未找到 token')
}
+ } else {
+ console.warn('[GoView] 请求拦截器:未找到 GO_SYSTEM_STORE')
}
return config
diff --git a/src/main.ts b/src/main.ts
index 57f57e4..2597f75 100644
--- a/src/main.ts
+++ b/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 等全局组件
diff --git a/src/router/router-guards.ts b/src/router/router-guards.ts
index ba4be11..7bd0835 100644
--- a/src/router/router-guards.ts
+++ b/src/router/router-guards.ts
@@ -8,12 +8,14 @@ import { setHtmlTheme } from '@/utils'
/**
* 从 URL 参数中提取 token 并自动登录
+ * 如果 URL 中没有 token,则使用本地存储的 token
*/
function autoLoginFromUrlToken(query: any) {
const token = query.token
+ const systemStore = useSystemStore()
+
if (token) {
- const systemStore = useSystemStore()
- // 存储 token 到 store
+ // URL 中有 token,保存到 store
systemStore.setItem(SystemStoreEnum.USER_INFO, {
[SystemStoreUserInfoEnum.USER_TOKEN]: token,
[SystemStoreUserInfoEnum.TOKEN_NAME]: 'token',
@@ -21,28 +23,40 @@ function autoLoginFromUrlToken(query: any) {
[SystemStoreUserInfoEnum.USER_NAME]: 'iframe-user',
[SystemStoreUserInfoEnum.NICK_NAME]: 'iframe-user',
})
- console.log('[GoView] 已从 URL 参数中获取 token 并自动登录')
+ console.log('[GoView] 已从 URL 参数中获取 token 并保存到本地')
return true
+ } else {
+ // URL 中没有 token,检查本地是否有 token
+ const localToken = systemStore.getUserInfo?.[SystemStoreUserInfoEnum.USER_TOKEN]
+ if (localToken) {
+ console.log('[GoView] 使用本地存储的 token')
+ return true
+ }
}
return false
}
/**
* 从 URL 参数中提取 mode 并切换主题
+ * 如果 URL 中没有 mode,则使用本地存储的主题
*/
function autoSwitchThemeFromUrlMode(query: any) {
const mode = query.mode
+ const designStore = useDesignStore()
+
if (mode) {
- const designStore = useDesignStore()
+ // URL 中有 mode,设置主题并保存到本地
const isDark = mode === 'dark'
const themeName = isDark ? ThemeEnum.DARK : ThemeEnum.LIGHT
- // 如果主题不同,则设置并持久化到localStorage
if (designStore.themeName !== themeName) {
designStore.setTheme(isDark)
setHtmlTheme(themeName)
console.log(`[GoView] 已切换主题为 ${mode} 并存储到本地`)
}
+ } else {
+ // URL 中没有 mode,使用本地已保存的主题
+ console.log(`[GoView] 使用本地主题 ${designStore.themeName}`)
}
}
diff --git a/src/views/project/items/index.vue b/src/views/project/items/index.vue
index f48f4da..bba2d03 100644
--- a/src/views/project/items/index.vue
+++ b/src/views/project/items/index.vue
@@ -8,8 +8,62 @@