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
P
pro-blocks
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
pro-blocks
Commits
2c3214f1
Commit
2c3214f1
authored
Jun 05, 2018
by
lyingd
Committed by
陈帅
Jun 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Login.Captcha组件支持countDown,onGetCaptcha支持Promise (#1305)
parent
add25295
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
97 additions
and
38 deletions
+97
-38
.roadhogrc.mock.js
.roadhogrc.mock.js
+29
-22
mock/api.js
mock/api.js
+9
-0
src/components/Login/LoginItem.js
src/components/Login/LoginItem.js
+20
-11
src/components/Login/index.en-US.md
src/components/Login/index.en-US.md
+2
-1
src/components/Login/index.zh-CN.md
src/components/Login/index.zh-CN.md
+2
-1
src/models/login.js
src/models/login.js
+4
-1
src/routes/User/Login.js
src/routes/User/Login.js
+27
-2
src/services/api.js
src/services/api.js
+4
-0
No files found.
.roadhogrc.mock.js
View file @
2c3214f1
import
mockjs
from
'
mockjs
'
;
import
mockjs
from
'
mockjs
'
;
import
{
getRule
,
postRule
}
from
'
./mock/rule
'
;
import
{
getRule
,
postRule
}
from
'
./mock/rule
'
;
import
{
getActivities
,
getNotice
,
getFakeList
,
postFakeList
}
from
'
./mock/api
'
;
import
{
getActivities
,
getNotice
,
getFakeList
,
postFakeList
,
getFakeCaptcha
}
from
'
./mock/api
'
;
import
{
getFakeChartData
}
from
'
./mock/chart
'
;
import
{
getFakeChartData
}
from
'
./mock/chart
'
;
import
{
getProfileBasicData
}
from
'
./mock/profile
'
;
import
{
getProfileBasicData
}
from
'
./mock/profile
'
;
import
{
getProfileAdvancedData
}
from
'
./mock/profile
'
;
import
{
getProfileAdvancedData
}
from
'
./mock/profile
'
;
...
@@ -24,32 +24,38 @@ const proxy = {
...
@@ -24,32 +24,38 @@ const proxy = {
},
},
$body
:
{
$body
:
{
name
:
'
Serati Ma
'
,
name
:
'
Serati Ma
'
,
avatar
:
avatar
:
'
https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png
'
,
'
https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png
'
,
userid
:
'
00000001
'
,
userid
:
'
00000001
'
,
email
:
'
antdesign@alipay.com
'
,
email
:
'
antdesign@alipay.com
'
,
signature
:
'
海纳百川,有容乃大
'
,
signature
:
'
海纳百川,有容乃大
'
,
title
:
'
交互专家
'
,
title
:
'
交互专家
'
,
group
:
'
蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED
'
,
group
:
'
蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED
'
,
tags
:
[{
tags
:
[
{
key
:
'
0
'
,
key
:
'
0
'
,
label
:
'
很有想法的
'
,
label
:
'
很有想法的
'
,
},
{
},
{
key
:
'
1
'
,
key
:
'
1
'
,
label
:
'
专注设计
'
,
label
:
'
专注设计
'
,
},
{
},
{
key
:
'
2
'
,
key
:
'
2
'
,
label
:
'
辣~
'
,
label
:
'
辣~
'
,
},
{
},
{
key
:
'
3
'
,
key
:
'
3
'
,
label
:
'
大长腿
'
,
label
:
'
大长腿
'
,
},
{
},
{
key
:
'
4
'
,
key
:
'
4
'
,
label
:
'
川妹子
'
,
label
:
'
川妹子
'
,
},
{
},
{
key
:
'
5
'
,
key
:
'
5
'
,
label
:
'
海纳百川
'
,
label
:
'
海纳百川
'
,
}],
},
],
notifyCount
:
12
,
notifyCount
:
12
,
country
:
'
China
'
,
country
:
'
China
'
,
geographic
:
{
geographic
:
{
...
@@ -176,6 +182,7 @@ const proxy = {
...
@@ -176,6 +182,7 @@ const proxy = {
},
},
'
GET /api/geographic/province
'
:
getProvince
,
'
GET /api/geographic/province
'
:
getProvince
,
'
GET /api/geographic/city/:province
'
:
getCity
,
'
GET /api/geographic/city/:province
'
:
getCity
,
'
GET /api/captcha
'
:
getFakeCaptcha
,
};
};
export
default
(
noProxy
?
{}
:
delay
(
proxy
,
1000
));
export
default
(
noProxy
?
{}
:
delay
(
proxy
,
1000
));
mock/api.js
View file @
2c3214f1
...
@@ -332,9 +332,18 @@ export const getActivities = [
...
@@ -332,9 +332,18 @@ export const getActivities = [
},
},
];
];
export
function
getFakeCaptcha
(
req
,
res
)
{
if
(
res
&&
res
.
json
)
{
res
.
json
(
'
captcha-xxx
'
);
}
else
{
return
'
captcha-xxx
'
;
}
}
export
default
{
export
default
{
getNotice
,
getNotice
,
getActivities
,
getActivities
,
getFakeList
,
getFakeList
,
postFakeList
,
postFakeList
,
getFakeCaptcha
,
};
};
src/components/Login/LoginItem.js
View file @
2c3214f1
...
@@ -23,18 +23,16 @@ class WarpFormItem extends Component {
...
@@ -23,18 +23,16 @@ class WarpFormItem extends Component {
clearInterval
(
this
.
interval
);
clearInterval
(
this
.
interval
);
}
}
onGetCaptcha
=
()
=>
{
onGetCaptcha
=
()
=>
{
let
count
=
59
;
const
{
onGetCaptcha
}
=
this
.
props
;
this
.
setState
({
count
})
;
const
result
=
onGetCaptcha
?
onGetCaptcha
()
:
null
;
if
(
this
.
props
.
onGetCaptcha
)
{
if
(
result
===
false
)
{
this
.
props
.
onGetCaptcha
()
;
return
;
}
}
this
.
interval
=
setInterval
(()
=>
{
if
(
result
instanceof
Promise
)
{
count
-=
1
;
result
.
then
(
this
.
runGetCaptchaCountDown
);
this
.
setState
({
count
});
}
else
{
if
(
count
===
0
)
{
this
.
runGetCaptchaCountDown
();
clearInterval
(
this
.
interval
);
}
}
},
1000
);
};
};
getFormItemOptions
=
({
onChange
,
defaultValue
,
rules
})
=>
{
getFormItemOptions
=
({
onChange
,
defaultValue
,
rules
})
=>
{
const
options
=
{
const
options
=
{
...
@@ -48,6 +46,17 @@ class WarpFormItem extends Component {
...
@@ -48,6 +46,17 @@ class WarpFormItem extends Component {
}
}
return
options
;
return
options
;
};
};
runGetCaptchaCountDown
=
()
=>
{
let
count
=
this
.
props
.
countDown
||
59
;
this
.
setState
({
count
});
this
.
interval
=
setInterval
(()
=>
{
count
-=
1
;
this
.
setState
({
count
});
if
(
count
===
0
)
{
clearInterval
(
this
.
interval
);
}
},
1000
);
};
render
()
{
render
()
{
const
{
count
}
=
this
.
state
;
const
{
count
}
=
this
.
state
;
...
...
src/components/Login/index.en-US.md
View file @
2c3214f1
...
@@ -38,7 +38,8 @@ Apart from the above properties, Login.Username also support all properties of a
...
@@ -38,7 +38,8 @@ Apart from the above properties, Login.Username also support all properties of a
Property | Description | Type | Default
Property | Description | Type | Default
----|------|-----|------
----|------|-----|------
onGetCaptcha | callback on getting a new Captcha | () => void | -
onGetCaptcha | callback on getting a new Captcha | () => (void
\|
false
\|
Promise) | -
countDown | count down | number |-
Apart from the above properties, _Login.Captcha_ support the same properties with _Login.UserName_.
Apart from the above properties, _Login.Captcha_ support the same properties with _Login.UserName_.
...
...
src/components/Login/index.zh-CN.md
View file @
2c3214f1
...
@@ -39,7 +39,8 @@ rules | 校验规则,同 Form getFieldDecorator(id, options) 中 [option.rules
...
@@ -39,7 +39,8 @@ rules | 校验规则,同 Form getFieldDecorator(id, options) 中 [option.rules
参数 | 说明 | 类型 | 默认值
参数 | 说明 | 类型 | 默认值
----|------|-----|------
----|------|-----|------
onGetCaptcha | 点击获取校验码的回调 | () => void | -
onGetCaptcha | 点击获取校验码的回调 | () => (void
\|
false
\|
Promise) | -
countDown | 倒计时 | number |-
除上述属性以外,Login.Captcha 支持的属性与 Login.UserName 相同。
除上述属性以外,Login.Captcha 支持的属性与 Login.UserName 相同。
...
...
src/models/login.js
View file @
2c3214f1
import
{
routerRedux
}
from
'
dva/router
'
;
import
{
routerRedux
}
from
'
dva/router
'
;
import
{
fakeAccountLogin
}
from
'
../services/api
'
;
import
{
fakeAccountLogin
,
getFakeCaptcha
}
from
'
../services/api
'
;
import
{
setAuthority
}
from
'
../utils/authority
'
;
import
{
setAuthority
}
from
'
../utils/authority
'
;
import
{
reloadAuthorized
}
from
'
../utils/Authorized
'
;
import
{
reloadAuthorized
}
from
'
../utils/Authorized
'
;
...
@@ -43,6 +43,9 @@ export default {
...
@@ -43,6 +43,9 @@ export default {
yield
put
(
routerRedux
.
push
(
'
/user/login
'
));
yield
put
(
routerRedux
.
push
(
'
/user/login
'
));
}
}
},
},
*
getCaptcha
({
payload
},
{
call
})
{
yield
call
(
getFakeCaptcha
,
payload
);
},
},
},
reducers
:
{
reducers
:
{
...
...
src/routes/User/Login.js
View file @
2c3214f1
...
@@ -21,6 +21,24 @@ export default class LoginPage extends Component {
...
@@ -21,6 +21,24 @@ export default class LoginPage extends Component {
this
.
setState
({
type
});
this
.
setState
({
type
});
};
};
onGetCaptcha
=
()
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
loginForm
.
validateFields
([
'
mobile
'
],
{},
(
err
,
values
)
=>
{
if
(
err
)
{
reject
(
err
);
}
else
{
this
.
props
.
dispatch
({
type
:
'
login/getCaptcha
'
,
payload
:
values
.
mobile
,
})
.
then
(
resolve
)
.
catch
(
reject
);
}
});
});
};
loginForm
;
handleSubmit
=
(
err
,
values
)
=>
{
handleSubmit
=
(
err
,
values
)
=>
{
const
{
type
}
=
this
.
state
;
const
{
type
}
=
this
.
state
;
if
(
!
err
)
{
if
(
!
err
)
{
...
@@ -49,7 +67,14 @@ export default class LoginPage extends Component {
...
@@ -49,7 +67,14 @@ export default class LoginPage extends Component {
const
{
type
}
=
this
.
state
;
const
{
type
}
=
this
.
state
;
return
(
return
(
<
div
className
=
{
styles
.
main
}
>
<
div
className
=
{
styles
.
main
}
>
<
Login
defaultActiveKey
=
{
type
}
onTabChange
=
{
this
.
onTabChange
}
onSubmit
=
{
this
.
handleSubmit
}
>
<
Login
defaultActiveKey
=
{
type
}
onTabChange
=
{
this
.
onTabChange
}
onSubmit
=
{
this
.
handleSubmit
}
ref
=
{
form
=>
{
this
.
loginForm
=
form
;
}}
>
<
Tab
key
=
"
account
"
tab
=
"
账户密码登录
"
>
<
Tab
key
=
"
account
"
tab
=
"
账户密码登录
"
>
{
login
.
status
===
'
error
'
&&
{
login
.
status
===
'
error
'
&&
login
.
type
===
'
account
'
&&
login
.
type
===
'
account
'
&&
...
@@ -64,7 +89,7 @@ export default class LoginPage extends Component {
...
@@ -64,7 +89,7 @@ export default class LoginPage extends Component {
!
login
.
submitting
&&
!
login
.
submitting
&&
this
.
renderMessage
(
'
验证码错误
'
)}
this
.
renderMessage
(
'
验证码错误
'
)}
<
Mobile
name
=
"
mobile
"
/>
<
Mobile
name
=
"
mobile
"
/>
<
Captcha
name
=
"
captcha
"
/>
<
Captcha
name
=
"
captcha
"
countDown
=
{
120
}
onGetCaptcha
=
{
this
.
onGetCaptcha
}
/
>
<
/Tab
>
<
/Tab
>
<
div
>
<
div
>
<
Checkbox
checked
=
{
this
.
state
.
autoLogin
}
onChange
=
{
this
.
changeAutoLogin
}
>
<
Checkbox
checked
=
{
this
.
state
.
autoLogin
}
onChange
=
{
this
.
changeAutoLogin
}
>
...
...
src/services/api.js
View file @
2c3214f1
...
@@ -120,3 +120,7 @@ export async function fakeRegister(params) {
...
@@ -120,3 +120,7 @@ export async function fakeRegister(params) {
export
async
function
queryNotices
()
{
export
async
function
queryNotices
()
{
return
request
(
'
/api/notices
'
);
return
request
(
'
/api/notices
'
);
}
}
export
async
function
getFakeCaptcha
(
mobile
)
{
return
request
(
`/api/captcha?mobile=
${
mobile
}
`
);
}
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