From 566da2e79151ba688f3fdb1deb07086aceb1d878 Mon Sep 17 00:00:00 2001 From: my_ong <429426262@qq.com> Date: Mon, 16 Dec 2024 10:05:13 +0800 Subject: [PATCH] =?UTF-8?q?bug:=20=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth/mods/auth/currentUser.ts | 24 ++++++++++++------------ src/layout/components/right-content.vue | 5 ++++- src/router/index.ts | 1 - src/stores/user.ts | 6 ++++++ 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/api/auth/mods/auth/currentUser.ts b/src/api/auth/mods/auth/currentUser.ts index a609560..7e0622f 100644 --- a/src/api/auth/mods/auth/currentUser.ts +++ b/src/api/auth/mods/auth/currentUser.ts @@ -1,18 +1,18 @@ /** * @desc 当前用户 */ -import { defaultSuccess, defaultError, http } from '@/plugins/axios'; -import type { AxiosResponse } from 'axios'; +import { defaultSuccess, defaultError, http } from '@/plugins/axios' +import type { AxiosResponse } from 'axios' export default async function ( - success: (data: auth.AuthUser) => void = defaultSuccess, - fail: (error: { code: string; error?: string }) => void = defaultError, + success: (data: auth.AuthUser) => void = defaultSuccess, + fail: (error: { code: string; error?: string }) => void = defaultError, ): Promise { - return http({ - method: 'get', - url: `/auth/current-user`, - }) - .then((data: AxiosResponse) => { - success(data.data); - }) - .catch((error: { code: string; error?: string }) => fail(error)); + return http({ + method: 'get', + url: `/auth/current-user`, + }) + .then((data: AxiosResponse) => { + success(data.data) + }) + .catch((error: { code: string; error?: string }) => fail(error)) } diff --git a/src/layout/components/right-content.vue b/src/layout/components/right-content.vue index 182760e..daa6a58 100644 --- a/src/layout/components/right-content.vue +++ b/src/layout/components/right-content.vue @@ -67,6 +67,7 @@ import { config } from '@/settings/application' import { MenuInfo } from 'ant-design-vue/es/menu/src/interface' import { useUserStore } from '@/stores/user' + import api from '@/api' const t = useI18n() const user = useUserStore() @@ -85,7 +86,9 @@ icon: createVNode(ExclamationCircleOutlined), content: createVNode('div', { style: 'color:red;' }, '确定退出系统吗?'), onOk() { - user.logout() + api.authApi.auth.logout(() => { + user.logout() + }) }, }) } diff --git a/src/router/index.ts b/src/router/index.ts index 77654b3..da1028c 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -101,7 +101,6 @@ export const routes: Array = [ const getNewRouter = () => { // TODO 用户store判断是否登录,登录就返回过滤的,没有登录就返回全量 - return createRouter({ history: createWebHashHistory(), routes: [ diff --git a/src/stores/user.ts b/src/stores/user.ts index 2bd4c35..b8dce86 100644 --- a/src/stores/user.ts +++ b/src/stores/user.ts @@ -18,6 +18,12 @@ export const useUserStore = defineStore('user', { isAdmin(state) { return state.roles.includes('admin') }, + isLogin(state) { + return state.token && state.refreshToken + }, + getPermission(state) { + return state.permissions + }, }, actions: { refreshUserInfo(user: auth.AuthUser) {