From 14e776a287c3fc7d7d9cfac622c8166fdf92cd0e Mon Sep 17 00:00:00 2001 From: honue Date: Tue, 5 Mar 2024 15:20:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=90=8E=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=8E=9F=E5=A7=8B=E9=A1=B5=E9=9D=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/login.vue | 4 ++-- src/router/index.ts | 1 + src/store/auth.ts | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pages/login.vue b/src/pages/login.vue index a002dd11..d57fbbf7 100644 --- a/src/pages/login.vue +++ b/src/pages/login.vue @@ -77,8 +77,8 @@ function login() { store.dispatch('auth/updateUserName', username) store.dispatch('auth/updateAvatar', avatar) - // 跳转到首页 - router.push('/') + // 跳转到首页或回原始页面 + router.push(store.state.auth.originalPath) }) .catch((error: any) => { // 登录失败,显示错误提示 diff --git a/src/router/index.ts b/src/router/index.ts index b5f687aa..c406c54c 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -162,6 +162,7 @@ router.beforeEach((to, from, next) => { const isAuthenticated = store.state.auth.token !== null if (to.meta.requiresAuth && !isAuthenticated) { + store.state.auth.originalPath = to.fullPath next('/login') } else { diff --git a/src/store/auth.ts b/src/store/auth.ts index e9a42783..352c4ab0 100644 --- a/src/store/auth.ts +++ b/src/store/auth.ts @@ -7,6 +7,7 @@ interface AuthState { superUser: boolean userName: string avatar: string + originalPath: string | null } // 定义根状态类型 @@ -23,6 +24,7 @@ const authModule: Module = { superUser: false, userName: '', avatar: '', + originalPath: null, }, mutations: { setToken(state, token: string) {