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
0a386582
Commit
0a386582
authored
Apr 08, 2018
by
jim
Committed by
ιεΈ
Apr 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chang to new context api
parent
b3821d53
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
162 additions
and
141 deletions
+162
-141
package.json
package.json
+5
-3
src/components/Login/LoginItem.js
src/components/Login/LoginItem.js
+108
-88
src/components/Login/LoginTab.js
src/components/Login/LoginTab.js
+13
-10
src/components/Login/index.js
src/components/Login/index.js
+30
-32
src/components/Login/loginContext.js
src/components/Login/loginContext.js
+4
-0
src/components/Login/map.js
src/components/Login/map.js
+2
-8
No files found.
package.json
View file @
0a386582
...
@@ -23,7 +23,9 @@
...
@@ -23,7 +23,9 @@
"dependencies"
:
{
"dependencies"
:
{
"
@antv/data-set
"
:
"
^0.8.0
"
,
"
@antv/data-set
"
:
"
^0.8.0
"
,
"
@babel/polyfill
"
:
"
^7.0.0-beta.36
"
,
"
@babel/polyfill
"
:
"
^7.0.0-beta.36
"
,
"
antd
"
:
"
^3.3.3
"
,
"
@types/react
"
:
"
^16.3.5
"
,
"
@types/react-dom
"
:
"
^16.0.4
"
,
"
antd
"
:
"
^3.4.0
"
,
"
babel-runtime
"
:
"
^6.9.2
"
,
"
babel-runtime
"
:
"
^6.9.2
"
,
"
bizcharts
"
:
"
^3.1.3-beta.1
"
,
"
bizcharts
"
:
"
^3.1.3-beta.1
"
,
"
bizcharts-plugin-slider
"
:
"
^2.0.1
"
,
"
bizcharts-plugin-slider
"
:
"
^2.0.1
"
,
...
@@ -40,10 +42,10 @@
...
@@ -40,10 +42,10 @@
"
prop-types
"
:
"
^15.5.10
"
,
"
prop-types
"
:
"
^15.5.10
"
,
"
qs
"
:
"
^6.5.0
"
,
"
qs
"
:
"
^6.5.0
"
,
"
rc-drawer-menu
"
:
"
^0.5.0
"
,
"
rc-drawer-menu
"
:
"
^0.5.0
"
,
"
react
"
:
"
^16.
2.0
"
,
"
react
"
:
"
^16.
3.1
"
,
"
react-container-query
"
:
"
^0.9.1
"
,
"
react-container-query
"
:
"
^0.9.1
"
,
"
react-document-title
"
:
"
^2.0.3
"
,
"
react-document-title
"
:
"
^2.0.3
"
,
"
react-dom
"
:
"
^16.
2.0
"
,
"
react-dom
"
:
"
^16.
3.1
"
,
"
react-fittext
"
:
"
^1.0.0
"
,
"
react-fittext
"
:
"
^1.0.0
"
,
"
rollbar
"
:
"
^2.3.4
"
,
"
rollbar
"
:
"
^2.3.4
"
,
"
url-polyfill
"
:
"
^1.0.10
"
"
url-polyfill
"
:
"
^1.0.10
"
...
...
src/components/Login/LoginItem.js
View file @
0a386582
import
React
,
{
Component
}
from
'
react
'
;
import
React
,
{
Component
}
from
'
react
'
;
import
PropTypes
from
'
prop-types
'
;
import
{
Form
,
Input
,
Button
,
Row
,
Col
}
from
'
antd
'
;
import
{
Form
,
Button
,
Row
,
Col
}
from
'
antd
'
;
import
omit
from
'
omit.js
'
;
import
omit
from
'
omit.js
'
;
import
styles
from
'
./index.less
'
;
import
styles
from
'
./index.less
'
;
import
map
from
'
./map
'
;
import
ItemMap
from
'
./map
'
;
import
LoginContext
from
'
./loginContext
'
;
const
FormItem
=
Form
.
Item
;
const
FormItem
=
Form
.
Item
;
function
generator
({
defaultProps
,
defaultRules
,
type
})
{
class
WarpFormItem
extends
Component
{
return
WrappedComponent
=>
{
constructor
(
props
)
{
return
class
BasicComponent
extends
Component
{
super
(
props
);
static
contextTypes
=
{
this
.
state
=
{
form
:
PropTypes
.
object
,
count
:
0
,
updateActive
:
PropTypes
.
func
,
};
};
}
constructor
(
props
)
{
componentDidMount
()
{
super
(
props
);
if
(
this
.
props
.
updateActive
)
{
this
.
state
=
{
this
.
props
.
updateActive
(
this
.
props
.
name
);
count
:
0
,
}
};
}
}
componentWillUnmount
()
{
componentDidMount
()
{
clearInterval
(
this
.
interval
);
if
(
this
.
context
.
updateActive
)
{
}
this
.
context
.
updateActive
(
this
.
props
.
name
);
onGetCaptcha
=
()
=>
{
}
let
count
=
59
;
}
this
.
setState
({
count
});
componentWillUnmount
()
{
if
(
this
.
props
.
onGetCaptcha
)
{
this
.
props
.
onGetCaptcha
();
}
this
.
interval
=
setInterval
(()
=>
{
count
-=
1
;
this
.
setState
({
count
});
if
(
count
===
0
)
{
clearInterval
(
this
.
interval
);
clearInterval
(
this
.
interval
);
}
}
onGetCaptcha
=
()
=>
{
},
1000
);
let
count
=
59
;
};
this
.
setState
({
count
});
getFormItemOptions
=
({
onChange
,
defaultValue
,
rules
})
=>
{
if
(
this
.
props
.
onGetCaptcha
)
{
const
options
=
{
this
.
props
.
onGetCaptcha
();
rules
:
rules
||
this
.
customprops
.
rules
,
}
this
.
interval
=
setInterval
(()
=>
{
count
-=
1
;
this
.
setState
({
count
});
if
(
count
===
0
)
{
clearInterval
(
this
.
interval
);
}
},
1000
);
};
render
()
{
const
{
getFieldDecorator
}
=
this
.
context
.
form
;
const
options
=
{};
let
otherProps
=
{};
const
{
onChange
,
defaultValue
,
rules
,
name
,
...
restProps
}
=
this
.
props
;
const
{
count
}
=
this
.
state
;
options
.
rules
=
rules
||
defaultRules
;
if
(
onChange
)
{
options
.
onChange
=
onChange
;
}
if
(
defaultValue
)
{
options
.
initialValue
=
defaultValue
;
}
otherProps
=
restProps
||
otherProps
;
if
(
type
===
'
Captcha
'
)
{
const
inputProps
=
omit
(
otherProps
,
[
'
onGetCaptcha
'
]);
return
(
<
FormItem
>
<
Row
gutter
=
{
8
}
>
<
Col
span
=
{
16
}
>
{
getFieldDecorator
(
name
,
options
)(
<
WrappedComponent
{...
defaultProps
}
{...
inputProps
}
/
>
)}
<
/Col
>
<
Col
span
=
{
8
}
>
<
Button
disabled
=
{
count
}
className
=
{
styles
.
getCaptcha
}
size
=
"
large
"
onClick
=
{
this
.
onGetCaptcha
}
>
{
count
?
`
${
count
}
s`
:
'
θ·ειͺθ―η
'
}
<
/Button
>
<
/Col
>
<
/Row
>
<
/FormItem
>
);
}
return
(
<
FormItem
>
{
getFieldDecorator
(
name
,
options
)(
<
WrappedComponent
{...
defaultProps
}
{...
otherProps
}
/
>
)}
<
/FormItem
>
);
}
};
};
if
(
onChange
)
{
options
.
onChange
=
onChange
;
}
if
(
defaultValue
)
{
options
.
initialValue
=
defaultValue
;
}
return
options
;
};
};
render
()
{
const
{
count
}
=
this
.
state
;
const
{
getFieldDecorator
}
=
this
.
props
.
form
;
// θΏδΉεζ―δΈΊδΊι²ζ’restPropsδΈ εΈ¦ε ₯ onChange, defaultValue, rules props
const
{
onChange
,
customprops
,
defaultValue
,
rules
,
name
,
updateActive
,
...
restProps
}
=
this
.
props
;
// get getFieldDecorator props
const
options
=
this
.
getFormItemOptions
(
this
.
props
);
const
otherProps
=
restProps
||
{};
if
(
this
.
props
.
type
===
'
Captcha
'
)
{
const
inputProps
=
omit
(
otherProps
,
[
'
onGetCaptcha
'
]);
return
(
<
FormItem
>
<
Row
gutter
=
{
8
}
>
<
Col
span
=
{
16
}
>
{
getFieldDecorator
(
name
,
options
)(
<
Input
{...
this
.
props
.
customprops
}
{...
inputProps
}
/
>
)}
<
/Col
>
<
Col
span
=
{
8
}
>
<
Button
disabled
=
{
count
}
className
=
{
styles
.
getCaptcha
}
size
=
"
large
"
onClick
=
{
this
.
onGetCaptcha
}
>
{
count
?
`
${
count
}
s`
:
'
θ·ειͺθ―η
'
}
<
/Button
>
<
/Col
>
<
/Row
>
<
/FormItem
>
);
}
return
(
<
FormItem
>
{
getFieldDecorator
(
name
,
options
)(
<
Input
{...
this
.
props
.
customprops
}
{...
otherProps
}
/>
)
}
<
/FormItem
>
);
}
}
}
const
LoginItem
=
{};
const
LoginItem
=
{};
Object
.
keys
(
map
).
forEach
(
item
=>
{
Object
.
keys
(
ItemMap
).
forEach
(
key
=>
{
LoginItem
[
item
]
=
generator
({
const
item
=
ItemMap
[
key
];
defaultProps
:
map
[
item
].
props
,
LoginItem
[
key
]
=
props
=>
{
defaultRules
:
map
[
item
].
rules
,
return
(
type
:
item
,
<
LoginContext
.
Consumer
>
})(
map
[
item
].
component
);
{
context
=>
(
<
WarpFormItem
customprops
=
{
item
.
props
}
{...
props
}
rules
=
{
item
.
rules
}
type
=
{
key
}
updateActive
=
{
context
.
updateActive
}
form
=
{
context
.
form
}
/
>
)}
<
/LoginContext.Consumer
>
);
};
});
});
export
default
LoginItem
;
export
default
LoginItem
;
src/components/Login/LoginTab.js
View file @
0a386582
import
React
,
{
Component
}
from
'
react
'
;
import
React
,
{
Component
}
from
'
react
'
;
import
PropTypes
from
'
prop-types
'
;
import
{
Tabs
}
from
'
antd
'
;
import
{
Tabs
}
from
'
antd
'
;
import
LoginContext
from
'
./loginContext
'
;
const
{
TabPane
}
=
Tabs
;
const
{
TabPane
}
=
Tabs
;
...
@@ -12,21 +12,24 @@ const generateId = (() => {
...
@@ -12,21 +12,24 @@ const generateId = (() => {
};
};
})();
})();
export
default
class
LoginTab
extends
Component
{
class
LoginTab
extends
Component
{
static
__ANT_PRO_LOGIN_TAB
=
true
;
static
contextTypes
=
{
tabUtil
:
PropTypes
.
object
,
};
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
this
.
uniqueId
=
generateId
(
'
login-tab-
'
);
this
.
uniqueId
=
generateId
(
'
login-tab-
'
);
}
}
componentWillMount
()
{
componentDidMount
()
{
if
(
this
.
context
.
tabUtil
)
{
this
.
props
.
tabUtil
.
addTab
(
this
.
uniqueId
);
this
.
context
.
tabUtil
.
addTab
(
this
.
uniqueId
);
}
}
}
render
()
{
render
()
{
return
<
TabPane
{...
this
.
props
}
/>
;
return
<
TabPane
{...
this
.
props
}
/>
;
}
}
}
}
const
warpContext
=
props
=>
{
return
(
<
LoginContext
.
Consumer
>
{
value
=>
<
LoginTab
tabUtil
=
{
value
.
tabUtil
}
{...
props
}
/>
}
<
/LoginContext.Consumer
>
);
};
export
default
warpContext
;
src/components/Login/index.js
View file @
0a386582
...
@@ -6,6 +6,7 @@ import LoginItem from './LoginItem';
...
@@ -6,6 +6,7 @@ import LoginItem from './LoginItem';
import
LoginTab
from
'
./LoginTab
'
;
import
LoginTab
from
'
./LoginTab
'
;
import
LoginSubmit
from
'
./LoginSubmit
'
;
import
LoginSubmit
from
'
./LoginSubmit
'
;
import
styles
from
'
./index.less
'
;
import
styles
from
'
./index.less
'
;
import
LoginContext
from
'
./loginContext
'
;
@
Form
.
create
()
@
Form
.
create
()
class
Login
extends
Component
{
class
Login
extends
Component
{
...
@@ -21,17 +22,18 @@ class Login extends Component {
...
@@ -21,17 +22,18 @@ class Login extends Component {
onTabChange
:
PropTypes
.
func
,
onTabChange
:
PropTypes
.
func
,
onSubmit
:
PropTypes
.
func
,
onSubmit
:
PropTypes
.
func
,
};
};
static
childContextTypes
=
{
tabUtil
:
PropTypes
.
object
,
form
:
PropTypes
.
object
,
updateActive
:
PropTypes
.
func
,
};
state
=
{
state
=
{
type
:
this
.
props
.
defaultActiveKey
,
type
:
this
.
props
.
defaultActiveKey
,
tabs
:
[],
tabs
:
[],
active
:
{},
active
:
{},
};
};
getChildContext
()
{
onSwitch
=
type
=>
{
this
.
setState
({
type
,
});
this
.
props
.
onTabChange
(
type
);
};
getContext
=
()
=>
{
return
{
return
{
tabUtil
:
{
tabUtil
:
{
addTab
:
id
=>
{
addTab
:
id
=>
{
...
@@ -58,12 +60,6 @@ class Login extends Component {
...
@@ -58,12 +60,6 @@ class Login extends Component {
});
});
},
},
};
};
}
onSwitch
=
type
=>
{
this
.
setState
({
type
,
});
this
.
props
.
onTabChange
(
type
);
};
};
handleSubmit
=
e
=>
{
handleSubmit
=
e
=>
{
e
.
preventDefault
();
e
.
preventDefault
();
...
@@ -83,32 +79,34 @@ class Login extends Component {
...
@@ -83,32 +79,34 @@ class Login extends Component {
return
;
return
;
}
}
// eslint-disable-next-line
// eslint-disable-next-line
if
(
item
.
type
.
__ANT_PRO_LOGIN_TAB
)
{
if
(
item
.
type
.
name
===
'
warpContext
'
)
{
TabChildren
.
push
(
item
);
TabChildren
.
push
(
item
);
}
else
{
}
else
{
otherChildren
.
push
(
item
);
otherChildren
.
push
(
item
);
}
}
});
});
return
(
return
(
<
div
className
=
{
classNames
(
className
,
styles
.
login
)}
>
<
LoginContext
.
Provider
value
=
{
this
.
getContext
()}
>
<
Form
onSubmit
=
{
this
.
handleSubmit
}
>
<
div
className
=
{
classNames
(
className
,
styles
.
login
)}
>
{
tabs
.
length
?
(
<
Form
onSubmit
=
{
this
.
handleSubmit
}
>
<
div
>
{
tabs
.
length
?
(
<
Tabs
<>
animated
=
{
false
}
<
Tabs
className
=
{
styles
.
tabs
}
animated
=
{
false
}
activeKey
=
{
type
}
className
=
{
styles
.
tabs
}
onChange
=
{
this
.
onSwitch
}
activeKey
=
{
type
}
>
onChange
=
{
this
.
onSwitch
}
{
TabChildren
}
>
<
/Tabs
>
{
TabChildren
}
{
otherChildren
}
<
/Tabs
>
<
/div
>
{
otherChildren
}
)
:
(
<
/
>
[...
children
]
)
:
(
)}
[...
children
]
<
/Form
>
)}
<
/div
>
<
/Form
>
<
/div
>
<
/LoginContext.Provider
>
);
);
}
}
}
}
...
...
src/components/Login/loginContext.js
0 β 100644
View file @
0a386582
import
{
createContext
}
from
'
react
'
;
const
LoginContext
=
createContext
();
export
default
LoginContext
;
src/components/Login/map.js
View file @
0a386582
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
I
nput
,
I
con
}
from
'
antd
'
;
import
{
Icon
}
from
'
antd
'
;
import
styles
from
'
./index.less
'
;
import
styles
from
'
./index.less
'
;
const
map
=
{
export
default
{
UserName
:
{
UserName
:
{
component
:
Input
,
props
:
{
props
:
{
size
:
'
large
'
,
size
:
'
large
'
,
prefix
:
<
Icon
type
=
"
user
"
className
=
{
styles
.
prefixIcon
}
/>
,
prefix
:
<
Icon
type
=
"
user
"
className
=
{
styles
.
prefixIcon
}
/>
,
...
@@ -18,7 +17,6 @@ const map = {
...
@@ -18,7 +17,6 @@ const map = {
],
],
},
},
Password
:
{
Password
:
{
component
:
Input
,
props
:
{
props
:
{
size
:
'
large
'
,
size
:
'
large
'
,
prefix
:
<
Icon
type
=
"
lock
"
className
=
{
styles
.
prefixIcon
}
/>
,
prefix
:
<
Icon
type
=
"
lock
"
className
=
{
styles
.
prefixIcon
}
/>
,
...
@@ -33,7 +31,6 @@ const map = {
...
@@ -33,7 +31,6 @@ const map = {
],
],
},
},
Mobile
:
{
Mobile
:
{
component
:
Input
,
props
:
{
props
:
{
size
:
'
large
'
,
size
:
'
large
'
,
prefix
:
<
Icon
type
=
"
mobile
"
className
=
{
styles
.
prefixIcon
}
/>
,
prefix
:
<
Icon
type
=
"
mobile
"
className
=
{
styles
.
prefixIcon
}
/>
,
...
@@ -51,7 +48,6 @@ const map = {
...
@@ -51,7 +48,6 @@ const map = {
],
],
},
},
Captcha
:
{
Captcha
:
{
component
:
Input
,
props
:
{
props
:
{
size
:
'
large
'
,
size
:
'
large
'
,
prefix
:
<
Icon
type
=
"
mail
"
className
=
{
styles
.
prefixIcon
}
/>
,
prefix
:
<
Icon
type
=
"
mail
"
className
=
{
styles
.
prefixIcon
}
/>
,
...
@@ -65,5 +61,3 @@ const map = {
...
@@ -65,5 +61,3 @@ const map = {
],
],
},
},
};
};
export
default
map
;
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