Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
753dc958
Commit
753dc958
authored
Dec 11, 2017
by
afc163
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Login code
parent
e783edb5
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
47 deletions
+20
-47
.roadhogrc.mock.js
.roadhogrc.mock.js
+5
-5
src/models/login.js
src/models/login.js
+7
-21
src/routes/User/Login.js
src/routes/User/Login.js
+8
-14
src/services/api.js
src/services/api.js
+0
-7
No files found.
.roadhogrc.mock.js
View file @
753dc958
...
@@ -69,11 +69,11 @@ const proxy = {
...
@@ -69,11 +69,11 @@ const proxy = {
'
GET /api/profile/basic
'
:
getProfileBasicData
,
'
GET /api/profile/basic
'
:
getProfileBasicData
,
'
GET /api/profile/advanced
'
:
getProfileAdvancedData
,
'
GET /api/profile/advanced
'
:
getProfileAdvancedData
,
'
POST /api/login/account
'
:
(
req
,
res
)
=>
{
'
POST /api/login/account
'
:
(
req
,
res
)
=>
{
const
{
password
,
userName
}
=
req
.
body
;
const
{
password
,
userName
,
type
}
=
req
.
body
;
res
.
send
({
status
:
password
===
'
888888
'
&&
userName
===
'
admin
'
?
'
ok
'
:
'
error
'
,
type
:
'
account
'
});
res
.
send
({
}
,
status
:
password
===
'
888888
'
&&
userName
===
'
admin
'
?
'
ok
'
:
'
error
'
,
'
POST /api/login/mobile
'
:
(
req
,
res
)
=>
{
type
,
res
.
send
({
status
:
'
ok
'
,
type
:
'
mobile
'
});
});
},
},
'
POST /api/register
'
:
(
req
,
res
)
=>
{
'
POST /api/register
'
:
(
req
,
res
)
=>
{
res
.
send
({
status
:
'
ok
'
});
res
.
send
({
status
:
'
ok
'
});
...
...
src/models/login.js
View file @
753dc958
import
{
routerRedux
}
from
'
dva/router
'
;
import
{
routerRedux
}
from
'
dva/router
'
;
import
{
fakeAccountLogin
,
fakeMobileLogin
}
from
'
../services/api
'
;
import
{
fakeAccountLogin
}
from
'
../services/api
'
;
export
default
{
export
default
{
namespace
:
'
login
'
,
namespace
:
'
login
'
,
...
@@ -9,7 +9,7 @@ export default {
...
@@ -9,7 +9,7 @@ export default {
},
},
effects
:
{
effects
:
{
*
accountSubmit
({
payload
},
{
call
,
put
})
{
*
login
({
payload
},
{
call
,
put
})
{
yield
put
({
yield
put
({
type
:
'
changeSubmitting
'
,
type
:
'
changeSubmitting
'
,
payload
:
true
,
payload
:
true
,
...
@@ -19,25 +19,10 @@ export default {
...
@@ -19,25 +19,10 @@ export default {
type
:
'
changeLoginStatus
'
,
type
:
'
changeLoginStatus
'
,
payload
:
response
,
payload
:
response
,
});
});
yield
put
({
// Login successfully
type
:
'
changeSubmitting
'
,
if
(
response
.
status
===
'
ok
'
)
{
payload
:
false
,
yield
put
(
routerRedux
.
push
(
'
/
'
));
});
}
},
*
mobileSubmit
(
_
,
{
call
,
put
})
{
yield
put
({
type
:
'
changeSubmitting
'
,
payload
:
true
,
});
const
response
=
yield
call
(
fakeMobileLogin
);
yield
put
({
type
:
'
changeLoginStatus
'
,
payload
:
response
,
});
yield
put
({
type
:
'
changeSubmitting
'
,
payload
:
false
,
});
},
},
*
logout
(
_
,
{
put
})
{
*
logout
(
_
,
{
put
})
{
yield
put
({
yield
put
({
...
@@ -56,6 +41,7 @@ export default {
...
@@ -56,6 +41,7 @@ export default {
...
state
,
...
state
,
status
:
payload
.
status
,
status
:
payload
.
status
,
type
:
payload
.
type
,
type
:
payload
.
type
,
submitting
:
false
,
};
};
},
},
changeSubmitting
(
state
,
{
payload
})
{
changeSubmitting
(
state
,
{
payload
})
{
...
...
src/routes/User/Login.js
View file @
753dc958
import
React
,
{
Component
}
from
'
react
'
;
import
React
,
{
Component
}
from
'
react
'
;
import
{
connect
}
from
'
dva
'
;
import
{
connect
}
from
'
dva
'
;
import
{
routerRedux
,
Link
}
from
'
dva/router
'
;
import
{
Link
}
from
'
dva/router
'
;
import
{
Form
,
Input
,
Tabs
,
Button
,
Icon
,
Checkbox
,
Row
,
Col
,
Alert
}
from
'
antd
'
;
import
{
Form
,
Input
,
Tabs
,
Button
,
Icon
,
Checkbox
,
Row
,
Col
,
Alert
}
from
'
antd
'
;
import
styles
from
'
./Login.less
'
;
import
styles
from
'
./Login.less
'
;
...
@@ -17,20 +17,12 @@ export default class Login extends Component {
...
@@ -17,20 +17,12 @@ export default class Login extends Component {
type
:
'
account
'
,
type
:
'
account
'
,
}
}
componentWillReceiveProps
(
nextProps
)
{
if
(
nextProps
.
login
.
status
===
'
ok
'
)
{
this
.
props
.
dispatch
(
routerRedux
.
push
(
'
/
'
));
}
}
componentWillUnmount
()
{
componentWillUnmount
()
{
clearInterval
(
this
.
interval
);
clearInterval
(
this
.
interval
);
}
}
onSwitch
=
(
key
)
=>
{
onSwitch
=
(
type
)
=>
{
this
.
setState
({
this
.
setState
({
type
});
type
:
key
,
});
}
}
onGetCaptcha
=
()
=>
{
onGetCaptcha
=
()
=>
{
...
@@ -47,13 +39,15 @@ export default class Login extends Component {
...
@@ -47,13 +39,15 @@ export default class Login extends Component {
handleSubmit
=
(
e
)
=>
{
handleSubmit
=
(
e
)
=>
{
e
.
preventDefault
();
e
.
preventDefault
();
const
{
type
}
=
this
.
state
;
this
.
props
.
form
.
validateFields
({
force
:
true
},
this
.
props
.
form
.
validateFields
({
force
:
true
},
(
err
,
values
)
=>
{
(
err
,
values
)
=>
{
if
(
!
err
)
{
if
(
!
err
)
{
this
.
props
.
dispatch
({
this
.
props
.
dispatch
({
type
:
`login/
${
type
}
Submit`
,
type
:
'
login/login
'
,
payload
:
values
,
payload
:
{
...
values
,
type
:
this
.
state
.
type
,
},
});
});
}
}
}
}
...
...
src/services/api.js
View file @
753dc958
...
@@ -67,13 +67,6 @@ export async function fakeAccountLogin(params) {
...
@@ -67,13 +67,6 @@ export async function fakeAccountLogin(params) {
});
});
}
}
export
async
function
fakeMobileLogin
(
params
)
{
return
request
(
'
/api/login/mobile
'
,
{
method
:
'
POST
'
,
body
:
params
,
});
}
export
async
function
fakeRegister
(
params
)
{
export
async
function
fakeRegister
(
params
)
{
return
request
(
'
/api/register
'
,
{
return
request
(
'
/api/register
'
,
{
method
:
'
POST
'
,
method
:
'
POST
'
,
...
...
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