Skip to content

Commit 690581f

Browse files
author
hy
committed
fix(LoginPage):优化LoginPage登录页面组件
1 parent edd9b88 commit 690581f

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

packages/core/src/LoginPage/index.tsx

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,30 @@ import { useTheme } from '@shopify/restyle';
77
import { logSvg, cEyes, oEyes } from './svg';
88

99
interface LoginPageProps {
10-
showPassword?: boolean;
1110
usernamePlaceholder?: string;
1211
inputContainerStyle?: object;
1312
buttonStyle?: object;
1413
containerStyle?: object;
1514
buttonText?: string;
15+
customContent?: React.ReactNode;
1616
onLogin?: (username: string, password: string) => void;
17+
onForgetPassword?: () => void;
1718
}
1819

1920
const LoginPage: React.FC<LoginPageProps> = ({
20-
showPassword = true,
21-
usernamePlaceholder = '请输入用户名',
21+
usernamePlaceholder,
2222
inputContainerStyle = {},
2323
containerStyle = {},
2424
buttonStyle = {},
2525
buttonText = 'Login',
26+
customContent,
2627
onLogin,
28+
onForgetPassword,
2729
}) => {
28-
const [isShowPassword, setIsShowPassword] = useState(false);
30+
const [showPsd, setShowPsd] = useState(false);
31+
const [showCode, setShowCode] = useState(false); // added state
32+
console.log('showCode', showCode);
33+
2934
const theme = useTheme<Theme>();
3035
const styles = createStyles({
3136
border: theme.colors.border || '#CCC',
@@ -57,43 +62,48 @@ const LoginPage: React.FC<LoginPageProps> = ({
5762
<Icon xml={logSvg(theme)} size={30} />
5863
<Text style={styles.title}>Login</Text>
5964
</View>
60-
<View style={[styles.inputContainer, inputContainerStyle]}>
65+
<View style={[styles.inputContainer, { paddingHorizontal: 15 }, inputContainerStyle]}>
6166
<TextInput
62-
placeholder={usernamePlaceholder}
63-
placeholderTextColor={theme.colors.icon}
67+
placeholder={usernamePlaceholder ? usernamePlaceholder : `请输入${showCode ? '手机号码' : '用户名'}`}
68+
placeholderTextColor={theme.colors.border}
6469
style={styles.input}
70+
keyboardType={showCode ? 'numeric' : 'default'}
6571
onChangeText={onChangeUsername}
6672
/>
6773
</View>
68-
{showPassword ? (
69-
<View style={[styles.inputContainers, inputContainerStyle]}>
74+
{!showCode ? (
75+
<View style={[styles.inputContainer, styles.inputC, { paddingHorizontal: 15 }, inputContainerStyle]}>
7076
<TextInput
7177
placeholder="请输入密码"
72-
placeholderTextColor={theme.colors.icon}
73-
secureTextEntry={!isShowPassword}
78+
placeholderTextColor={theme.colors.border}
79+
secureTextEntry={!showPsd}
7480
style={[styles.input, { width: '92%' }]}
7581
onChangeText={onChangePassword}
7682
/>
77-
<TouchableOpacity onPress={() => setIsShowPassword(!isShowPassword)}>
78-
<Icon xml={isShowPassword ? cEyes : oEyes} size={20} />
83+
<TouchableOpacity onPress={() => setShowPsd(!showPsd)}>
84+
<Icon xml={showPsd ? cEyes : oEyes} size={20} />
7985
</TouchableOpacity>
8086
</View>
8187
) : (
8288
<VerificationCode
8389
value={password}
8490
count={60}
8591
onChange={onChangePassword}
86-
outerStyle={[styles.inputContainer, inputContainerStyle]}
92+
outerStyle={[styles.inputContainer, styles.inputC, inputContainerStyle]}
8793
/>
8894
)}
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>
96-
</View>
95+
{customContent ? (
96+
customContent
97+
) : (
98+
<View style={styles.textSty1}>
99+
<TouchableOpacity onPress={onForgetPassword}>
100+
<Text style={styles.textSty}>忘记密码</Text>
101+
</TouchableOpacity>
102+
<TouchableOpacity onPress={() => setShowCode(!showCode)}>
103+
<Text style={styles.textSty}>{`${showCode ? '用户名' : '验证码'}登录`}</Text>
104+
</TouchableOpacity>
105+
</View>
106+
)}
97107
<TouchableOpacity style={[styles.button, buttonStyle]} onPress={handleLogin}>
98108
<Text style={[styles.buttonText, styles.buttonTextStyle]}>{buttonText}</Text>
99109
</TouchableOpacity>
@@ -126,30 +136,22 @@ function createStyles({ border, putCol }: CreStyle) {
126136
title: {
127137
fontSize: 24,
128138
fontWeight: 'bold',
129-
marginLeft: 20,
139+
marginLeft: 15,
130140
color: putCol,
131141
},
132142
inputContainer: {
133143
height: 40,
134-
marginBottom: 20,
135144
borderColor: border,
136145
borderWidth: 1,
137146
borderRadius: 5,
138147
justifyContent: 'center',
139-
paddingHorizontal: 15,
140148
flexDirection: 'row',
141149
alignItems: 'center',
142150
},
143-
inputContainers: {
144-
height: 40,
151+
inputC: {
152+
paddingHorizontal: 10,
153+
marginTop: 20,
145154
marginBottom: 5,
146-
borderColor: border,
147-
borderWidth: 1,
148-
borderRadius: 5,
149-
justifyContent: 'center',
150-
paddingHorizontal: 15,
151-
flexDirection: 'row',
152-
alignItems: 'center',
153155
},
154156
input: {
155157
flex: 1,

packages/core/src/VerificationCode/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const VerificationCode: FC<VerificationCodeProps> = ({
7878
border={null}
7979
containerStyle={[{ height: 40 }, outerStyle]}
8080
placeholder={placeholder}
81+
placeholderTextColor={theme.colors.border}
8182
value={value}
8283
onChangeText={(text) => onChange(text)}
8384
extraEnd={
@@ -86,7 +87,7 @@ const VerificationCode: FC<VerificationCodeProps> = ({
8687
disabled={disabled}
8788
onPress={handleClick}
8889
color={theme.colors.background || '#fff'}
89-
style={buttonStyle}
90+
style={[buttonStyle]}
9091
>
9192
<Text color={disabled ? 'disabled' : 'text'}>{disabled ? `${resendLabel}(${timer}s)` : label}</Text>
9293
</Button>

0 commit comments

Comments
 (0)