diff --git a/src/components/layout/TopBar.vue b/src/components/layout/TopBar.vue index ee4f5d1..cbf18d6 100644 --- a/src/components/layout/TopBar.vue +++ b/src/components/layout/TopBar.vue @@ -1,58 +1,72 @@ diff --git a/src/stores/user.ts b/src/stores/user.ts index 3520a76..6a2db6a 100644 --- a/src/stores/user.ts +++ b/src/stores/user.ts @@ -2,6 +2,7 @@ import { defineStore } from 'pinia' import { ref } from 'vue' import type { UserInfo } from '@/api/user' import { userApi } from '@/api/user' +import { ElMessage } from 'element-plus' export const useUserStore = defineStore('user', () => { const userInfo = ref(null) @@ -10,8 +11,9 @@ export const useUserStore = defineStore('user', () => { // 获取用户信息 const getUserInfo = async () => { try { - console.log(1111) - await userApi.getCurrentUser() + const data = await userApi.getCurrentUser() + userInfo.value = data + return data } catch (error) { console.error('获取用户信息失败:', error) return null @@ -19,8 +21,9 @@ export const useUserStore = defineStore('user', () => { } // 设置token - const setToken = (token: string) => { - localStorage.setItem('token', token) + const setToken = (newToken: string) => { + token.value = newToken + localStorage.setItem('token', newToken) } // 清除用户信息 @@ -35,6 +38,6 @@ export const useUserStore = defineStore('user', () => { token, getUserInfo, setToken, - clearUserInfo, + clearUserInfo } })