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
cc28e069
Commit
cc28e069
authored
Dec 29, 2017
by
WhatAKitty
Committed by
ddcat1115
Dec 29, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do with new router (#519)
* Do with new router * Move default values into form model
parent
8a15e9bd
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
298 additions
and
263 deletions
+298
-263
src/common/router.js
src/common/router.js
+3
-0
src/models/form.js
src/models/form.js
+4
-0
src/routes/Forms/StepForm/Step1.js
src/routes/Forms/StepForm/Step1.js
+110
-92
src/routes/Forms/StepForm/Step2.js
src/routes/Forms/StepForm/Step2.js
+107
-88
src/routes/Forms/StepForm/Step3.js
src/routes/Forms/StepForm/Step3.js
+53
-45
src/routes/Forms/StepForm/index.js
src/routes/Forms/StepForm/index.js
+21
-38
No files found.
src/common/router.js
View file @
cc28e069
...
@@ -54,6 +54,9 @@ export const getRouterData = (app) => {
...
@@ -54,6 +54,9 @@ export const getRouterData = (app) => {
'
/form/step-form
'
:
{
'
/form/step-form
'
:
{
component
:
dynamicWrapper
(
app
,
[
'
form
'
],
()
=>
import
(
'
../routes/Forms/StepForm
'
)),
component
:
dynamicWrapper
(
app
,
[
'
form
'
],
()
=>
import
(
'
../routes/Forms/StepForm
'
)),
},
},
'
/form/step-form/info
'
:
{
component
:
dynamicWrapper
(
app
,
[
'
form
'
],
()
=>
import
(
'
../routes/Forms/StepForm/Step1
'
)),
},
'
/form/step-form/confirm
'
:
{
'
/form/step-form/confirm
'
:
{
component
:
dynamicWrapper
(
app
,
[
'
form
'
],
()
=>
import
(
'
../routes/Forms/StepForm/Step2
'
)),
component
:
dynamicWrapper
(
app
,
[
'
form
'
],
()
=>
import
(
'
../routes/Forms/StepForm/Step2
'
)),
},
},
...
...
src/models/form.js
View file @
cc28e069
...
@@ -7,6 +7,10 @@ export default {
...
@@ -7,6 +7,10 @@ export default {
state
:
{
state
:
{
step
:
{
step
:
{
payAccount
:
'
ant-design@alipay.com
'
,
receiverAccount
:
'
test@example.com
'
,
receiverName
:
'
Alex
'
,
amount
:
'
500
'
,
},
},
regularFormSubmitting
:
false
,
regularFormSubmitting
:
false
,
stepFormSubmitting
:
false
,
stepFormSubmitting
:
false
,
...
...
src/routes/Forms/StepForm/Step1.js
View file @
cc28e069
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
connect
}
from
'
dva
'
;
import
{
Form
,
Input
,
Button
,
Select
,
Divider
}
from
'
antd
'
;
import
{
Form
,
Input
,
Button
,
Select
,
Divider
}
from
'
antd
'
;
import
{
routerRedux
}
from
'
dva/router
'
;
import
{
routerRedux
}
from
'
dva/router
'
;
import
styles
from
'
./style.less
'
;
import
styles
from
'
./style.less
'
;
const
{
Option
}
=
Select
;
const
{
Option
}
=
Select
;
export
default
({
formItemLayout
,
form
,
dispatch
,
data
})
=>
{
const
formItemLayout
=
{
labelCol
:
{
span
:
5
,
},
wrapperCol
:
{
span
:
19
,
},
};
@
Form
.
create
()
class
Step1
extends
React
.
PureComponent
{
render
()
{
const
{
form
,
dispatch
,
data
}
=
this
.
props
;
const
{
getFieldDecorator
,
validateFields
}
=
form
;
const
{
getFieldDecorator
,
validateFields
}
=
form
;
const
onValidateForm
=
()
=>
{
const
onValidateForm
=
()
=>
{
validateFields
((
err
,
values
)
=>
{
validateFields
((
err
,
values
)
=>
{
...
@@ -26,7 +39,7 @@ export default ({ formItemLayout, form, dispatch, data }) => {
...
@@ -26,7 +39,7 @@ export default ({ formItemLayout, form, dispatch, data }) => {
label
=
"
付款账户
"
label
=
"
付款账户
"
>
>
{
getFieldDecorator
(
'
payAccount
'
,
{
{
getFieldDecorator
(
'
payAccount
'
,
{
initialValue
:
data
.
payAccount
||
'
ant-design@alipay.com
'
,
initialValue
:
data
.
payAccount
,
rules
:
[{
required
:
true
,
message
:
'
请选择付款账户
'
}],
rules
:
[{
required
:
true
,
message
:
'
请选择付款账户
'
}],
})(
})(
<
Select
placeholder
=
"
test@example.com
"
>
<
Select
placeholder
=
"
test@example.com
"
>
...
@@ -44,7 +57,7 @@ export default ({ formItemLayout, form, dispatch, data }) => {
...
@@ -44,7 +57,7 @@ export default ({ formItemLayout, form, dispatch, data }) => {
<
Option
value
=
"
bank
"
>
银行账户
<
/Option
>
<
Option
value
=
"
bank
"
>
银行账户
<
/Option
>
<
/Select
>
<
/Select
>
{
getFieldDecorator
(
'
receiverAccount
'
,
{
{
getFieldDecorator
(
'
receiverAccount
'
,
{
initialValue
:
data
.
receiverAccount
||
'
test@example.com
'
,
initialValue
:
data
.
receiverAccount
,
rules
:
[
rules
:
[
{
required
:
true
,
message
:
'
请输入收款人账户
'
},
{
required
:
true
,
message
:
'
请输入收款人账户
'
},
{
type
:
'
email
'
,
message
:
'
账户名应为邮箱格式
'
},
{
type
:
'
email
'
,
message
:
'
账户名应为邮箱格式
'
},
...
@@ -59,7 +72,7 @@ export default ({ formItemLayout, form, dispatch, data }) => {
...
@@ -59,7 +72,7 @@ export default ({ formItemLayout, form, dispatch, data }) => {
label
=
"
收款人姓名
"
label
=
"
收款人姓名
"
>
>
{
getFieldDecorator
(
'
receiverName
'
,
{
{
getFieldDecorator
(
'
receiverName
'
,
{
initialValue
:
data
.
receiverName
||
'
Alex
'
,
initialValue
:
data
.
receiverName
,
rules
:
[{
required
:
true
,
message
:
'
请输入收款人姓名
'
}],
rules
:
[{
required
:
true
,
message
:
'
请输入收款人姓名
'
}],
})(
})(
<
Input
placeholder
=
"
请输入收款人姓名
"
/>
<
Input
placeholder
=
"
请输入收款人姓名
"
/>
...
@@ -70,7 +83,7 @@ export default ({ formItemLayout, form, dispatch, data }) => {
...
@@ -70,7 +83,7 @@ export default ({ formItemLayout, form, dispatch, data }) => {
label
=
"
转账金额
"
label
=
"
转账金额
"
>
>
{
getFieldDecorator
(
'
amount
'
,
{
{
getFieldDecorator
(
'
amount
'
,
{
initialValue
:
data
.
amount
||
'
500
'
,
initialValue
:
data
.
amount
,
rules
:
[
rules
:
[
{
required
:
true
,
message
:
'
请输入转账金额
'
},
{
required
:
true
,
message
:
'
请输入转账金额
'
},
{
pattern
:
/^
(\d
+
)((?:\.\d
+
)?)
$/
,
message
:
'
请输入合法金额数字
'
},
{
pattern
:
/^
(\d
+
)((?:\.\d
+
)?)
$/
,
message
:
'
请输入合法金额数字
'
},
...
@@ -101,4 +114,9 @@ export default ({ formItemLayout, form, dispatch, data }) => {
...
@@ -101,4 +114,9 @@ export default ({ formItemLayout, form, dispatch, data }) => {
<
/div
>
<
/div
>
<
/div
>
<
/div
>
);
);
};
}
}
export
default
connect
(({
form
})
=>
({
data
:
form
.
step
,
}))(
Step1
);
src/routes/Forms/StepForm/Step2.js
View file @
cc28e069
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
connect
}
from
'
dva
'
;
import
{
Form
,
Input
,
Button
,
Alert
,
Divider
}
from
'
antd
'
;
import
{
Form
,
Input
,
Button
,
Alert
,
Divider
}
from
'
antd
'
;
import
{
routerRedux
}
from
'
dva/router
'
;
import
{
routerRedux
}
from
'
dva/router
'
;
import
{
digitUppercase
}
from
'
../../../utils/utils
'
;
import
{
digitUppercase
}
from
'
../../../utils/utils
'
;
import
styles
from
'
./style.less
'
;
import
styles
from
'
./style.less
'
;
export
default
({
formItemLayout
,
form
,
data
,
dispatch
,
submitting
})
=>
{
const
formItemLayout
=
{
labelCol
:
{
span
:
5
,
},
wrapperCol
:
{
span
:
19
,
},
};
@
Form
.
create
()
class
Step2
extends
React
.
PureComponent
{
render
()
{
const
{
form
,
data
,
dispatch
,
submitting
}
=
this
.
props
;
const
{
getFieldDecorator
,
validateFields
}
=
form
;
const
{
getFieldDecorator
,
validateFields
}
=
form
;
const
onPrev
=
()
=>
{
const
onPrev
=
()
=>
{
dispatch
(
routerRedux
.
push
(
'
/form/step-form
'
));
dispatch
(
routerRedux
.
push
(
'
/form/step-form
'
));
...
@@ -92,4 +105,10 @@ export default ({ formItemLayout, form, data, dispatch, submitting }) => {
...
@@ -92,4 +105,10 @@ export default ({ formItemLayout, form, data, dispatch, submitting }) => {
<
/Form.Item
>
<
/Form.Item
>
<
/Form
>
<
/Form
>
);
);
};
}
}
export
default
connect
(({
form
})
=>
({
submitting
:
form
.
stepFormSubmitting
,
data
:
form
.
step
,
}))(
Step2
);
src/routes/Forms/StepForm/Step3.js
View file @
cc28e069
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
connect
}
from
'
dva
'
;
import
{
Button
,
Row
,
Col
}
from
'
antd
'
;
import
{
Button
,
Row
,
Col
}
from
'
antd
'
;
import
{
routerRedux
}
from
'
dva/router
'
;
import
{
routerRedux
}
from
'
dva/router
'
;
import
Result
from
'
../../../components/Result
'
;
import
Result
from
'
../../../components/Result
'
;
import
styles
from
'
./style.less
'
;
import
styles
from
'
./style.less
'
;
export
default
({
dispatch
,
data
})
=>
{
class
Step3
extends
React
.
PureComponent
{
render
()
{
const
{
dispatch
,
data
}
=
this
.
props
;
const
onFinish
=
()
=>
{
const
onFinish
=
()
=>
{
dispatch
(
routerRedux
.
push
(
'
/form/step-form
'
));
dispatch
(
routerRedux
.
push
(
'
/form/step-form
'
));
};
};
...
@@ -48,4 +51,9 @@ export default ({ dispatch, data }) => {
...
@@ -48,4 +51,9 @@ export default ({ dispatch, data }) => {
className
=
{
styles
.
result
}
className
=
{
styles
.
result
}
/
>
/
>
);
);
};
}
}
export
default
connect
(({
form
})
=>
({
data
:
form
.
step
,
}))(
Step3
);
src/routes/Forms/StepForm/index.js
View file @
cc28e069
import
React
,
{
PureComponent
}
from
'
react
'
;
import
React
,
{
PureComponent
}
from
'
react
'
;
import
{
connect
}
from
'
dva
'
;
import
{
Route
,
Redirect
,
Switch
}
from
'
dva/router
'
;
import
{
Card
,
Steps
,
Form
}
from
'
antd
'
;
import
{
Card
,
Steps
}
from
'
antd
'
;
import
PageHeaderLayout
from
'
../../../layouts/PageHeaderLayout
'
;
import
PageHeaderLayout
from
'
../../../layouts/PageHeaderLayout
'
;
import
Step1
from
'
./Step1
'
;
import
NotFound
from
'
../../Exception/404
'
;
import
Step2
from
'
./Step2
'
;
import
{
getRoutes
}
from
'
../../../utils/utils
'
;
import
Step3
from
'
./Step3
'
;
import
styles
from
'
../style.less
'
;
import
styles
from
'
../style.less
'
;
const
{
Step
}
=
Steps
;
const
{
Step
}
=
Steps
;
@
Form
.
create
()
export
default
class
StepForm
extends
PureComponent
{
class
StepForm
extends
PureComponent
{
getCurrentStep
()
{
getCurrentStep
()
{
const
{
location
}
=
this
.
props
;
const
{
location
}
=
this
.
props
;
const
{
pathname
}
=
location
;
const
{
pathname
}
=
location
;
const
pathList
=
pathname
.
split
(
'
/
'
);
const
pathList
=
pathname
.
split
(
'
/
'
);
switch
(
pathList
[
pathList
.
length
-
1
])
{
switch
(
pathList
[
pathList
.
length
-
1
])
{
case
'
step-form
'
:
return
0
;
case
'
info
'
:
return
0
;
case
'
confirm
'
:
return
1
;
case
'
confirm
'
:
return
1
;
case
'
result
'
:
return
2
;
case
'
result
'
:
return
2
;
default
:
return
0
;
default
:
return
0
;
}
}
}
}
getCurrentComponent
()
{
const
componentMap
=
{
0
:
Step1
,
1
:
Step2
,
2
:
Step3
,
};
return
componentMap
[
this
.
getCurrentStep
()];
}
render
()
{
render
()
{
const
{
form
,
stepFormData
,
submitting
,
dispatch
}
=
this
.
props
;
const
{
match
,
routerData
}
=
this
.
props
;
const
formItemLayout
=
{
labelCol
:
{
span
:
5
,
},
wrapperCol
:
{
span
:
19
,
},
};
const
CurrentComponent
=
this
.
getCurrentComponent
();
return
(
return
(
<
PageHeaderLayout
title
=
"
分步表单
"
content
=
"
将一个冗长或用户不熟悉的表单任务分成多个步骤,指导用户完成。
"
>
<
PageHeaderLayout
title
=
"
分步表单
"
content
=
"
将一个冗长或用户不熟悉的表单任务分成多个步骤,指导用户完成。
"
>
<
Card
bordered
=
{
false
}
>
<
Card
bordered
=
{
false
}
>
...
@@ -50,21 +31,23 @@ class StepForm extends PureComponent {
...
@@ -50,21 +31,23 @@ class StepForm extends PureComponent {
<
Step
title
=
"
确认转账信息
"
/>
<
Step
title
=
"
确认转账信息
"
/>
<
Step
title
=
"
完成
"
/>
<
Step
title
=
"
完成
"
/>
<
/Steps
>
<
/Steps
>
<
CurrentComponent
<
Switch
>
formItemLayout
=
{
formItemLayout
}
{
form
=
{
form
}
getRoutes
(
match
.
path
,
routerData
).
map
(
item
=>
(
dispatch
=
{
dispatch
}
<
Route
data
=
{
stepFormData
}
key
=
{
item
.
key
}
submitting
=
{
submitting
}
path
=
{
item
.
path
}
component
=
{
item
.
component
}
exact
=
{
item
.
exact
}
/
>
/
>
))
}
<
Redirect
exact
from
=
"
/form/step-form
"
to
=
"
/form/step-form/info
"
/>
<
Route
render
=
{
NotFound
}
/
>
<
/Switch
>
<
/div
>
<
/div
>
<
/Card
>
<
/Card
>
<
/PageHeaderLayout
>
<
/PageHeaderLayout
>
);
);
}
}
}
}
export
default
connect
(
state
=>
({
stepFormData
:
state
.
form
.
step
,
submitting
:
state
.
form
.
stepFormSubmitting
,
}))(
StepForm
);
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