|
|
|
@ -2,6 +2,10 @@ import React, { useEffect, useState} from 'react'; |
|
|
|
|
|
|
|
import { Form, Input, Button, Checkbox } from 'antd'; |
|
|
|
|
|
|
|
import _auth from '@netuno/auth-client'; |
|
|
|
|
|
|
|
import { Redirect } from "react-router-dom"; |
|
|
|
|
|
|
|
import './index.less'; |
|
|
|
|
|
|
|
const layout = { |
|
|
|
@ -13,14 +17,41 @@ const tailLayout = { |
|
|
|
}; |
|
|
|
|
|
|
|
export default ()=> { |
|
|
|
const [loading, setLoading] = useState(false); |
|
|
|
|
|
|
|
const onFinish = (values) => { |
|
|
|
console.log('Success:', values); |
|
|
|
setLoading(true); |
|
|
|
_auth.login({ |
|
|
|
username: values.username, |
|
|
|
password: values.password, |
|
|
|
success: ()=> { |
|
|
|
setLoading(false); |
|
|
|
if (values.remember) { |
|
|
|
localStorage.setItem("login", JSON.stringify(values)); |
|
|
|
} else { |
|
|
|
localStorage.removeItem("login"); |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: ()=> { |
|
|
|
setLoading(false); |
|
|
|
alert("Fail."); |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
const onFinishFailed = (errorInfo) => { |
|
|
|
console.log('Failed:', errorInfo); |
|
|
|
}; |
|
|
|
|
|
|
|
let initialValues = { |
|
|
|
remember: true, |
|
|
|
}; |
|
|
|
if (localStorage.getItem("login")) { |
|
|
|
initialValues = JSON.parse(localStorage.getItem("login")); |
|
|
|
} |
|
|
|
if (_auth.isLogged()) { |
|
|
|
return <Redirect to="/main" />; |
|
|
|
} |
|
|
|
return ( |
|
|
|
<div className="login"> |
|
|
|
<h1>Login</h1> |
|
|
|
@ -28,9 +59,7 @@ export default ()=> { |
|
|
|
<Form |
|
|
|
{...layout} |
|
|
|
name="basic" |
|
|
|
initialValues={{ |
|
|
|
remember: true, |
|
|
|
}} |
|
|
|
initialValues={initialValues} |
|
|
|
onFinish={onFinish} |
|
|
|
onFinishFailed={onFinishFailed} |
|
|
|
> |
|
|
|
@ -65,7 +94,7 @@ export default ()=> { |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
<Form.Item {...tailLayout}> |
|
|
|
<Button type="primary" htmlType="submit"> |
|
|
|
<Button type="primary" htmlType="submit" loading={loading}> |
|
|
|
Entrar |
|
|
|
</Button> |
|
|
|
</Form.Item> |
|
|
|
|