From cbbcbb71fe5d4e089e81fc539479d91d4eaf4f53 Mon Sep 17 00:00:00 2001 From: vapao Date: Tue, 24 Nov 2020 20:16:48 +0800 Subject: [PATCH] ant migrate v4 --- spug_web/src/pages/login/index.js | 186 ++++++++++++++---------------- 1 file changed, 85 insertions(+), 101 deletions(-) diff --git a/spug_web/src/pages/login/index.js b/spug_web/src/pages/login/index.js index 8b7dd29..4aa6f3c 100644 --- a/spug_web/src/pages/login/index.js +++ b/spug_web/src/pages/login/index.js @@ -3,9 +3,9 @@ * Copyright (c) * Released under the AGPL-3.0 License. */ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { Form, Input, Button, Tabs, Modal } from 'antd'; -import { UserOutlined, LockOutlined } from '@ant-design/icons'; +import { UserOutlined, LockOutlined, CopyrightOutlined, GithubOutlined } from '@ant-design/icons'; import styles from './login.module.css'; import history from 'libs/history'; import { http, updatePermissions } from 'libs'; @@ -16,52 +16,45 @@ import requestStore from 'pages/deploy/request/store'; import execStore from 'pages/exec/task/store'; import hostStore from 'pages/host/store'; -class LoginIndex extends React.Component { - constructor(props) { - super(props); - this.state = { - loading: false, - loginType: 'default' - } - } +export default function () { + const [form] = Form.useForm(); + const [loading, setLoading] = useState(false); + const [loginType, setLoginType] = useState('default'); - componentDidMount() { + useEffect(() => { envStore.records = []; appStore.records = []; requestStore.records = []; requestStore.deploys = []; hostStore.records = []; execStore.hosts = []; + }, []) + + function handleSubmit() { + setLoading(true); + const formData = form.getFieldsValue(); + formData['type'] = loginType; + http.post('/api/account/login/', formData) + .then(data => { + if (!data['has_real_ip']) { + Modal.warning({ + title: '安全警告', + className: styles.tips, + content:
+ 未能获取到访问者的真实IP,无法提供基于请求来源IP的合法性验证,详细信息请参考 + 官方文档。 +
, + onOk: () => doLogin(data) + }) + } else { + doLogin(data) + } + }, () => setLoading(false)) } - handleSubmit = () => { - this.props.form.validateFields((err, formData) => { - if (!err) { - this.setState({loading: true}); - formData['type'] = this.state.loginType; - http.post('/api/account/login/', formData) - .then(data => { - if (!data['has_real_ip']) { - Modal.warning({ - title: '安全警告', - className: styles.tips, - content:
- 未能获取到访问者的真实IP,无法提供基于请求来源IP的合法性验证,详细信息请参考 - 官方文档。 -
, - onOk: () => this.doLogin(data) - }) - } else { - this.doLogin(data) - } - }, () => this.setState({loading: false})) - } - }) - }; - - doLogin = (data) => { + function doLogin(data) { localStorage.setItem('token', data['access_token']); localStorage.setItem('nickname', data['nickname']); localStorage.setItem('is_supper', data['is_supper']); @@ -73,67 +66,58 @@ class LoginIndex extends React.Component { } else { history.push('/welcome/index') } - }; - - render() { - const {getFieldDecorator} = this.props.form; - return ( -
-
-
logo
-
灵活、强大、功能全面的开源运维平台
-
-
- this.setState({loginType: e})}> - - - -
- - {getFieldDecorator('username', {rules: [{required: true, message: '请输入账户'}]})( - }/> - )} - - - {getFieldDecorator('password', {rules: [{required: true, message: '请输入密码'}]})( - }/> - )} - -
- - -
- -
-
- 官网 - - 文档 -
-
Copyright 2020 By OpenSpug
-
-
- ) } -} -export default Form.create()(LoginIndex) + return ( +
+
+
logo
+
灵活、强大、功能全面的开源运维平台
+
+
+ setLoginType(v)}> + + + +
+ + }/> + + + }/> + +
+ + +
+ +
+
+ 官网 + + 文档 +
+
Copyright 2020 By OpenSpug
+
+
+ ) +}