feat: token
This commit is contained in:
@@ -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] 准备更新 token,URL 中的 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>
|
||||
|
||||
Reference in New Issue
Block a user