From b1a373f220bcafea8f41fa735b42d4eeafb2ee4e Mon Sep 17 00:00:00 2001
From: 李凌 <344137771@qq.com>
Date: Wed, 22 Oct 2025 14:06:15 +0800
Subject: [PATCH] 2
---
src/router/index.js | 45 ++++++++++++++-------------------------------
1 files changed, 14 insertions(+), 31 deletions(-)
diff --git a/src/router/index.js b/src/router/index.js
index fcd1e6a..ece65cc 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -1522,38 +1522,21 @@
},
})
router.beforeEach((to, from, next) => {
- const userStore = useUserStore()
- console.log(to.name);
- if (to.name === 'Login' || to.name == 'Register') {
- if (userStore.userInfo && userStore.userInfo.token) {
- // 通过vuex state获取当前的token是否存在
- next()
- } else {
- // loginButton().then(() => {
- // console.log('钱包授权成功');
- // next(); // 授权成功后允许跳转
- // }).catch(() => {
- // console.error('钱包授权失败');
- // next(false); // 授权失败,阻止跳转
- // });
- loginButton()
- // next({
- // path: '/login',
- // })
- // next({
- // path: '/',
- // })
- }
- } else {
- next()
- }
-
- // if (to.meta.requireAuth) {
- // 判断该路由是否需要登录权限
-
-
+ const userStore = useUserStore()
+ if (to.meta.requireAuth) {
+ // 判断该路由是否需要登录权限
+ if (userStore.userInfo && userStore.userInfo.token) {
+ // 通过vuex state获取当前的token是否存在
+ next()
+ } else {
+ next({
+ path: '/login',
+ })
+ }
+ } else {
+ next()
+ }
})
-
// 登录按钮逻辑,标记为异步函数
const loginButton = async () => {
const userStore = useUserStore()
--
Gitblit v1.9.3