|
|
@@ -4,7 +4,7 @@ import { useNavigate } from 'react-router-dom';
|
|
|
import { Input, Loading, Form, Grid } from '@alifd/next';
|
|
|
const { Row, Col } = Grid
|
|
|
import { CustomMessage } from '@/components/CustomMessage'
|
|
|
-import { useLoading } from '@/components/LoadingContext';
|
|
|
+import { useLoading } from '@/components/LoadingContext';
|
|
|
|
|
|
export default function Login({ setIsLoggedIn }: { setIsLoggedIn: (loggedIn: boolean) => void }) {
|
|
|
const formRef = useRef<any>(null);
|
|
|
@@ -89,7 +89,7 @@ export default function Login({ setIsLoggedIn }: { setIsLoggedIn: (loggedIn: boo
|
|
|
const { msg = "", token = "", code } = res;
|
|
|
if (!code) {
|
|
|
// setLoading(false);
|
|
|
- hideLoading();
|
|
|
+ hideLoading();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -97,7 +97,7 @@ export default function Login({ setIsLoggedIn }: { setIsLoggedIn: (loggedIn: boo
|
|
|
evVerify()
|
|
|
CustomMessage.error(msg);
|
|
|
// setLoading(false);
|
|
|
- hideLoading();
|
|
|
+ hideLoading();
|
|
|
return false;
|
|
|
}
|
|
|
fetch('https://user.landwu.com/api/user/getProfile', {
|
|
|
@@ -117,7 +117,7 @@ export default function Login({ setIsLoggedIn }: { setIsLoggedIn: (loggedIn: boo
|
|
|
localStorage.setItem('isLoggedIn', 'true');
|
|
|
setTimeout(() => {
|
|
|
// setLoading(false);
|
|
|
- hideLoading();
|
|
|
+ hideLoading();
|
|
|
setIsLoggedIn(true);
|
|
|
// 跳转到首页
|
|
|
navigate('/');
|
|
|
@@ -125,158 +125,156 @@ export default function Login({ setIsLoggedIn }: { setIsLoggedIn: (loggedIn: boo
|
|
|
}
|
|
|
}).catch(err => {
|
|
|
// setLoading(false);
|
|
|
- hideLoading();
|
|
|
+ hideLoading();
|
|
|
})
|
|
|
}).catch((e) => {
|
|
|
console.log("catch")
|
|
|
// setLoading(false);
|
|
|
- hideLoading();
|
|
|
+ hideLoading();
|
|
|
});
|
|
|
} catch (error) {
|
|
|
console.error('登录请求失败:', error);
|
|
|
CustomMessage.error('网络错误,请稍后重试');
|
|
|
- hideLoading();
|
|
|
+ hideLoading();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
- <Loading visible={loading} fullScreen>
|
|
|
- <div className="bg-gray-50 p-4">
|
|
|
- <div className="text-center mb-6">
|
|
|
- <h1 className="text-2xl font-bold text-gray-800">登录</h1>
|
|
|
- </div>
|
|
|
+ <div className="bg-gray-50 p-4">
|
|
|
+ <div className="text-center mb-6">
|
|
|
+ <h1 className="text-2xl font-bold text-gray-800">登录</h1>
|
|
|
+ </div>
|
|
|
|
|
|
- <Form>
|
|
|
- <Form.Item
|
|
|
- label="用户名"
|
|
|
- name="username"
|
|
|
- required
|
|
|
- help={errors.username}
|
|
|
- validateState={errors.username ? 'error' : undefined}
|
|
|
- >
|
|
|
- <Input
|
|
|
- placeholder="请输入用户名"
|
|
|
- value={username}
|
|
|
- onChange={(value) => {
|
|
|
- if (typeof value === 'string') {
|
|
|
- setUsername(value);
|
|
|
- } else {
|
|
|
- setUsername(String(value));
|
|
|
- }
|
|
|
- if (errors.username) {
|
|
|
- setErrors({ ...errors, username: undefined });
|
|
|
- }
|
|
|
- }}
|
|
|
- disabled={loading}
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
+ <Form>
|
|
|
+ <Form.Item
|
|
|
+ label="用户名"
|
|
|
+ name="username"
|
|
|
+ required
|
|
|
+ help={errors.username}
|
|
|
+ validateState={errors.username ? 'error' : undefined}
|
|
|
+ >
|
|
|
+ <Input
|
|
|
+ placeholder="请输入用户名"
|
|
|
+ value={username}
|
|
|
+ onChange={(value) => {
|
|
|
+ if (typeof value === 'string') {
|
|
|
+ setUsername(value);
|
|
|
+ } else {
|
|
|
+ setUsername(String(value));
|
|
|
+ }
|
|
|
+ if (errors.username) {
|
|
|
+ setErrors({ ...errors, username: undefined });
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ disabled={loading}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
|
|
|
- <Form.Item
|
|
|
- label="密码"
|
|
|
- name="password"
|
|
|
- required
|
|
|
- help={errors.password}
|
|
|
- validateState={errors.password ? 'error' : undefined}
|
|
|
- >
|
|
|
- <Input
|
|
|
- htmlType="password"
|
|
|
- placeholder="请输入密码"
|
|
|
- value={password}
|
|
|
- onChange={(value) => {
|
|
|
- if (typeof value === 'string') {
|
|
|
- setPassword(value);
|
|
|
- } else {
|
|
|
- setPassword(String(value));
|
|
|
- }
|
|
|
- if (errors.password) {
|
|
|
- setErrors({ ...errors, password: undefined });
|
|
|
- }
|
|
|
- }}
|
|
|
- disabled={loading}
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item
|
|
|
- label="邀请码"
|
|
|
- name="invitationCode"
|
|
|
- required
|
|
|
- help={errors.invitationCode}
|
|
|
- validateState={errors.invitationCode ? 'error' : undefined}>
|
|
|
- <Input
|
|
|
- htmlType="invitationCode"
|
|
|
- placeholder="请输入邀请码"
|
|
|
- value={invitationCode}
|
|
|
- onChange={(value) => {
|
|
|
- if (typeof value === 'string') {
|
|
|
- setInvitationCode(value);
|
|
|
- } else {
|
|
|
- setInvitationCode(String(value));
|
|
|
- }
|
|
|
- if (errors.invitationCode) {
|
|
|
- setErrors({ ...errors, invitationCode: undefined });
|
|
|
- }
|
|
|
- }}
|
|
|
- disabled={loading}
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
- <Row>
|
|
|
- <Col span={16}>
|
|
|
- <Form.Item
|
|
|
- label="验证码"
|
|
|
- name="code"
|
|
|
- required
|
|
|
- help={errors.code}
|
|
|
- validateState={errors.code ? 'error' : undefined}
|
|
|
- >
|
|
|
- <Input
|
|
|
- size="large"
|
|
|
- placeholder="请输入验证码"
|
|
|
- value={code}
|
|
|
- onChange={(value) => {
|
|
|
- if (typeof value === 'string') {
|
|
|
- setCode(value);
|
|
|
- } else {
|
|
|
- setCode(String(value));
|
|
|
- }
|
|
|
- if (errors.code) {
|
|
|
- setErrors({ ...errors, code: undefined });
|
|
|
- }
|
|
|
- }}
|
|
|
- disabled={loading}
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
- </Col>
|
|
|
- <Col span={8}>
|
|
|
- <img
|
|
|
- src={validImg}
|
|
|
- style={{
|
|
|
- width: 82,
|
|
|
- height: 28,
|
|
|
- marginTop: 28,
|
|
|
- cursor: 'pointer',
|
|
|
+ <Form.Item
|
|
|
+ label="密码"
|
|
|
+ name="password"
|
|
|
+ required
|
|
|
+ help={errors.password}
|
|
|
+ validateState={errors.password ? 'error' : undefined}
|
|
|
+ >
|
|
|
+ <Input
|
|
|
+ htmlType="password"
|
|
|
+ placeholder="请输入密码"
|
|
|
+ value={password}
|
|
|
+ onChange={(value) => {
|
|
|
+ if (typeof value === 'string') {
|
|
|
+ setPassword(value);
|
|
|
+ } else {
|
|
|
+ setPassword(String(value));
|
|
|
+ }
|
|
|
+ if (errors.password) {
|
|
|
+ setErrors({ ...errors, password: undefined });
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ disabled={loading}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item
|
|
|
+ label="邀请码"
|
|
|
+ name="invitationCode"
|
|
|
+ required
|
|
|
+ help={errors.invitationCode}
|
|
|
+ validateState={errors.invitationCode ? 'error' : undefined}>
|
|
|
+ <Input
|
|
|
+ htmlType="invitationCode"
|
|
|
+ placeholder="请输入邀请码"
|
|
|
+ value={invitationCode}
|
|
|
+ onChange={(value) => {
|
|
|
+ if (typeof value === 'string') {
|
|
|
+ setInvitationCode(value);
|
|
|
+ } else {
|
|
|
+ setInvitationCode(String(value));
|
|
|
+ }
|
|
|
+ if (errors.invitationCode) {
|
|
|
+ setErrors({ ...errors, invitationCode: undefined });
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ disabled={loading}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ <Row>
|
|
|
+ <Col span={16}>
|
|
|
+ <Form.Item
|
|
|
+ label="验证码"
|
|
|
+ name="code"
|
|
|
+ required
|
|
|
+ help={errors.code}
|
|
|
+ validateState={errors.code ? 'error' : undefined}
|
|
|
+ >
|
|
|
+ <Input
|
|
|
+ size="large"
|
|
|
+ placeholder="请输入验证码"
|
|
|
+ value={code}
|
|
|
+ onChange={(value) => {
|
|
|
+ if (typeof value === 'string') {
|
|
|
+ setCode(value);
|
|
|
+ } else {
|
|
|
+ setCode(String(value));
|
|
|
+ }
|
|
|
+ if (errors.code) {
|
|
|
+ setErrors({ ...errors, code: undefined });
|
|
|
+ }
|
|
|
}}
|
|
|
- onClick={evVerify}
|
|
|
+ disabled={loading}
|
|
|
/>
|
|
|
- </Col>
|
|
|
- </Row>
|
|
|
+ </Form.Item>
|
|
|
+ </Col>
|
|
|
+ <Col span={8}>
|
|
|
+ <img
|
|
|
+ src={validImg}
|
|
|
+ style={{
|
|
|
+ width: 82,
|
|
|
+ height: 28,
|
|
|
+ marginTop: 28,
|
|
|
+ cursor: 'pointer',
|
|
|
+ }}
|
|
|
+ onClick={evVerify}
|
|
|
+ />
|
|
|
+ </Col>
|
|
|
+ </Row>
|
|
|
|
|
|
- <Form.Item>
|
|
|
- <Form.Submit
|
|
|
- type="primary"
|
|
|
- validate
|
|
|
- loading={loading}
|
|
|
- onClick={handleLogin}
|
|
|
- className="w-full"
|
|
|
- style={{ marginRight: 8 }}
|
|
|
- >
|
|
|
- {loading ? '登录中...' : '登录'}
|
|
|
- </Form.Submit>
|
|
|
- </Form.Item>
|
|
|
- </Form>
|
|
|
+ <Form.Item>
|
|
|
+ <Form.Submit
|
|
|
+ type="primary"
|
|
|
+ validate
|
|
|
+ loading={loading}
|
|
|
+ onClick={handleLogin}
|
|
|
+ className="w-full"
|
|
|
+ style={{ marginRight: 8 }}
|
|
|
+ >
|
|
|
+ {loading ? '登录中...' : '登录'}
|
|
|
+ </Form.Submit>
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
|
|
|
- <div className="mt-4 text-center text-sm text-gray-500">
|
|
|
- <p>忘记密码?请联系管理员</p>
|
|
|
- </div>
|
|
|
+ <div className="mt-4 text-center text-sm text-gray-500">
|
|
|
+ <p>忘记密码?请联系管理员</p>
|
|
|
</div>
|
|
|
- </Loading>
|
|
|
+ </div>
|
|
|
);
|
|
|
}
|