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-06-13 11:12:02 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
44d18ccf86f645e80ca86115093dd1b2bdb7449d
44d18ccf
1 parent
61d82b97
feat(auth): 添加从服务器获取授权信息的功能
当本地没有用户信息时,新增调用getAuthInfoAPI接口检查用户授权状态
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
1 deletions
src/contexts/auth.js
src/contexts/auth.js
View file @
44d18cc
/*
* @Date: 2025-03-20 21:11:31
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-0
5-23 09:50:46
* @LastEditTime: 2025-0
6-13 11:09:37
* @FilePath: /mlaj/src/contexts/auth.js
* @Description: 认证上下文管理模块,提供用户认证状态管理、登录登出功能
*/
...
...
@@ -9,6 +9,7 @@
// 导入Vue的组合式API相关函数
import
{
ref
,
provide
,
inject
,
onMounted
}
from
'vue'
import
{
logoutAPI
,
getUserInfoAPI
}
from
'@/api/users'
import
{
getAuthInfoAPI
}
from
'@/api/auth'
// 创建认证上下文的Symbol key,用于provide/inject依赖注入
// 使用Symbol确保key的唯一性,避免命名冲突
...
...
@@ -68,6 +69,15 @@ export function provideAuth() {
}
else
{
logout
()
}
}
else
{
// 查询用户是否授权, 从服务器获取用户信息并更新本地存储
const
{
code
,
data
}
=
await
getAuthInfoAPI
();
if
(
code
)
{
if
(
data
.
openid_has
)
{
currentUser
.
value
=
data
.
user
localStorage
.
setItem
(
'currentUser'
,
JSON
.
stringify
(
currentUser
.
value
))
}
}
}
// 初始化完成,关闭加载状态
loading
.
value
=
false
...
...
Please
register
or
login
to post a comment