@@ -7,25 +7,38 @@ import { useTheme } from '@shopify/restyle';
77import { logSvg , cEyes , oEyes } from './svg' ;
88
99interface LoginPageProps {
10- showPassword ?: boolean ;
10+ /** 自定义账号输入框为空时显示的文字 */
1111 usernamePlaceholder ?: string ;
12+ /** 自定义账号,密码,验证码输入框样式 */
1213 inputContainerStyle ?: object ;
14+ /** 登录按钮自定义样式 */
1315 buttonStyle ?: object ;
16+ /** 登录页自定义最外层样式 */
1417 containerStyle ?: object ;
18+ /** 登录按钮自定义文字 */
1519 buttonText ?: string ;
20+ /** 自定义忘记密码,切换登录方式 */
21+ customContent ?: React . ReactNode ;
22+ /** 登录按钮事件 */
1623 onLogin ?: ( username : string , password : string ) => void ;
24+ /** 忘记密码按钮事件 */
25+ onForgetPassword ?: ( ) => void ;
1726}
1827
1928const LoginPage : React . FC < LoginPageProps > = ( {
20- showPassword = true ,
21- usernamePlaceholder = '请输入用户名' ,
29+ usernamePlaceholder,
2230 inputContainerStyle = { } ,
2331 containerStyle = { } ,
2432 buttonStyle = { } ,
2533 buttonText = 'Login' ,
34+ customContent,
2635 onLogin,
36+ onForgetPassword,
2737} ) => {
28- const [ isShowPassword , setIsShowPassword ] = useState ( false ) ;
38+ const [ showPsd , setShowPsd ] = useState ( false ) ;
39+ const [ showCode , setShowCode ] = useState ( false ) ; // added state
40+ console . log ( 'showCode' , showCode ) ;
41+
2942 const theme = useTheme < Theme > ( ) ;
3043 const styles = createStyles ( {
3144 border : theme . colors . border || '#CCC' ,
@@ -57,43 +70,50 @@ const LoginPage: React.FC<LoginPageProps> = ({
5770 < Icon xml = { logSvg ( theme ) } size = { 30 } />
5871 < Text style = { styles . title } > Login</ Text >
5972 </ View >
60- < View style = { [ styles . inputContainer , inputContainerStyle ] } >
73+ < View style = { [ styles . inputContainer , { paddingHorizontal : 15 } , inputContainerStyle ] } >
6174 < TextInput
62- placeholder = { usernamePlaceholder }
63- placeholderTextColor = { theme . colors . icon }
75+ placeholder = { usernamePlaceholder ? usernamePlaceholder : `请输入 ${ showCode ? '手机号码' : '用户名' } ` }
76+ placeholderTextColor = { theme . colors . border }
6477 style = { styles . input }
78+ keyboardType = { showCode ? 'numeric' : 'default' }
6579 onChangeText = { onChangeUsername }
6680 />
6781 </ View >
68- { showPassword ? (
69- < View style = { [ styles . inputContainers , inputContainerStyle ] } >
82+ { ! showCode ? (
83+ < View style = { [ styles . inputContainer , styles . inputC , { paddingHorizontal : 15 } , inputContainerStyle ] } >
7084 < TextInput
7185 placeholder = "请输入密码"
72- placeholderTextColor = { theme . colors . icon }
73- secureTextEntry = { ! isShowPassword }
86+ placeholderTextColor = { theme . colors . border }
87+ secureTextEntry = { ! showPsd }
7488 style = { [ styles . input , { width : '92%' } ] }
7589 onChangeText = { onChangePassword }
7690 />
77- < TouchableOpacity onPress = { ( ) => setIsShowPassword ( ! isShowPassword ) } >
78- < Icon xml = { isShowPassword ? cEyes : oEyes } size = { 20 } />
91+ < TouchableOpacity onPress = { ( ) => setShowPsd ( ! showPsd ) } >
92+ < Icon xml = { showPsd ? cEyes : oEyes } size = { 20 } />
7993 </ TouchableOpacity >
8094 </ View >
8195 ) : (
8296 < VerificationCode
8397 value = { password }
8498 count = { 60 }
8599 onChange = { onChangePassword }
86- outerStyle = { [ styles . inputContainer , inputContainerStyle ] }
100+ outerStyle = { [ styles . inputContainer , styles . inputC , inputContainerStyle ] }
87101 />
88102 ) }
89- < View style = { styles . textSty1 } >
90- < TouchableOpacity >
91- < Text style = { styles . textSty } > 忘记密码</ Text >
92- </ TouchableOpacity >
93- < TouchableOpacity >
94- < Text style = { styles . textSty } > 验证码登录</ Text >
95- </ TouchableOpacity >
103+
104+ < View >
105+ { customContent || (
106+ < View style = { styles . textSty1 } >
107+ < TouchableOpacity onPress = { onForgetPassword } >
108+ < Text style = { styles . textSty } > 忘记密码</ Text >
109+ </ TouchableOpacity >
110+ < TouchableOpacity onPress = { ( ) => setShowCode ( ! showCode ) } >
111+ < Text style = { styles . textSty } > { `${ showCode ? '用户名' : '验证码' } 登录` } </ Text >
112+ </ TouchableOpacity >
113+ </ View >
114+ ) }
96115 </ View >
116+
97117 < TouchableOpacity style = { [ styles . button , buttonStyle ] } onPress = { handleLogin } >
98118 < Text style = { [ styles . buttonText , styles . buttonTextStyle ] } > { buttonText } </ Text >
99119 </ TouchableOpacity >
@@ -126,30 +146,22 @@ function createStyles({ border, putCol }: CreStyle) {
126146 title : {
127147 fontSize : 24 ,
128148 fontWeight : 'bold' ,
129- marginLeft : 20 ,
149+ marginLeft : 15 ,
130150 color : putCol ,
131151 } ,
132152 inputContainer : {
133153 height : 40 ,
134- marginBottom : 20 ,
135154 borderColor : border ,
136155 borderWidth : 1 ,
137156 borderRadius : 5 ,
138157 justifyContent : 'center' ,
139- paddingHorizontal : 15 ,
140158 flexDirection : 'row' ,
141159 alignItems : 'center' ,
142160 } ,
143- inputContainers : {
144- height : 40 ,
161+ inputC : {
162+ paddingHorizontal : 10 ,
163+ marginTop : 20 ,
145164 marginBottom : 5 ,
146- borderColor : border ,
147- borderWidth : 1 ,
148- borderRadius : 5 ,
149- justifyContent : 'center' ,
150- paddingHorizontal : 15 ,
151- flexDirection : 'row' ,
152- alignItems : 'center' ,
153165 } ,
154166 input : {
155167 flex : 1 ,
@@ -158,6 +170,7 @@ function createStyles({ border, putCol }: CreStyle) {
158170 button : {
159171 backgroundColor : '#1890ff' ,
160172 height : 40 ,
173+ marginTop : 5 ,
161174 borderRadius : 5 ,
162175 justifyContent : 'center' ,
163176 alignItems : 'center' ,
@@ -176,7 +189,6 @@ function createStyles({ border, putCol }: CreStyle) {
176189 flexDirection : 'row' ,
177190 alignItems : 'center' ,
178191 justifyContent : 'space-between' ,
179- marginBottom : 30 ,
180192 } ,
181193 } ) ;
182194}
0 commit comments