Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
mlaj
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2025-03-27 16:59:49 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dd416064a650b189dde0991d4995151d1e70b01d
dd416064
1 parent
89b55269
feat(路由): 添加用户登录检查功能
在路由守卫中添加用户登录检查逻辑,并在auth.js中新增获取用户登录状态的API。同时关闭调试模式以优化生产环境。
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
2 deletions
.env
src/api/auth.js
src/router/guards.js
src/router/index.js
.env
View file @
dd41606
...
...
@@ -11,7 +11,7 @@ VITE_PROXY_PREFIX = /srv/
VITE_OUTDIR = mlaj
# 是否开启调试
VITE_CONSOLE =
1
VITE_CONSOLE =
0
# appID相关
VITE_APPID=微信appID
...
...
src/api/auth.js
View file @
dd41606
...
...
@@ -2,6 +2,7 @@ import { fn, fetch } from '@/api/fn';
const
Api
=
{
AUTH_INFO
:
'/srv/?a=openid_has'
,
USER_IS_LOGIN
:
'/srv/?a=user_is_login'
,
}
/**
...
...
@@ -10,3 +11,10 @@ const Api = {
* @returns
*/
export
const
getAuthInfoAPI
=
()
=>
fn
(
fetch
.
get
(
Api
.
AUTH_INFO
));
/**
* @description: 判断用户是否登录
* @param {*}
* @returns { data: { is_login: boolean }}
*/
export
const
getUserIsLoginAPI
=
()
=>
fn
(
fetch
.
get
(
Api
.
USER_IS_LOGIN
));
...
...
src/router/guards.js
View file @
dd41606
/*
* @Date: 2025-03-20 20:36:36
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-2
6 16:52:03
* @LastEditTime: 2025-03-2
7 16:49:19
* @FilePath: /mlaj/src/router/guards.js
* @Description: 路由守卫逻辑
*/
...
...
@@ -44,6 +44,9 @@ export const checkWxAuth = async () => {
return
true
}
// 检查用户是否已登录
// 登录权限检查
export
const
checkAuth
=
(
to
)
=>
{
const
currentUser
=
JSON
.
parse
(
localStorage
.
getItem
(
'currentUser'
))
...
...
src/router/index.js
View file @
dd41606
...
...
@@ -27,6 +27,8 @@ router.beforeEach(async (to, from, next) => {
return
}
// 检查用户是否已登录
// 登录权限检查
const
authResult
=
checkAuth
(
to
)
if
(
authResult
!==
true
)
{
...
...
Please
register
or
login
to post a comment