first commit

This commit is contained in:
2024-01-11 00:49:37 +08:00
commit 1d4ca069e7
169 changed files with 44956 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
/**
* Created by hao.cheng on 2017/4/16.
*/
import React, { useEffect } from 'react';
import { Button, Form, Input } from 'antd';
import { PwaInstaller } from '../widget';
import { useAlita } from 'redux-alita';
import { RouteComponentProps } from 'react-router';
import { FormProps } from 'antd/lib/form';
import umbrella from 'umbrella-storage';
import { GithubOutlined, LockOutlined, UserOutlined } from '@ant-design/icons';
import { useUpdateEffect } from 'ahooks';
import { trailwayLogin } from '../../service';
const FormItem = Form.Item;
type LoginProps = {
setAlitaState: (param: any) => void;
auth: any;
} & RouteComponentProps &
FormProps;
const Login = (props: LoginProps) => {
const { history } = props;
const [auth, setAlita] = useAlita({ auth: {} }, { light: true });
useEffect(() => {
setAlita('auth', null);
}, [setAlita]);
useUpdateEffect(() => {
if (auth && auth.uid) {
// 判断是否登陆
umbrella.setLocalStorage('user', auth);
history.push('/');
}
}, [history, auth]);
const handleSubmit = (values: any) => {
if (checkUser(values)) {
setAlita({ funcName: values.userName, stateName: 'auth' });
}
};
const checkUser = (values: any) => {
// const users = [
// ['admin', 'admin'],
// ['guest', 'guest'],
// ];
// return users.some((user) => user[0] === values.userName && user[1] === values.password);
let success = trailwayLogin({ username: values.userName, password: values.password }).then(
(res) => {
console.log(res);
return res.data.success === true;
}
);
console.log(success);
return success;
};
const gitHub = () => {
window.location.href =
'https://github.com/login/oauth/authorize?client_id=792cdcd244e98dcd2dee&redirect_uri=http://localhost:3006/&scope=user&state=reactAdmin';
};
return (
<div className="login">
<div className="login-form">
<div className="login-logo">
<span>React Admin</span>
<PwaInstaller />
</div>
<Form onFinish={handleSubmit} style={{ maxWidth: '300px' }}>
<FormItem
name="userName"
rules={[{ required: true, message: '请输入用户名!' }]}
>
<Input
prefix={<UserOutlined size={13} />}
placeholder="管理员输入admin, 游客输入guest"
/>
</FormItem>
<FormItem name="password" rules={[{ required: true, message: '请输入密码!' }]}>
<Input
prefix={<LockOutlined size={13} />}
type="password"
placeholder="管理员输入admin, 游客输入guest"
/>
</FormItem>
<FormItem>
<span className="login-form-forgot" style={{ float: 'right' }}>
</span>
<Button
type="primary"
htmlType="submit"
className="login-form-button"
style={{ width: '100%' }}
>
</Button>
<p style={{ display: 'flex', justifyContent: 'space-between' }}>
<span> !</span>
<span onClick={gitHub}>
<GithubOutlined />
()
</span>
</p>
</FormItem>
</Form>
</div>
</div>
);
};
export default Login;