Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mr-julyedu
Overview
Overview
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
baiguangyao
mr-julyedu
Commits
da9aeaf6
Commit
da9aeaf6
authored
Aug 12, 2019
by
zhanghaozhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登录相关逻辑
parent
9765af18
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
18 deletions
+31
-18
src/App.js
+8
-6
src/components/passport/index.js
+1
-1
src/router/privateRoute.js
+17
-7
src/router/route-middle-page.js
+3
-3
src/store/userAction.js
+1
-1
src/store/userReducer.js
+1
-0
No files found.
src/App.js
View file @
da9aeaf6
...
@@ -7,7 +7,6 @@ import { withRouter } from 'react-router-dom'
...
@@ -7,7 +7,6 @@ import { withRouter } from 'react-router-dom'
import
{
compose
}
from
'redux'
import
{
compose
}
from
'redux'
import
{
getParam
,
http
}
from
"@/utils"
;
import
{
getParam
,
http
}
from
"@/utils"
;
import
{
Toast
}
from
"antd-mobile"
;
import
{
Toast
}
from
"antd-mobile"
;
import
jsCookie
from
'js-cookie'
import
{
addDays
}
from
'date-fns'
import
{
addDays
}
from
'date-fns'
...
@@ -27,7 +26,8 @@ class App extends Component {
...
@@ -27,7 +26,8 @@ class App extends Component {
componentDidMount
()
{
componentDidMount
()
{
//平台信息
//平台信息
cookie
.
set
(
'plat'
,
'5'
)
cookie
.
set
(
'plat'
,
'5'
,
{
domain
:
'.julyedu.com'
})
this
.
props
.
startFetchUser
()
this
.
props
.
startFetchUser
()
http
.
get
(
`
${
API
.
home
}
/m/user_info`
).
then
(
res
=>
{
http
.
get
(
`
${
API
.
home
}
/m/user_info`
).
then
(
res
=>
{
...
@@ -35,6 +35,9 @@ class App extends Component {
...
@@ -35,6 +35,9 @@ class App extends Component {
})
})
//微信
let
code
=
getParam
(
'code'
)
let
code
=
getParam
(
'code'
)
if
(
code
)
{
if
(
code
)
{
...
@@ -42,7 +45,6 @@ class App extends Component {
...
@@ -42,7 +45,6 @@ class App extends Component {
http
.
get
(
`
${
api
[
'home'
]}
/m/wx_loginInfo/code/
${
code
}
`
)
http
.
get
(
`
${
api
[
'home'
]}
/m/wx_loginInfo/code/
${
code
}
`
)
.
then
(
res
=>
{
.
then
(
res
=>
{
let
data
=
res
.
data
let
data
=
res
.
data
console
.
log
(
res
)
if
(
data
.
errno
==
200
)
{
if
(
data
.
errno
==
200
)
{
if
(
data
.
data
[
'is_bind_mobile'
])
{
if
(
data
.
data
[
'is_bind_mobile'
])
{
window
.
location
.
assign
(
data
.
data
.
url
)
window
.
location
.
assign
(
data
.
data
.
url
)
...
@@ -51,9 +53,9 @@ class App extends Component {
...
@@ -51,9 +53,9 @@ class App extends Component {
let
user
=
this
.
transformWxUser
(
res
)
let
user
=
this
.
transformWxUser
(
res
)
let
{
role
,
uid
,
token
}
=
data
.
data
let
{
role
,
uid
,
token
}
=
data
.
data
let
expires
=
{
expires
:
addDays
(
new
Date
(),
90
)}
let
expires
=
{
expires
:
addDays
(
new
Date
(),
90
)}
jsC
ookie
.
set
(
'role'
,
role
,
expires
)
c
ookie
.
set
(
'role'
,
role
,
expires
)
jsC
ookie
.
set
(
'uid'
,
uid
,
expires
)
c
ookie
.
set
(
'uid'
,
uid
,
expires
)
jsC
ookie
.
set
(
'token'
,
token
,
expires
)
c
ookie
.
set
(
'token'
,
token
,
expires
)
this
.
props
.
setCurrentUser
(
user
)
this
.
props
.
setCurrentUser
(
user
)
}
}
}
else
{
}
else
{
...
...
src/components/passport/index.js
View file @
da9aeaf6
...
@@ -64,7 +64,7 @@ class Passport extends Component {
...
@@ -64,7 +64,7 @@ class Passport extends Component {
let
{
history
}
=
this
.
props
let
{
history
}
=
this
.
props
let
{
data
}
=
this
.
props
.
user
let
{
data
}
=
this
.
props
.
user
if
(
data
&&
Object
.
values
(
data
).
filter
(
item
=>
!!
item
).
length
)
{
if
(
data
&&
Object
.
values
(
data
).
filter
(
item
=>
!!
item
).
length
)
{
history
.
action
===
'POP'
&&
history
.
go
(
-
1
)
history
.
action
===
'POP'
&&
history
.
length
<=
3
?
history
.
push
(
'/'
)
:
history
.
go
(
-
1
)
}
}
}
}
...
...
src/router/privateRoute.js
View file @
da9aeaf6
import
React
from
'react'
;
import
React
,
{
useState
,
useEffect
}
from
'react'
;
import
{
Route
}
from
"react-router-dom"
;
import
{
Route
}
from
"react-router-dom"
;
import
{
connect
}
from
"react-redux"
;
import
{
connect
}
from
"react-redux"
;
import
jsCookie
from
'js-cookie'
import
RouteMiddlePage
from
'./route-middle-page'
import
RouteMiddlePage
from
'./route-middle-page'
import
Loading
from
'@/common/Loading'
const
PrivateRoute
=
({
component
:
Component
,
path
,
user
,
...
rest
})
=>
{
const
PrivateRoute
=
({
component
:
Component
,
path
,
user
,
...
rest
})
=>
{
let
authenticated
=
jsCookie
.
get
(
'token'
)
&&
jsCookie
.
get
(
'uid'
)
const
[
isLoading
,
setLoadingState
]
=
useState
(
true
)
const
[
authenticated
,
setAuthorization
]
=
useState
(
false
)
useEffect
(()
=>
{
let
_auth
=
!
user
.
hasError
&&
user
.
code
!=
4040
typeof
_auth
!==
'undefined'
&&
(
setAuthorization
(
_auth
)
,
setLoadingState
(
false
))
})
return
(
return
(
<
Route
{...
rest
}
render
=
{
props
=>
{
<
Route
{...
rest
}
render
=
{
props
=>
{
return
authenticated
return
<
Loading
isLoading
=
{
isLoading
}
>
?
<
Component
{...
props
}
/
>
{
authenticated
:
<
RouteMiddlePage
state
=
{{
from
:
props
.
location
}}
/
>
?
<
Component
{...
props
}
/
>
:
<
RouteMiddlePage
state
=
{{
from
:
props
.
location
}}
/>
}
<
/Loading
>
}}
/
>
}}
/
>
)
;
)
};
};
export
default
connect
(
export
default
connect
(
...
...
src/router/route-middle-page.js
View file @
da9aeaf6
...
@@ -13,7 +13,7 @@ function RouteMiddlePage(props) {
...
@@ -13,7 +13,7 @@ function RouteMiddlePage(props) {
let
{
user
,
location
,
history
}
=
props
let
{
user
,
location
,
history
}
=
props
if
(
history
.
action
===
'POP'
)
{
if
(
history
.
action
===
'POP'
&&
history
.
length
>
2
)
{
history
.
goBack
();
history
.
goBack
();
return
return
}
}
...
@@ -27,7 +27,7 @@ function RouteMiddlePage(props) {
...
@@ -27,7 +27,7 @@ function RouteMiddlePage(props) {
if
(
data
&&
Object
.
values
(
data
).
every
(
item
=>
!!
item
))
{
if
(
data
&&
Object
.
values
(
data
).
every
(
item
=>
!!
item
))
{
history
.
replace
(
location
.
pathname
)
history
.
replace
(
location
.
pathname
)
setLoadingState
(
false
)
setLoadingState
(
false
)
}
else
{
}
else
{
history
.
replace
(
'/passport'
,
{
from
:
location
})
history
.
replace
(
'/passport'
,
{
from
:
location
})
}
}
}
}
...
@@ -37,7 +37,7 @@ function RouteMiddlePage(props) {
...
@@ -37,7 +37,7 @@ function RouteMiddlePage(props) {
return
(
return
(
<
div
className
=
{
'loading-route'
}
>
<
div
className
=
{
'loading-route'
}
>
<
LoadingComponent
isLoading
=
{
isLoading
}
>
<
LoadingComponent
isLoading
=
{
isLoading
}
>
<
div
><
/div
>
<
div
/
>
<
/LoadingComponent
>
<
/LoadingComponent
>
<
/div
>
<
/div
>
);
);
...
...
src/store/userAction.js
View file @
da9aeaf6
...
@@ -54,7 +54,7 @@ const LOGOUT = 'LOGOUT'
...
@@ -54,7 +54,7 @@ const LOGOUT = 'LOGOUT'
const
logout
=
()
=>
dispatch
=>
{
const
logout
=
()
=>
dispatch
=>
{
jsCookie
.
remove
(
'token'
,
{
path
:
'/'
,
domain
:
'.julyedu.com'
})
jsCookie
.
remove
(
'token'
,
{
path
:
'/'
,
domain
:
'.julyedu.com'
})
jsCookie
.
remove
(
'uid'
,
{
path
:
'/'
,
domain
:
'.julyedu.com'
})
jsCookie
.
remove
(
'uid'
,
{
path
:
'/'
,
domain
:
'.julyedu.com'
})
dispatch
(
setCurrentUser
({}))
dispatch
(
setCurrentUser
({
hasError
:
true
}))
}
}
...
...
src/store/userReducer.js
View file @
da9aeaf6
...
@@ -4,6 +4,7 @@ import { merge } from 'lodash'
...
@@ -4,6 +4,7 @@ import { merge } from 'lodash'
const
initialState
=
{
const
initialState
=
{
hasError
:
false
,
hasError
:
false
,
code
:
0
,
msg
:
''
,
msg
:
''
,
data
:
{
data
:
{
username
:
''
,
username
:
''
,
...
...
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