fix(ui): 完善界面交互与开发配置
This commit is contained in:
@@ -166,6 +166,16 @@ const LoginForm = () => {
|
||||
const [githubButtonText, setGithubButtonText] = useState('');
|
||||
const [githubButtonDisabled, setGithubButtonDisabled] = useState(false);
|
||||
const githubTimeoutRef = useRef(null);
|
||||
// 微信验证码弹窗表单:确定前先做前端必填校验,通过后再走原提交逻辑
|
||||
const wechatFormApi = useRef(null);
|
||||
const submitWeChatCodeWithValidation = async () => {
|
||||
try {
|
||||
await wechatFormApi.current?.validate();
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
await onSubmitWeChatVerificationCode();
|
||||
};
|
||||
|
||||
const logo = getLogo();
|
||||
const systemName = getSystemName();
|
||||
@@ -826,14 +836,10 @@ const LoginForm = () => {
|
||||
<Form.Input
|
||||
field='username'
|
||||
className='auth-login-required-field'
|
||||
rules={[{ required: true, message: t('请输入用户名或邮箱') }]}
|
||||
rules={[{ required: true, message: t('请输入用户名/邮箱') }]}
|
||||
required
|
||||
aria-required='true'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('用户名/邮箱')}
|
||||
</span>
|
||||
}
|
||||
label={t('用户名/邮箱')}
|
||||
placeholder={t('请输入用户名或邮箱')}
|
||||
name='username'
|
||||
size='default'
|
||||
@@ -849,11 +855,7 @@ const LoginForm = () => {
|
||||
rules={[{ required: true, message: t('请输入密码') }]}
|
||||
required
|
||||
aria-required='true'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('密码')}
|
||||
</span>
|
||||
}
|
||||
label={t('密码')}
|
||||
placeholder={t('请输入密码')}
|
||||
name='password'
|
||||
mode='password'
|
||||
@@ -864,7 +866,7 @@ const LoginForm = () => {
|
||||
/>
|
||||
|
||||
{(hasUserAgreement || hasPrivacyPolicy) && (
|
||||
<div className='flex items-center'>
|
||||
<div className='auth-login-agree-row flex items-center'>
|
||||
<Checkbox
|
||||
checked={agreedToTerms}
|
||||
onChange={(e) => setAgreedToTerms(e.target.checked)}
|
||||
@@ -987,7 +989,7 @@ const LoginForm = () => {
|
||||
}
|
||||
visible={showWeChatLoginModal}
|
||||
maskClosable={true}
|
||||
onOk={onSubmitWeChatVerificationCode}
|
||||
onOk={submitWeChatCodeWithValidation}
|
||||
onCancel={() => setShowWeChatLoginModal(false)}
|
||||
okText={t('登录')}
|
||||
centered={true}
|
||||
@@ -1048,11 +1050,12 @@ const LoginForm = () => {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Form>
|
||||
<Form getFormApi={(api) => (wechatFormApi.current = api)}>
|
||||
<Form.Input
|
||||
field='wechat_verification_code'
|
||||
placeholder={t('请输入验证码')}
|
||||
label={t('验证码')}
|
||||
rules={[{ required: true, message: t('请输入验证码') }]}
|
||||
value={inputs.wechat_verification_code}
|
||||
onChange={(value) =>
|
||||
handleChange('wechat_verification_code', value)
|
||||
|
||||
@@ -121,10 +121,20 @@ const PasswordResetForm = () => {
|
||||
subtitle={t('密码重置')}
|
||||
/>
|
||||
|
||||
<Form className='auth-login-form'>
|
||||
{/* 前端校验(必填 + 邮箱格式)通过后才调用原 handleSubmit */}
|
||||
<Form className='auth-login-form' onSubmit={() => handleSubmit()}>
|
||||
<Form.Input
|
||||
field='email'
|
||||
label={t('邮箱')}
|
||||
rules={[
|
||||
{ required: true, message: t('请输入邮箱') },
|
||||
{
|
||||
type: 'email',
|
||||
transform: (v) => v?.trim(),
|
||||
message: t('邮箱格式不正确'),
|
||||
},
|
||||
]}
|
||||
trigger='blur'
|
||||
placeholder={t('请输入您的邮箱地址')}
|
||||
name='email'
|
||||
value={email}
|
||||
@@ -138,7 +148,6 @@ const PasswordResetForm = () => {
|
||||
block
|
||||
className='auth-login-submit'
|
||||
htmlType='submit'
|
||||
onClick={handleSubmit}
|
||||
loading={loading}
|
||||
disabled={disableButton}
|
||||
>
|
||||
|
||||
@@ -144,6 +144,26 @@ const RegisterForm = () => {
|
||||
const [githubButtonDisabled, setGithubButtonDisabled] = useState(false);
|
||||
const [showWeChatOpenTipModal, setShowWeChatOpenTipModal] = useState(false);
|
||||
const githubTimeoutRef = useRef(null);
|
||||
// 注册表单 / 微信验证码弹窗的表单实例:用于在原逻辑执行前做前端校验
|
||||
const registerFormApi = useRef(null);
|
||||
const wechatFormApi = useRef(null);
|
||||
// 获取验证码前先校验邮箱必填与格式,通过后走原发送逻辑
|
||||
const sendVerificationCodeWithValidation = async () => {
|
||||
try {
|
||||
await registerFormApi.current?.validate(['email']);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
await sendVerificationCode();
|
||||
};
|
||||
const submitWeChatCodeWithValidation = async () => {
|
||||
try {
|
||||
await wechatFormApi.current?.validate();
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
await onSubmitWeChatVerificationCode();
|
||||
};
|
||||
|
||||
const logo = getLogo();
|
||||
const systemName = getSystemName();
|
||||
@@ -665,14 +685,16 @@ const RegisterForm = () => {
|
||||
logoWrapperClassName='mb-2'
|
||||
/>
|
||||
|
||||
<Form className='auth-login-form'>
|
||||
{/* 前端校验通过后才调用原 handleSubmit;其内协议 / 长度 / 一致性判断原样保留 */}
|
||||
<Form
|
||||
className='auth-login-form'
|
||||
getFormApi={(api) => (registerFormApi.current = api)}
|
||||
onSubmit={() => handleSubmit()}
|
||||
>
|
||||
<Form.Input
|
||||
field='username'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('用户名')}
|
||||
</span>
|
||||
}
|
||||
label={t('用户名')}
|
||||
rules={[{ required: true, message: t('请输入用户名') }]}
|
||||
placeholder={t('请输入用户名')}
|
||||
name='username'
|
||||
autoComplete='username'
|
||||
@@ -680,14 +702,15 @@ const RegisterForm = () => {
|
||||
prefix={<IconUser size='small' />}
|
||||
/>
|
||||
|
||||
{/* 密码输入框 */}
|
||||
{/* 密码输入框:长度 8-20 与占位提示、后端约束一致 */}
|
||||
<Form.Input
|
||||
field='password'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('密码')}
|
||||
</span>
|
||||
}
|
||||
label={t('密码')}
|
||||
rules={[
|
||||
{ required: true, message: t('请输入密码') },
|
||||
{ min: 8, max: 20, message: t('密码长度需为 8-20 位') },
|
||||
]}
|
||||
trigger='blur'
|
||||
placeholder={t('输入密码,最短 8 位,最长 20 位')}
|
||||
name='password'
|
||||
mode='password'
|
||||
@@ -699,11 +722,14 @@ const RegisterForm = () => {
|
||||
{/* 确认密码输入框 */}
|
||||
<Form.Input
|
||||
field='password2'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('确认密码')}
|
||||
</span>
|
||||
}
|
||||
label={t('确认密码')}
|
||||
required
|
||||
validate={(value, values) => {
|
||||
if (!value) return t('请输入确认密码');
|
||||
if (value !== values.password) return t('两次输入的密码不一致');
|
||||
return '';
|
||||
}}
|
||||
trigger='blur'
|
||||
placeholder={t('确认密码')}
|
||||
name='password2'
|
||||
mode='password'
|
||||
@@ -716,11 +742,16 @@ const RegisterForm = () => {
|
||||
<>
|
||||
<Form.Input
|
||||
field='email'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('邮箱')}
|
||||
</span>
|
||||
}
|
||||
label={t('邮箱')}
|
||||
rules={[
|
||||
{ required: true, message: t('请输入邮箱') },
|
||||
{
|
||||
type: 'email',
|
||||
transform: (v) => v?.trim(),
|
||||
message: t('邮箱格式不正确'),
|
||||
},
|
||||
]}
|
||||
trigger='blur'
|
||||
placeholder={t('输入邮箱地址')}
|
||||
name='email'
|
||||
type='email'
|
||||
@@ -730,7 +761,7 @@ const RegisterForm = () => {
|
||||
suffix={
|
||||
<Button
|
||||
size='small'
|
||||
onClick={sendVerificationCode}
|
||||
onClick={sendVerificationCodeWithValidation}
|
||||
loading={verificationCodeLoading}
|
||||
disabled={disableButton || verificationCodeLoading}
|
||||
className='!rounded-lg'
|
||||
@@ -743,11 +774,8 @@ const RegisterForm = () => {
|
||||
/>
|
||||
<Form.Input
|
||||
field='verification_code'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('验证码')}
|
||||
</span>
|
||||
}
|
||||
label={t('验证码')}
|
||||
rules={[{ required: true, message: t('请输入验证码') }]}
|
||||
placeholder={t('输入验证码')}
|
||||
name='verification_code'
|
||||
onChange={(value) => handleChange('verification_code', value)}
|
||||
@@ -757,7 +785,7 @@ const RegisterForm = () => {
|
||||
)}
|
||||
|
||||
{(hasUserAgreement || hasPrivacyPolicy) && (
|
||||
<div className='flex items-center'>
|
||||
<div className='auth-login-agree-row flex items-center'>
|
||||
<Checkbox
|
||||
checked={agreedToTerms}
|
||||
onChange={(e) => setAgreedToTerms(e.target.checked)}
|
||||
@@ -793,13 +821,12 @@ const RegisterForm = () => {
|
||||
)}
|
||||
|
||||
<div className='auth-login-actions'>
|
||||
{/* 注册按钮:与登录按钮同款实心主按钮(36px),保留原提交触发与禁用条件 */}
|
||||
{/* 注册按钮:提交经表单校验后调用原 handleSubmit,禁用条件不变 */}
|
||||
<Button
|
||||
theme='solid'
|
||||
htmlType='submit'
|
||||
block
|
||||
className='auth-login-submit'
|
||||
onClick={handleSubmit}
|
||||
loading={registerLoading}
|
||||
disabled={
|
||||
registerLoading ||
|
||||
@@ -870,7 +897,7 @@ const RegisterForm = () => {
|
||||
}
|
||||
visible={showWeChatLoginModal}
|
||||
maskClosable={true}
|
||||
onOk={onSubmitWeChatVerificationCode}
|
||||
onOk={submitWeChatCodeWithValidation}
|
||||
onCancel={() => setShowWeChatLoginModal(false)}
|
||||
okText={t('登录')}
|
||||
centered={true}
|
||||
@@ -931,11 +958,12 @@ const RegisterForm = () => {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Form>
|
||||
<Form getFormApi={(api) => (wechatFormApi.current = api)}>
|
||||
<Form.Input
|
||||
field='wechat_verification_code'
|
||||
placeholder={t('请输入验证码')}
|
||||
label={t('验证码')}
|
||||
rules={[{ required: true, message: t('请输入验证码') }]}
|
||||
value={inputs.wechat_verification_code}
|
||||
onChange={(value) =>
|
||||
handleChange('wechat_verification_code', value)
|
||||
|
||||
@@ -71,6 +71,21 @@ const TwoFAVerification = ({ onSuccess, onBack, isModal = false }) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 前端校验:与 handleSubmit 内原有判断一致,改为在输入框下方就地提示
|
||||
const codeRules = [
|
||||
{
|
||||
required: true,
|
||||
message: useBackupCode ? t('请输入备用码') : t('请输入验证码'),
|
||||
},
|
||||
{
|
||||
validator: (_, value) => {
|
||||
if (!value) return true;
|
||||
if (useBackupCode) return value.length === 8 || t('备用码必须是8位');
|
||||
return /^\d{6}$/.test(value) || t('验证码必须是6位数字');
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
if (isModal) {
|
||||
return (
|
||||
<div className='space-y-4'>
|
||||
@@ -88,6 +103,8 @@ const TwoFAVerification = ({ onSuccess, onBack, isModal = false }) => {
|
||||
value={verificationCode}
|
||||
onChange={setVerificationCode}
|
||||
onKeyPress={handleKeyPress}
|
||||
rules={codeRules}
|
||||
trigger='blur'
|
||||
style={{ marginBottom: 16 }}
|
||||
autoFocus
|
||||
/>
|
||||
@@ -177,6 +194,8 @@ const TwoFAVerification = ({ onSuccess, onBack, isModal = false }) => {
|
||||
value={verificationCode}
|
||||
onChange={setVerificationCode}
|
||||
onKeyPress={handleKeyPress}
|
||||
rules={codeRules}
|
||||
trigger='blur'
|
||||
style={{ marginBottom: 16 }}
|
||||
autoFocus
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user