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
b0635070
Commit
b0635070
authored
Jun 18, 2021
by
前端-许佳敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: login
parent
a0669950
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
28 deletions
+68
-28
.env
.env
+2
-2
config.ts
config/config.ts
+4
-0
RightContent.tsx
src/layouts/components/RightContent.tsx
+1
-1
LoginWrap.tsx
src/pages/user/components/LoginWrap.tsx
+8
-8
auth.ts
src/utils/auth.ts
+21
-12
siteCookie.ts
src/utils/siteCookie.ts
+32
-5
No files found.
.env
View file @
b0635070
# https://umijs.org/zh-CN/docs/env-variables
PORT=4396
\ No newline at end of file
PORT=4396
HTTPS=true
config/config.ts
View file @
b0635070
...
...
@@ -151,6 +151,10 @@ const config: any = {
* 配置主题,实际上是配 less 变量。
*/
theme
,
devServer
:
{
https
:
true
,
}
};
// if (OPEN_THEME_BUILD) {
...
...
src/layouts/components/RightContent.tsx
View file @
b0635070
...
...
@@ -62,7 +62,7 @@ const GlobalHeaderRight: React.FC<{ SiteStore?: any }> = (props) => {
},
[
ws
]);
useEffect
(()
=>
{
webSocketInit
();
//
webSocketInit();
return
()
=>
{
ws
.
current
?.
close
();
};
...
...
src/pages/user/components/LoginWrap.tsx
View file @
b0635070
...
...
@@ -9,7 +9,8 @@ import {
import
{
PublicApi
}
from
'@/services/api'
;
import
{
setAuth
,
setRouters
}
from
'@/utils/auth'
;
import
{
encryptedByAES
}
from
'@/utils/cryptoAes'
;
import
{
setTokenCookie
}
from
'@/utils/siteCookie'
;
import
{
setUserCookie
}
from
'@/utils/siteCookie'
;
import
{
omit
}
from
'@/utils'
;
const
LoginWrap
:
React
.
FC
=
()
=>
{
const
{
redirect
}
=
history
.
location
.
query
...
...
@@ -25,16 +26,15 @@ const LoginWrap: React.FC = () => {
if
(
code
===
1000
)
{
message
.
destroy
()
message
.
success
(
"登录成功"
)
setAuth
(
data
)
setRouters
(
data
.
urls
)
// 设置同域名cookie缓存
set
TokenCookie
(
data
.
token
)
set
Auth
(
omit
(
data
,
[
'urls'
])
)
// 此处需使用href跳转, 否则无法触发app.ts中的路由初始化校验
if
(
redirect
)
{
window
.
location
.
replace
(
decodeURIComponent
(
atob
(
redirect
)))
}
else
{
window
.
location
.
replace
(
'/memberCenter/home'
)
}
//
if (redirect) {
//
window.location.replace(decodeURIComponent(atob(redirect)))
//
} else {
//
window.location.replace('/memberCenter/home')
//
}
}
else
{
setLoginLoading
(
false
)
}
...
...
src/utils/auth.ts
View file @
b0635070
import
{
isDev
}
from
'@/constants'
import
{
GetMemberLoginRegetResponse
}
from
'@/services/memberApi'
import
{
getUserCookie
,
setUserCookie
}
from
'./siteCookie'
export
interface
AuthInfo
{
userId
?:
number
,
memberId
?:
number
,
name
?:
string
,
token
?:
string
,
company
?:
string
,
validateMsg
?:
string
,
validateStatus
?:
number
,
validateStatusDesc
?:
string
,
userId
:
number
,
memberId
:
number
,
name
:
string
,
token
:
string
,
logo
:
string
,
levelTag
:
string
,
creditPoint
:
number
,
}
export
const
setAuth
=
(
info
:
AuthInfo
)
=>
{
window
.
localStorage
.
setItem
(
'auth'
,
JSON
.
stringify
(
info
))
const
auth
=
{
userId
:
info
.
userId
,
memberId
:
info
.
memberId
,
token
:
info
.
token
,
name
:
info
.
name
,
logo
:
info
.
logo
,
levelTag
:
info
.
levelTag
,
creditPoint
:
info
.
creditPoint
}
setUserCookie
(
auth
)
}
export
const
getAuth
=
()
:
Partial
<
GetMemberLoginRegetResponse
>
|
null
=>
{
export
const
getAuth
=
()
=>
{
try
{
const
localAuth
=
window
.
localStorage
.
getItem
(
'auth'
)
return
localAuth
?
JSON
.
parse
(
localAuth
)
:
null
const
localAuth
:
AuthInfo
=
getUserCookie
()
as
unknown
as
AuthInfo
return
localAuth
?
localAuth
:
{}
}
catch
(
error
)
{
return
{}
}
...
...
src/utils/siteCookie.ts
View file @
b0635070
/**
* 设置samesite的cookie, 达到多个域名登录信息共享
*/
import
{
GlobalConfig
}
from
'@/global/config'
import
Cookie
from
'js-cookie'
const
TOKEN_KEY
=
'siteToken'
export
const
setTokenCookie
=
(
token
:
string
)
=>
{
Cookie
.
set
(
TOKEN_KEY
,
token
,
{
domain
:
'lingxidev.com'
,
secure
:
true
,
httpOnly
:
true
,
})
const
USER_KEY
=
'AUTH'
const
DOMAIN_REGXP
=
/
(?<
=
\.)\w
+
\.(
com|net|cn
)
$/
// pass平台设置的域名
const
DOMAIN
=
GlobalConfig
.
global
.
siteInfo
.
siteUrl
export
const
setUserCookie
=
(
data
:
any
)
=>
{
Cookie
.
set
(
USER_KEY
,
JSON
.
stringify
(
data
),
{
domain
:
getDomainUrl
(
DOMAIN
)
})
}
export
const
getUserCookie
=
()
=>
{
try
{
return
JSON
.
parse
(
Cookie
.
get
(
USER_KEY
))
}
catch
(
err
)
{
return
{}
}
}
export
const
getTokenCookie
=
()
=>
{
return
Cookie
.
get
(
TOKEN_KEY
)
export
const
removeUserCoookie
=
()
=>
{
Cookie
.
remove
(
USER_KEY
)
}
/**
* 从域名中获取主域名, 只能获取常用的几种, 如需扩展 可在上方正则加入
*/
function
getDomainUrl
(
url
:
string
)
{
const
result
=
url
.
match
(
DOMAIN_REGXP
)
if
(
result
.
length
>
0
)
{
return
result
[
0
]
}
else
{
return
''
}
}
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