feat: add new interfaces, services, and utilities for API integration

refactor: reorganize type definitions and improve type safety

build: add lodash and @types/lodash as dependencies

chore: update tsconfig and vite config for path aliases

style: improve code organization and add documentation comments

fix: correct type usage in LanguageSwitcher component

perf: implement snackbar provider for global notifications

test: add new test interfaces and utility functions

ci: update pnpm-lock.yaml with new dependencies
This commit is contained in:
2025-10-10 15:09:04 +08:00
parent 8cf7a4e5d5
commit a1282de74f
45 changed files with 5088 additions and 274 deletions

View File

@@ -13,9 +13,11 @@ import {
AppBar,
Toolbar,
Card,
CardContent
CardContent,
Alert
} from '@mui/material';
import LanguageSwitcher from '../components/LanguageSwitcher';
import userService from '../services/user_service';
const Login = () => {
const { t } = useTranslation();
@@ -25,24 +27,40 @@ const Login = () => {
const [isSubmitting, setIsSubmitting] = useState(false);
const [emailError, setEmailError] = useState(false);
const [passwordError, setPasswordError] = useState(false);
const [loginError, setLoginError] = useState('');
const navigate = useNavigate();
console.log(t, t('en'), t('login'));
const handleSubmit = (e: React.FormEvent) => {
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
const hasEmail = !!email.trim();
const hasPassword = !!password.trim();
setEmailError(!hasEmail);
setPasswordError(!hasPassword);
setLoginError('');
if (!hasEmail || !hasPassword) return;
setIsSubmitting(true);
// 模拟登录过程
setTimeout(() => {
navigate('/');
}, 800);
try {
const response = await userService.login({ email, password });
// if (response.code === 0) {
// // 登录成功,跳转到主页
// navigate('/');
// } else {
// // 登录失败,显示错误信息
// setLoginError(response.message || t('login.loginFailed'));
// }
} catch (error: any) {
// 处理网络错误或其他异常
setLoginError(error.message || t('login.networkError'));
} finally {
setIsSubmitting(false);
}
};
return (
@@ -84,6 +102,12 @@ const Login = () => {
</Typography>
<Box component="form" onSubmit={handleSubmit} noValidate>
{loginError && (
<Alert severity="error" sx={{ mb: 2 }}>
{loginError}
</Alert>
)}
<TextField
fullWidth
id="email"