12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import React from 'react';
- import axios from 'axios';
- import { Button, Form, Input } from 'antd';
- import { history } from 'umi';
- import { setSessionToken } from '@/utils/token';
- import './index.less'
- interface IProps {
- }
- const onFinish = (values: any) => {
- console.log('Success:', values);
- const response: any = axios.get('/api/token').then((res) => res.data.data);
- const current = new Date();
- const expireTime = current.setTime(current.getTime() + 1000 * 12 * 60 * 60);
- setSessionToken(response.token, response.token, expireTime);
- history.push('/');
- };
- const onFinishFailed = (errorInfo: any) => {
- console.log('Failed:', errorInfo);
- };
- const Login: React.FC<IProps> = ((): JSX.Element => {
- return <div className='login'>
- <div className='w_1200'>
- <Form
- name="basic"
- labelCol={{ span: 7 }}
- wrapperCol={{ span: 10 }}
- style={{ maxWidth: 1200 }}
- initialValues={{ remember: true }}
- onFinish={onFinish}
- onFinishFailed={onFinishFailed}
- autoComplete="off"
- >
- <Form.Item
- label="用户名"
- name="username"
- rules={[{ required: true, message: '请输入用户名!' }]}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="密码"
- name="password"
- rules={[{ required: true, message: '请输入密码d!' }]}
- >
- <Input.Password />
- </Form.Item>
- <Form.Item wrapperCol={{ offset: 7, span: 10 }}>
- <Button type="primary" htmlType="submit">
- 登录
- </Button>
- </Form.Item>
- </Form>
- </div>
- </div>
- });
- export default Login;
|