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

@@ -8,8 +8,62 @@
</template>
<script setup lang="ts">
import { onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { ProjectItemsList } from './components/ProjectItemsList'
import { ProjectLayoutCreate } from '../layout/components/ProjectLayoutCreate'
import { useSystemStore } from '@/store/modules/systemStore/systemStore'
import { useDesignStore } from '@/store/modules/designStore/designStore'
import { SystemStoreEnum, SystemStoreUserInfoEnum } from '@/store/modules/systemStore/systemStore.d'
import { ThemeEnum } from '@/enums/styleEnum'
import { setHtmlTheme } from '@/utils'
const route = useRoute()
const systemStore = useSystemStore()
const designStore = useDesignStore()
// 组件挂载时处理 URL 参数中的 token 和 mode
onMounted(() => {
const { token, mode } = route.query
// 处理 token 参数
if (token && typeof token === 'string') {
console.log('[GoView] 准备更新 tokenURL 中的 token:', token)
console.log('[GoView] 更新前的 userInfo:', JSON.stringify(systemStore.getUserInfo))
systemStore.setItem(SystemStoreEnum.USER_INFO, {
[SystemStoreUserInfoEnum.USER_TOKEN]: token,
[SystemStoreUserInfoEnum.TOKEN_NAME]: 'token',
[SystemStoreUserInfoEnum.USER_ID]: 'iframe-user',
[SystemStoreUserInfoEnum.USER_NAME]: 'iframe-user',
[SystemStoreUserInfoEnum.NICK_NAME]: 'iframe-user',
})
console.log('[GoView] 更新后的 userInfo:', JSON.stringify(systemStore.getUserInfo))
console.log('[GoView] /project/items 路由:已从 URL 参数中获取 token 并保存到本地')
} else {
const localToken = systemStore.getUserInfo?.[SystemStoreUserInfoEnum.USER_TOKEN]
if (localToken) {
console.log('[GoView] /project/items 路由:使用本地存储的 token:', localToken)
} else {
console.warn('[GoView] /project/items 路由URL 和本地都没有 token')
}
}
// 处理 mode 参数
if (mode && typeof mode === 'string') {
const isDark = mode === 'dark'
const themeName = isDark ? ThemeEnum.DARK : ThemeEnum.LIGHT
if (designStore.themeName !== themeName) {
designStore.setTheme(isDark)
setHtmlTheme(themeName)
console.log(`[GoView] /project/items 路由:已设置主题为 ${mode} 并存储到本地`)
}
} else {
console.log(`[GoView] /project/items 路由:使用本地主题 ${designStore.themeName}`)
}
})
</script>
<style lang="scss" scoped>