From e1ae0605513c0bff8fed7258c44fad8166265725 Mon Sep 17 00:00:00 2001 From: ovo Date: Sat, 7 Dec 2024 22:26:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E5=90=8E=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/layout/TopBar.vue | 185 +++++++++++++++++-------------- src/stores/user.ts | 13 ++- 2 files changed, 108 insertions(+), 90 deletions(-) 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 } })