docs:重命名文件、变量名称
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// ============================================================
|
||||
// Test2 — 账户信息展示
|
||||
// AccountInfo — 账户信息展示
|
||||
// 数据来源:AuthAPI.getUserInfo() → GET /api/v1/auth/me
|
||||
// ============================================================
|
||||
|
||||
@@ -39,7 +39,7 @@ function formatDate(date: Date | string | undefined): string {
|
||||
return d.toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' });
|
||||
}
|
||||
|
||||
export function Test2() {
|
||||
export function AccountInfo() {
|
||||
const { token } = antTheme.useToken();
|
||||
const [userInfo, setUserInfo] = useState<UserInfoBody | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { useState, useCallback } from 'react';
|
||||
import { Input, Button, Checkbox, Typography } from 'antd';
|
||||
import { UserOutlined, LockOutlined } from '@ant-design/icons';
|
||||
import { UserOutlined, LockOutlined, EyeTwoTone, EyeInvisibleOutlined } from '@ant-design/icons';
|
||||
|
||||
import { loginFields } from '../config/login-fields';
|
||||
import { validateForm } from '../config/validators';
|
||||
@@ -40,7 +40,7 @@ export function LoginForm({
|
||||
const [password, setPassword] = useState(initialPassword || '');
|
||||
const [remember, setRemember] = useState(initialRemember);
|
||||
const [autoLogin, setAutoLogin] = useState(initialAutoLogin);
|
||||
const [agreed, setAgreed] = useState(false);
|
||||
const [agreed, setAgreed] = useState(true);
|
||||
const [errors, setErrors] = useState<Record<string, string[]>>({});
|
||||
|
||||
// 协议弹窗
|
||||
@@ -103,6 +103,8 @@ export function LoginForm({
|
||||
setPassword(e.target.value);
|
||||
clearError('password');
|
||||
}}
|
||||
iconRender={(visible) => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
|
||||
onPressEnter={handleSubmit}
|
||||
status={errors.password ? 'error' : undefined}
|
||||
allowClear
|
||||
/>
|
||||
@@ -162,6 +164,11 @@ export function LoginForm({
|
||||
setAgreed(e.target.checked);
|
||||
clearError('_agreement');
|
||||
}}
|
||||
onKeyDown={(event)=>{
|
||||
if (event.key === 'Enter' || event.keyCode === 13) {
|
||||
setAgreed(!agreed);
|
||||
}
|
||||
}}
|
||||
className="text-xs"
|
||||
>
|
||||
已阅读并同意
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// RegisterForm — 注册表单(仅个人版)
|
||||
// ============================================================
|
||||
|
||||
import { useState, useCallback, useRef } from 'react';
|
||||
import React, { useState, useCallback, useRef } from 'react';
|
||||
import { Input, Button, Checkbox, Typography } from 'antd';
|
||||
|
||||
import { LegalTextModal } from '@/components/ui/LegalTextModal';
|
||||
@@ -87,17 +87,16 @@ export function RegisterForm({ submitting = false, onSubmit, onSendSms }: Regist
|
||||
onSendSms?.(phone);
|
||||
}, [values.phone, onSendSms]);
|
||||
|
||||
// 跨字段校验
|
||||
const crossValidators = {
|
||||
confirmPassword: (val: string) => {
|
||||
if (!val) return '请再次输入密码';
|
||||
if (val !== values.password) return '两次密码不一致';
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
// 提交
|
||||
const handleSubmit = useCallback(() => {
|
||||
// 跨字段校验(内联避免每次渲染创建新引用致使用 useCallback 失效)
|
||||
const crossValidators = {
|
||||
confirmPassword: (val: string) => {
|
||||
if (!val) return '请再次输入密码';
|
||||
if (val !== values.password) return '两次密码不一致';
|
||||
return null;
|
||||
},
|
||||
};
|
||||
const fieldErrors = validateForm(values, registerFields, crossValidators);
|
||||
if (Object.keys(fieldErrors).length > 0) {
|
||||
setErrors(fieldErrors);
|
||||
@@ -208,6 +207,11 @@ export function RegisterForm({ submitting = false, onSubmit, onSendSms }: Regist
|
||||
return n;
|
||||
});
|
||||
}}
|
||||
onKeyDown={(e)=>{
|
||||
if(e.key==="Enter" || e.keyCode == 13) {
|
||||
setAgreed(!agreed);
|
||||
}
|
||||
}}
|
||||
className="text-xs"
|
||||
>
|
||||
已阅读并同意
|
||||
|
||||
Reference in New Issue
Block a user