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
872c7822
Commit
872c7822
authored
Aug 07, 2020
by
前端-许佳敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
权限接口对接
parent
81852234
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
3 deletions
+41
-3
LoginWrap.tsx
src/pages/user/components/LoginWrap.tsx
+9
-1
auth.ts
src/utils/auth.ts
+17
-0
request.ts
src/utils/request.ts
+15
-2
No files found.
src/pages/user/components/LoginWrap.tsx
View file @
872c7822
import
React
,
{
useState
}
from
'react'
import
{
history
}
from
'umi'
import
{
Form
,
Row
,
Col
,
Input
,
Button
}
from
'antd'
import
{
UserOutlined
,
...
...
@@ -7,6 +8,7 @@ import {
}
from
'@ant-design/icons'
;
import
styles
from
'../index.less'
import
{
PublicApi
}
from
'@/services/api'
;
import
{
setAuth
}
from
'@/utils/auth'
;
const
LoginWrap
:
React
.
FC
=
()
=>
{
const
[
validFrame
,
setValidFrame
]
=
useState
(
false
)
...
...
@@ -15,7 +17,13 @@ const LoginWrap: React.FC = () => {
const
finish
=
(
value
:
any
)
=>
{
console
.
log
(
value
)
PublicApi
.
postMemberLogin
(
value
).
then
(
res
=>
{
console
.
log
(
res
)
const
{
data
}
=
res
setAuth
({
memberId
:
data
.
memberId
,
userId
:
data
.
userId
,
token
:
data
.
token
})
history
.
push
(
'/'
)
})
}
...
...
src/utils/auth.ts
0 → 100644
View file @
872c7822
export
interface
AuthInfo
{
userId
:
number
,
memberId
:
number
,
token
:
string
}
export
const
setAuth
=
(
info
:
AuthInfo
)
=>
{
window
.
localStorage
.
setItem
(
'auth'
,
JSON
.
stringify
(
info
))
}
export
const
getAuth
=
()
=>
{
try
{
return
JSON
.
parse
(
window
.
localStorage
.
getItem
(
'auth'
))
}
catch
(
error
)
{
return
{}
}
}
src/utils/request.ts
View file @
872c7822
...
...
@@ -2,6 +2,7 @@ import { extend, ResponseError, OnionOptions, RequestOptionsInit, ResponseInterc
import
responseCode
from
'@/constants/responseCode'
import
{
IRequestError
,
IRequestSuccess
}
from
'..'
;
import
{
message
}
from
'antd'
import
{
getAuth
}
from
'./auth'
;
export
type
CtlType
=
'none'
|
'message'
// 根前缀请求路径
...
...
@@ -49,7 +50,9 @@ const errorHandler = (error: ResponseError): IRequestError => {
}
const
defaultHeaders
=
{
'Content-Type'
:
'Application/json'
'Content-Type'
:
'Application/json'
,
// 能力中心特定标识, 不可修改
source
:
'1'
}
/**
...
...
@@ -64,10 +67,20 @@ const baseRequest = extend({
// 请求拦截器
baseRequest
.
interceptors
.
request
.
use
((
url
:
string
,
options
:
RequestOptionsInit
):
{
url
:
string
,
options
:
RequestOptionsInit
}
=>
{
// 判断是否有权限
const
loginAfterHeaders
=
getAuth
()
const
headers
=
{
...
options
.
headers
,
...
loginAfterHeaders
}
return
{
// 前缀如果已经带上api, 跳过自动补前缀
url
:
url
.
startsWith
(
'/api'
)
?
url
:
basePrefix
+
url
,
options
,
options
:
{
...
options
,
headers
},
};
});
...
...
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