Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄庭坚
jinfa-platform
Commits
a7722af5
Commit
a7722af5
authored
Jun 24, 2021
by
前端-许佳敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 登录状态维持
parent
1ebcb3f2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
5 deletions
+19
-5
LoginWrap.tsx
src/pages/user/components/LoginWrap.tsx
+1
-1
auth.ts
src/utils/auth.ts
+18
-4
No files found.
src/pages/user/components/LoginWrap.tsx
View file @
a7722af5
...
@@ -28,7 +28,7 @@ const LoginWrap: React.FC = () => {
...
@@ -28,7 +28,7 @@ const LoginWrap: React.FC = () => {
message
.
success
(
"登录成功"
)
message
.
success
(
"登录成功"
)
setRouters
(
data
.
urls
)
setRouters
(
data
.
urls
)
// 设置同域名cookie缓存
// 设置同域名cookie缓存
setAuth
(
omit
(
data
,
[
'urls'
])
)
setAuth
(
data
)
// 此处需使用href跳转, 否则无法触发app.ts中的路由初始化校验
// 此处需使用href跳转, 否则无法触发app.ts中的路由初始化校验
if
(
redirect
)
{
if
(
redirect
)
{
window
.
location
.
replace
(
decodeURIComponent
(
atob
(
redirect
)))
window
.
location
.
replace
(
decodeURIComponent
(
atob
(
redirect
)))
...
...
src/utils/auth.ts
View file @
a7722af5
import
{
isDev
,
TOP_DOMAIN
}
from
'@/constants'
import
{
isDev
,
TOP_DOMAIN
}
from
'@/constants'
import
{
GetMemberLoginRegetResponse
}
from
'@/services/memberApi'
import
{
GetMemberLoginRegetResponse
}
from
'@/services/memberApi'
import
{
getCookie
,
setCookie
}
from
'./cookie'
import
{
getTopDomainByHost
}
from
'.'
import
{
getCookie
,
removeCookie
,
setCookie
}
from
'./cookie'
import
{
getUserCookie
,
setUserCookie
}
from
'./siteCookie'
import
{
getUserCookie
,
setUserCookie
}
from
'./siteCookie'
export
interface
AuthInfo
{
export
interface
AuthInfo
{
...
@@ -11,6 +12,7 @@ export interface AuthInfo {
...
@@ -11,6 +12,7 @@ export interface AuthInfo {
logo
:
string
,
logo
:
string
,
levelTag
:
string
,
levelTag
:
string
,
creditPoint
:
number
,
creditPoint
:
number
,
urls
:
string
[]
}
}
const
AUTH_KEY
=
'AUTH'
const
AUTH_KEY
=
'AUTH'
...
@@ -25,11 +27,20 @@ export const setAuth = (info: AuthInfo) => {
...
@@ -25,11 +27,20 @@ export const setAuth = (info: AuthInfo) => {
creditPoint
:
info
.
creditPoint
creditPoint
:
info
.
creditPoint
}
}
setCookie
(
AUTH_KEY
,
JSON
.
stringify
(
auth
),
{
domain
:
TOP_DOMAIN
})
setCookie
(
AUTH_KEY
,
JSON
.
stringify
(
auth
),
{
domain
:
TOP_DOMAIN
})
setLocalAuth
(
info
)
setRouters
(
info
.
urls
)
}
/**
* 由于member本地需要获取urls字段, 但cookie不需要, 所以分开保留以前的储存方式
*/
export
const
setLocalAuth
=
(
info
:
AuthInfo
)
=>
{
window
.
localStorage
.
setItem
(
AUTH_KEY
,
JSON
.
stringify
(
info
))
}
}
export
const
getAuth
=
():
AuthInfo
=>
{
export
const
getAuth
=
():
AuthInfo
=>
{
try
{
try
{
const
localAuth
=
getCookie
(
AUTH_KEY
)
const
localAuth
=
JSON
.
parse
(
window
.
localStorage
.
getItem
(
AUTH_KEY
)
)
return
(
localAuth
||
{}
)
as
AuthInfo
return
(
localAuth
||
{}
)
as
AuthInfo
}
catch
(
error
)
{
}
catch
(
error
)
{
return
{}
as
AuthInfo
return
{}
as
AuthInfo
...
@@ -42,7 +53,7 @@ export const setRouters = (routers: any[]) => {
...
@@ -42,7 +53,7 @@ export const setRouters = (routers: any[]) => {
export
const
getRouters
=
():
string
[]
=>
{
export
const
getRouters
=
():
string
[]
=>
{
try
{
try
{
const
localAuth
=
window
.
localStorage
.
getItem
(
'auth
'
)
const
localAuth
=
window
.
sessionStorage
.
getItem
(
'rt
'
)
if
(
localAuth
)
{
if
(
localAuth
)
{
const
userInfo
=
JSON
.
parse
(
localAuth
)
const
userInfo
=
JSON
.
parse
(
localAuth
)
return
userInfo
.
urls
?
userInfo
.
urls
:
[]
return
userInfo
.
urls
?
userInfo
.
urls
:
[]
...
@@ -58,7 +69,10 @@ export const removeRouters = () => {
...
@@ -58,7 +69,10 @@ export const removeRouters = () => {
}
}
export
const
removeAuth
=
()
=>
{
export
const
removeAuth
=
()
=>
{
window
.
localStorage
.
removeItem
(
'auth'
)
console
.
log
(
TOP_DOMAIN
)
removeCookie
(
AUTH_KEY
,
{
path
:
'/'
,
domain
:
TOP_DOMAIN
})
window
.
localStorage
.
removeItem
(
AUTH_KEY
)
removeRouters
()
}
}
export
const
asyncRouter
=
async
(
routeLists
:
string
[],
routes
:
any
[])
=>
{
export
const
asyncRouter
=
async
(
routeLists
:
string
[],
routes
:
any
[])
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment