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
2026-01-18 22:53:18 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8e77f3fbe4aed8787a0ad30e0db813eb1e84dfec
8e77f3fb
1 parent
11373ab4
feat(用户信息): 添加教师身份判断逻辑
在用户信息和认证上下文中添加get_is_teacher函数,用于从不同字段中判断教师身份并统一返回0或1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
0 deletions
src/composables/useUserInfo.js
src/contexts/auth.js
src/composables/useUserInfo.js
View file @
8e77f3f
...
...
@@ -43,6 +43,24 @@ export function useUserInfo() {
return
null
}
const
get_is_teacher
=
(
data
)
=>
{
const
candidates
=
[
data
?.
is_teacher
,
data
?.
user
?.
is_teacher
,
data
?.
user
?.
teacher
,
]
for
(
const
value
of
candidates
)
{
if
(
value
===
null
||
value
===
undefined
)
continue
if
(
value
===
true
||
value
===
'true'
)
return
1
if
(
value
===
false
||
value
===
'false'
)
return
0
const
num
=
Number
(
value
)
if
(
Number
.
isFinite
(
num
))
return
num
?
1
:
0
}
return
null
}
/**
* 刷新用户信息
* @returns {Promise<Object>} 用户信息对象
...
...
@@ -68,6 +86,11 @@ export function useUserInfo() {
mergedUser
.
unread_msg_count
=
unread
}
const
is_teacher
=
get_is_teacher
(
data
)
if
(
is_teacher
!==
null
)
{
mergedUser
.
is_teacher
=
is_teacher
}
// 更新本地存储
localStorage
.
setItem
(
'currentUser'
,
JSON
.
stringify
(
mergedUser
))
...
...
src/contexts/auth.js
View file @
8e77f3f
...
...
@@ -48,6 +48,24 @@ export function provideAuth() {
return
null
}
const
get_is_teacher
=
(
data
)
=>
{
const
candidates
=
[
data
?.
is_teacher
,
data
?.
user
?.
is_teacher
,
data
?.
user
?.
teacher
,
]
for
(
const
value
of
candidates
)
{
if
(
value
===
null
||
value
===
undefined
)
continue
if
(
value
===
true
||
value
===
'true'
)
return
1
if
(
value
===
false
||
value
===
'false'
)
return
0
const
num
=
Number
(
value
)
if
(
Number
.
isFinite
(
num
))
return
num
?
1
:
0
}
return
null
}
/**
* 检查登录token是否过期
* @returns {boolean} true表示token有效,false表示token已过期
...
...
@@ -84,10 +102,12 @@ export function provideAuth() {
const
{
code
,
data
}
=
await
getUserInfoAPI
();
if
(
code
===
1
)
{
const
unread
=
get_unread_msg_count
(
data
)
const
is_teacher
=
get_is_teacher
(
data
)
currentUser
.
value
=
{
...
data
.
user
,
...
data
.
checkin
,
...(
unread
!==
null
?
{
unread_msg_count
:
unread
}
:
{}),
...(
is_teacher
!==
null
?
{
is_teacher
}
:
{}),
}
localStorage
.
setItem
(
'currentUser'
,
JSON
.
stringify
(
currentUser
.
value
))
// 重新设置认证头
...
...
@@ -119,10 +139,12 @@ export function provideAuth() {
const
userRes
=
await
getUserInfoAPI
();
if
(
userRes
.
code
===
1
)
{
const
unread
=
get_unread_msg_count
(
userRes
.
data
)
const
is_teacher
=
get_is_teacher
(
userRes
.
data
)
currentUser
.
value
=
{
...
userRes
.
data
.
user
,
...
userRes
.
data
.
checkin
,
...(
unread
!==
null
?
{
unread_msg_count
:
unread
}
:
{}),
...(
is_teacher
!==
null
?
{
is_teacher
}
:
{}),
}
}
else
{
currentUser
.
value
=
{
...
data
.
user
,
...
data
.
checkin
}
...
...
Please
register
or
login
to post a comment