feat: 登录页优化

This commit is contained in:
jinyaqiu 2025-08-01 16:05:27 +08:00
parent ef70e2f83a
commit e6a8faa610
3 changed files with 376 additions and 243 deletions

View File

@ -81,7 +81,7 @@ const LoginScreen = () => {
}} }}
> >
{ {
showPassword (showPassword || showSecondPassword)
? ?
<LoginIP2 /> <LoginIP2 />
: :

View File

@ -2,7 +2,7 @@ import { fetchApi } from "@/lib/server-api-util";
import { User } from "@/types/user"; import { User } from "@/types/user";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { ActivityIndicator, TextInput, TouchableOpacity, View } from "react-native"; import { ActivityIndicator, StyleSheet, TextInput, TouchableOpacity, View } from "react-native";
import { ThemedText } from "../ThemedText"; import { ThemedText } from "../ThemedText";
interface LoginProps { interface LoginProps {
@ -15,12 +15,10 @@ interface LoginProps {
const ForgetPwd = ({ setIsSignUp, updateUrlParam, setError }: LoginProps) => { const ForgetPwd = ({ setIsSignUp, updateUrlParam, setError }: LoginProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const [loading, setLocading] = useState(false); const [loading, setLocading] = useState(false);
// 发送邮箱后把按钮变为disabled
const [isDisabled, setIsDisabled] = useState(false); const [isDisabled, setIsDisabled] = useState(false);
const [email, setEmail] = useState(''); const [email, setEmail] = useState('');
const [countdown, setCountdown] = useState(0); const [countdown, setCountdown] = useState(0);
// 倒计时效果
useEffect(() => { useEffect(() => {
if (countdown > 0) { if (countdown > 0) {
const timer = setTimeout(() => setCountdown(countdown - 1), 1000); const timer = setTimeout(() => setCountdown(countdown - 1), 1000);
@ -30,7 +28,6 @@ const ForgetPwd = ({ setIsSignUp, updateUrlParam, setError }: LoginProps) => {
} }
}, [countdown, isDisabled]); }, [countdown, isDisabled]);
// 发送邮件
const handleSubmit = () => { const handleSubmit = () => {
if (!email) { if (!email) {
setError(t('auth.forgetPwd.emailPlaceholder', { ns: 'login' })); setError(t('auth.forgetPwd.emailPlaceholder', { ns: 'login' }));
@ -41,7 +38,7 @@ const ForgetPwd = ({ setIsSignUp, updateUrlParam, setError }: LoginProps) => {
const body = { const body = {
email: email, email: email,
} }
// 调接口确定邮箱是否正确,是否有该用户邮箱权限
fetchApi<User>('/iam/reset-password-session', { fetchApi<User>('/iam/reset-password-session', {
method: 'POST', method: 'POST',
body: JSON.stringify(body), body: JSON.stringify(body),
@ -50,19 +47,17 @@ const ForgetPwd = ({ setIsSignUp, updateUrlParam, setError }: LoginProps) => {
} }
}) })
.then((_) => { .then((_) => {
// console.log("Password reset email sent successfully");
setIsDisabled(true); setIsDisabled(true);
setCountdown(60); // 开始60秒倒计时 setCountdown(60);
}) })
.catch((error) => { .catch((error) => {
// console.error('Failed to send reset email:', error);
setError(t('auth.forgetPwd.sendEmailError', { ns: 'login' })); setError(t('auth.forgetPwd.sendEmailError', { ns: 'login' }));
}) })
.finally(() => { .finally(() => {
setLocading(false); setLocading(false);
}); });
}; };
// 返回登陆
const handleBackToLogin = () => { const handleBackToLogin = () => {
if (setIsSignUp) { if (setIsSignUp) {
setIsSignUp('login'); setIsSignUp('login');
@ -72,50 +67,95 @@ const ForgetPwd = ({ setIsSignUp, updateUrlParam, setError }: LoginProps) => {
} }
} }
return <View> return (
{/* 邮箱输入框 */} <View style={styles.container}>
<View className="mb-5"> <View style={styles.inputContainer}>
<ThemedText className="text-base !text-textPrimary mb-2 ml-2"> <ThemedText style={styles.inputLabel}>
{t('auth.forgetPwd.title', { ns: 'login' })} {t('auth.forgetPwd.title', { ns: 'login' })}
</ThemedText>
<TextInput
className="border border-gray-300 rounded-2xl p-3 text-base bg-inputBackground"
placeholder={t('auth.forgetPwd.emailPlaceholder', { ns: 'login' })}
placeholderTextColor="#ccc"
value={email}
onChangeText={setEmail}
keyboardType="email-address"
autoCapitalize="none"
/>
</View>
{/* 发送重置密码邮件 */}
<TouchableOpacity
className={`w-full bg-[#E2793F] rounded-full p-4 items-center ${isDisabled ? 'opacity-50' : ''}`}
onPress={handleSubmit}
disabled={isDisabled || loading}
>
{loading ? (
<ActivityIndicator color="#fff" />
) : (
<ThemedText className="!text-white font-semibold">
{isDisabled
? `${t("auth.forgetPwd.sendEmailBtnDisabled", { ns: "login" })} (${countdown}s)`
: t("auth.forgetPwd.sendEmailBtn", { ns: "login" })}
</ThemedText> </ThemedText>
)} <TextInput
</TouchableOpacity> style={styles.textInput}
{/* 返回登陆 */} placeholder={t('auth.forgetPwd.emailPlaceholder', { ns: 'login' })}
<TouchableOpacity placeholderTextColor="#ccc"
className="self-center mt-6" value={email}
onPress={handleBackToLogin} onChangeText={setEmail}
> keyboardType="email-address"
<ThemedText className="!text-textPrimary text-sm"> autoCapitalize="none"
{t('auth.forgetPwd.goback', { ns: 'login' })} />
</ThemedText> </View>
</TouchableOpacity>
</View> <TouchableOpacity
style={[
styles.submitButton,
(isDisabled || loading) && styles.disabledButton
]}
onPress={handleSubmit}
disabled={isDisabled || loading}
>
{loading ? (
<ActivityIndicator color="#fff" />
) : (
<ThemedText style={styles.buttonText}>
{isDisabled
? `${t("auth.forgetPwd.sendEmailBtnDisabled", { ns: "login" })} (${countdown}s)`
: t("auth.forgetPwd.sendEmailBtn", { ns: "login" })}
</ThemedText>
)}
</TouchableOpacity>
<TouchableOpacity
style={styles.backButton}
onPress={handleBackToLogin}
>
<ThemedText style={styles.backButtonText}>
{t('auth.forgetPwd.goback', { ns: 'login' })}
</ThemedText>
</TouchableOpacity>
</View>
);
} }
const styles = StyleSheet.create({
container: {
width: '100%',
},
inputContainer: {
marginBottom: 20,
},
inputLabel: {
fontSize: 16,
color: '#1F2937',
marginBottom: 8,
marginLeft: 8,
},
textInput: {
borderRadius: 12,
padding: 12,
fontSize: 16,
backgroundColor: '#FFF8DE',
},
submitButton: {
width: '100%',
backgroundColor: '#E2793F',
borderRadius: 28,
padding: 16,
alignItems: 'center',
},
disabledButton: {
opacity: 0.5,
},
buttonText: {
color: '#FFFFFF',
fontWeight: '600',
},
backButton: {
alignSelf: 'center',
marginTop: 24,
},
backButtonText: {
color: '#1F2937',
fontSize: 14,
},
});
export default ForgetPwd export default ForgetPwd;

View File

@ -2,7 +2,7 @@ import { Ionicons } from "@expo/vector-icons";
import { useLocalSearchParams, useRouter } from "expo-router"; import { useLocalSearchParams, useRouter } from "expo-router";
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { ActivityIndicator, TextInput, TouchableOpacity, View } from 'react-native'; import { ActivityIndicator, StyleSheet, TextInput, TouchableOpacity, View } from 'react-native';
import { useAuth } from "../../contexts/auth-context"; import { useAuth } from "../../contexts/auth-context";
import { fetchApi } from "../../lib/server-api-util"; import { fetchApi } from "../../lib/server-api-util";
import { User } from "../../types/user"; import { User } from "../../types/user";
@ -143,206 +143,299 @@ const SignUp = ({ updateUrlParam, setError, setShowPassword, showPassword, setSh
setShowSecondPassword(false) setShowSecondPassword(false)
}, []) }, [])
return <View className="w-full"> return (
{/* 邮箱输入 */} <View style={styles.container}>
<View className="mb-4"> {/* 邮箱输入 */}
<ThemedText className="text-base !text-textPrimary mb-2 ml-2"> <View style={styles.inputContainer}>
{t('auth.login.email', { ns: 'login' })} <ThemedText style={styles.inputLabel}>
</ThemedText> {t('auth.login.email', { ns: 'login' })}
<View className="border border-gray-300 rounded-2xl bg-inputBackground overflow-hidden">
<TextInput
className="p-3 text-base flex-1"
placeholder={t('auth.login.accountPlaceholder', { ns: 'login' })}
placeholderTextColor="#ccc"
value={email}
onChangeText={(value) => {
setEmail(value)
setError('123')
}}
keyboardType="email-address"
autoCapitalize="none"
/>
</View>
</View>
{/* 密码输入 */}
<View className="mb-4">
<ThemedText className="text-base !text-textPrimary mb-2 ml-2">
{t('auth.login.password', { ns: 'login' })}
</ThemedText>
<View className="border border-gray-300 rounded-2xl bg-inputBackground overflow-hidden flex-row items-center">
<TextInput
className="p-3 text-base flex-1"
placeholder={t('auth.login.passwordPlaceholder', { ns: 'login' })}
placeholderTextColor="#ccc"
value={password}
onChangeText={(value) => {
handlePasswordChange(value)
setError('123')
}}
secureTextEntry={!showPassword}
/>
<TouchableOpacity
onPress={() => setShowPassword(!showPassword)}
className="px-3 py-2"
>
<Ionicons
name={showPassword ? 'eye' : 'eye-off'}
size={20}
color="#666"
/>
</TouchableOpacity>
</View>
</View>
{/* 确认密码 */}
<View className="mb-6">
<ThemedText className="text-base !text-textPrimary mb-2 ml-2">
{t('auth.signup.confirmPassword', { ns: 'login' })}
</ThemedText>
<View className="border border-gray-300 rounded-2xl bg-inputBackground overflow-hidden flex-row items-center">
<TextInput
className="p-3 text-base flex-1"
placeholder={t('auth.signup.confirmPasswordPlaceholder', { ns: 'login' })}
placeholderTextColor="#ccc"
value={confirmPassword}
onChangeText={(value) => {
handleConfirmPasswordChange(value)
setError('123')
}}
secureTextEntry={!showSecondPassword}
/>
<TouchableOpacity
onPress={() => setShowSecondPassword(!showSecondPassword)}
className="px-3 py-2"
>
<Ionicons
name={showSecondPassword ? 'eye' : 'eye-off'}
size={20}
color="#666"
/>
</TouchableOpacity>
</View>
</View>
{/* 注册按钮 */}
<TouchableOpacity
className={`w-full bg-[#E2793F] rounded-full p-4 items-center ${loading ? 'opacity-70' : ''}`}
onPress={handleSubmit}
disabled={loading}
>
{loading ? (
<ActivityIndicator color="#fff" />
) : (
<ThemedText className="!text-white font-semibold">
{t("auth.signup.signupButton", { ns: 'login' })}
</ThemedText> </ThemedText>
)} <View style={styles.inputWrapper}>
</TouchableOpacity> <TextInput
<View style={{ flexDirection: 'row', alignItems: 'center', marginVertical: 10 }}> style={styles.textInput}
<TouchableOpacity placeholder={t('auth.login.accountPlaceholder', { ns: 'login' })}
onPress={() => { placeholderTextColor="#ccc"
const newValue = !checked; value={email}
setChecked(newValue); onChangeText={(value) => {
if (!newValue) { setEmail(value)
setError(t('auth.signup.checkedRequired', { ns: 'login' })); setError('123')
return }}
} else { keyboardType="email-address"
setError("123") autoCapitalize="none"
} />
</View>
</View>
}} {/* 密码输入 */}
style={{ <View style={styles.inputContainer}>
width: 20, <ThemedText style={styles.inputLabel}>
height: 20, {t('auth.login.password', { ns: 'login' })}
borderRadius: 10, </ThemedText>
borderWidth: 2, <View style={styles.passwordInputContainer}>
borderColor: checked ? '#E2793F' : '#ccc', <TextInput
backgroundColor: checked ? '#E2793F' : 'transparent', style={[styles.textInput, { flex: 1 }]}
justifyContent: 'center', placeholder={t('auth.login.passwordPlaceholder', { ns: 'login' })}
alignItems: 'center', placeholderTextColor="#ccc"
marginRight: 8, value={password}
}} onChangeText={(value) => {
handlePasswordChange(value)
setError('123')
}}
secureTextEntry={!showPassword}
/>
<TouchableOpacity
onPress={() => setShowPassword(!showPassword)}
style={styles.eyeIcon}
>
<Ionicons
name={showPassword ? 'eye' : 'eye-off'}
size={20}
color="#666"
/>
</TouchableOpacity>
</View>
</View>
{/* 确认密码 */}
<View style={[styles.inputContainer, { marginBottom: 24 }]}>
<ThemedText style={styles.inputLabel}>
{t('auth.signup.confirmPassword', { ns: 'login' })}
</ThemedText>
<View style={styles.passwordInputContainer}>
<TextInput
style={[styles.textInput, { flex: 1 }]}
placeholder={t('auth.signup.confirmPasswordPlaceholder', { ns: 'login' })}
placeholderTextColor="#ccc"
value={confirmPassword}
onChangeText={(value) => {
handleConfirmPasswordChange(value)
setError('123')
}}
secureTextEntry={!showSecondPassword}
/>
<TouchableOpacity
onPress={() => setShowSecondPassword(!showSecondPassword)}
style={styles.eyeIcon}
>
<Ionicons
name={showSecondPassword ? 'eye' : 'eye-off'}
size={20}
color="#666"
/>
</TouchableOpacity>
</View>
</View>
{/* 注册按钮 */}
<TouchableOpacity
style={[styles.signupButton, loading && { opacity: 0.7 }]}
onPress={handleSubmit}
disabled={loading}
> >
{checked && ( {loading ? (
<Ionicons name="checkmark" size={14} color="white" /> <ActivityIndicator color="#fff" />
) : (
<ThemedText style={styles.signupButtonText}>
{t("auth.signup.signupButton", { ns: 'login' })}
</ThemedText>
)} )}
</TouchableOpacity> </TouchableOpacity>
<View style={{ flexDirection: 'row', flexWrap: 'wrap', flex: 1 }}> <View style={styles.termsContainer}>
<ThemedText className="text-sm !text-textPrimary"> <TouchableOpacity
{t("auth.telLogin.agree", { ns: 'login' })} onPress={() => {
</ThemedText> const newValue = !checked;
<TouchableOpacity onPress={() => { setChecked(newValue);
setModalType('terms'); if (!newValue) {
setPrivacyModalVisible(true); setError(t('auth.signup.checkedRequired', { ns: 'login' }));
}}> return
<ThemedText className="text-sm !text-[#E2793F]"> } else {
{t("auth.telLogin.terms", { ns: 'login' })} setError("123")
</ThemedText> }
}}
style={[
styles.checkbox,
checked && styles.checkboxChecked
]}
>
{checked && (
<Ionicons name="checkmark" size={14} color="white" />
)}
</TouchableOpacity> </TouchableOpacity>
<ThemedText className="text-sm !text-textPrimary"> <View style={styles.termsTextContainer}>
{t("auth.telLogin.and", { ns: 'login' })} <ThemedText style={styles.termsText}>
</ThemedText> {t("auth.telLogin.agree", { ns: 'login' })}
<TouchableOpacity onPress={() => {
setModalType('privacy');
setPrivacyModalVisible(true);
}}>
<ThemedText className="text-sm !text-[#E2793F]">
{t("auth.telLogin.privacyPolicy", { ns: 'login' })}
</ThemedText> </ThemedText>
</TouchableOpacity> <TouchableOpacity onPress={() => {
<ThemedText className="text-sm !text-textPrimary"> setModalType('terms');
{t("auth.telLogin.and", { ns: 'login' })} setPrivacyModalVisible(true);
</ThemedText> }}>
<TouchableOpacity onPress={() => { <ThemedText style={styles.termsLink}>
setModalType('user'); {t("auth.telLogin.terms", { ns: 'login' })}
setPrivacyModalVisible(true); </ThemedText>
}}> </TouchableOpacity>
<ThemedText className="text-sm !text-[#E2793F]"> <ThemedText style={styles.termsText}>
{t("auth.telLogin.userAgreement", { ns: 'login' })} {t("auth.telLogin.and", { ns: 'login' })}
</ThemedText> </ThemedText>
</TouchableOpacity> <TouchableOpacity onPress={() => {
<ThemedText className="text-sm !text-textPrimary"> setModalType('privacy');
{t("auth.telLogin.and", { ns: 'login' })} setPrivacyModalVisible(true);
</ThemedText> }}>
<TouchableOpacity onPress={() => { <ThemedText style={styles.termsLink}>
setModalType('ai'); {t("auth.telLogin.privacyPolicy", { ns: 'login' })}
setPrivacyModalVisible(true); </ThemedText>
}}> </TouchableOpacity>
<ThemedText className="text-sm !text-[#E2793F]"> <ThemedText style={styles.termsText}>
{t("auth.telLogin.aiAgreement", { ns: 'login' })} {t("auth.telLogin.and", { ns: 'login' })}
</ThemedText> </ThemedText>
</TouchableOpacity> <TouchableOpacity onPress={() => {
<ThemedText className="text-sm !text-textPrimary"> setModalType('user');
{t("auth.telLogin.agreement", { ns: 'login' })} setPrivacyModalVisible(true);
</ThemedText> }}>
<ThemedText className="text-sm !text-[#E2793F]"> <ThemedText style={styles.termsLink}>
{t("common.name")} {t("auth.telLogin.userAgreement", { ns: 'login' })}
</ThemedText> </ThemedText>
<ThemedText className="text-sm !text-textPrimary"> </TouchableOpacity>
{t("auth.telLogin.getPhone", { ns: 'login' })} <ThemedText style={styles.termsText}>
</ThemedText> {t("auth.telLogin.and", { ns: 'login' })}
</ThemedText>
<TouchableOpacity onPress={() => {
setModalType('ai');
setPrivacyModalVisible(true);
}}>
<ThemedText style={styles.termsLink}>
{t("auth.telLogin.aiAgreement", { ns: 'login' })}
</ThemedText>
</TouchableOpacity>
<ThemedText style={styles.termsText}>
{t("auth.telLogin.agreement", { ns: 'login' })}
</ThemedText>
<ThemedText style={styles.termsLink}>
{t("common.name")}
</ThemedText>
<ThemedText style={styles.termsText}>
{t("auth.telLogin.getPhone", { ns: 'login' })}
</ThemedText>
</View>
</View> </View>
</View> {/* 已有账号 */}
{/* 已有账号 */} <View style={styles.loginContainer}>
<View className="flex-row justify-center mt-6"> <ThemedText style={styles.loginText}>
<ThemedText className="text-sm !text-textPrimary"> {t("auth.signup.haveAccount", { ns: 'login' })}
{t("auth.signup.haveAccount", { ns: 'login' })}
</ThemedText>
<TouchableOpacity
onPress={() => {
updateUrlParam("status", "login");
}}
>
<ThemedText className="!text-[#E2793F] text-sm font-semibold ml-1">
{t("auth.signup.login", { ns: 'login' })}
</ThemedText> </ThemedText>
</TouchableOpacity> <TouchableOpacity
onPress={() => {
updateUrlParam("status", "login");
}}
>
<ThemedText style={styles.loginLink}>
{t("auth.signup.login", { ns: 'login' })}
</ThemedText>
</TouchableOpacity>
</View>
{/* 协议弹窗 */}
<PrivacyModal modalVisible={privacyModalVisible} setModalVisible={setPrivacyModalVisible} type={modalType} />
</View> </View>
);
};
{/* 协议弹窗 */} const styles = StyleSheet.create({
<PrivacyModal modalVisible={privacyModalVisible} setModalVisible={setPrivacyModalVisible} type={modalType} /> container: {
</View> width: '100%',
} },
inputContainer: {
marginBottom: 16,
},
inputWrapper: {
borderRadius: 12,
backgroundColor: '#FFF8DE',
overflow: 'hidden',
},
inputLabel: {
fontSize: 16,
color: '#1F2937',
marginBottom: 8,
marginLeft: 8,
},
textInput: {
padding: 12,
fontSize: 16,
color: '#1F2937',
},
passwordInputContainer: {
flexDirection: 'row',
alignItems: 'center',
borderRadius: 12,
backgroundColor: '#FFF8DE',
overflow: 'hidden',
},
eyeIcon: {
paddingHorizontal: 12,
paddingVertical: 8,
},
signupButton: {
width: '100%',
backgroundColor: '#E2793F',
borderRadius: 28,
padding: 16,
alignItems: 'center',
marginBottom: 16,
},
signupButtonText: {
color: '#FFFFFF',
fontWeight: '600',
},
termsContainer: {
flexDirection: 'row',
alignItems: 'flex-start',
marginVertical: 10,
},
checkbox: {
width: 20,
height: 20,
borderRadius: 10,
borderWidth: 2,
borderColor: '#E5E7EB',
justifyContent: 'center',
alignItems: 'center',
marginRight: 8,
marginTop: 2,
},
checkboxChecked: {
backgroundColor: '#E2793F',
borderColor: '#E2793F',
},
termsTextContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
flex: 1,
},
termsText: {
fontSize: 14,
color: '#1F2937',
lineHeight: 20,
},
termsLink: {
fontSize: 14,
color: '#E2793F',
lineHeight: 20,
},
loginContainer: {
flexDirection: 'row',
justifyContent: 'center',
marginTop: 24,
},
loginText: {
fontSize: 14,
color: '#1F2937',
},
loginLink: {
color: '#E2793F',
fontSize: 14,
fontWeight: '600',
marginLeft: 4,
},
});
export default SignUp export default SignUp;