diff --git a/web/package.json b/web/package.json index 828ef789..25436cf6 100644 --- a/web/package.json +++ b/web/package.json @@ -23,7 +23,8 @@ "react-router": "^5.2.0", "react-router-dom": "^5.2.0", "socket.io-client": "^4.1.2", - "tailwindcss": "^2.2.4" + "tailwindcss": "^2.2.4", + "yup": "^0.32.9" }, "devDependencies": { "@types/mini-css-extract-plugin": "^1.4.3", diff --git a/web/src/routes/Entry/LoginView.tsx b/web/src/routes/Entry/LoginView.tsx index 93379588..ffcae882 100644 --- a/web/src/routes/Entry/LoginView.tsx +++ b/web/src/routes/Entry/LoginView.tsx @@ -3,6 +3,7 @@ import { Divider } from 'antd'; import { useAsyncFn } from 'pawchat-shared'; import React, { useState } from 'react'; import { Spinner } from '../../components/Spinner'; +import { string } from 'yup'; /** * 第三方登录 @@ -25,17 +26,28 @@ OAuthLoginView.displayName = 'OAuthLoginView'; * 登录视图 */ export const LoginView: React.FC = React.memo(() => { - const [username, setUsername] = useState(''); + const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); - const [{ value, loading }, handleLogin] = useAsyncFn(async () => { + const [{ loading, error }, handleLogin] = useAsyncFn(async () => { + console.log({ email, password }); + + await string() + .email('邮箱格式不正确') + .required('邮箱不能为空') + .validate(email); + + await string() + .min(6, '密码不能低于6位') + .required('密码不能为空') + .validate(password); + await new Promise((resolve) => { setTimeout(() => { resolve(''); }, 2000); }); - console.log({ username, password }); - }, [username, password]); + }, [email, password]); return (
{error.message}
} +