'use strict'; import React, { useState, useEffect, useRef } from 'react'; import { connect } from 'react-redux'; import { push } from 'react-router-redux'; import { ApiTable } from '$utils' import { Request } from '@peace/utils' import { Button, Input, Form, Row, Col, message, Tabs, Tooltip } from 'antd'; import { login, LOGIN_ERROR } from '../actions/auth'; import { ExclamationCircleOutlined } from '@ant-design/icons'; import { Uploads } from '$components' import { LockOutlined, UserOutlined } from '@ant-design/icons'; import './login.less'; const FormItem = Form.Item; let codCountDownInterval = null const Login = props => { const { dispatch, user, error, isRequesting } = props const [username, setUserName] = useState('') const [password, setPassword] = useState('') const [phone, setPhone] = useState('') const [code, setCode] = useState('') const [inputChanged, setInputChanged] = useState(false) const [curTabKey, setCurTabKey] = useState(1) const [codSending, setCodSending] = useState(false) const [codCountDown, setCodeCountDown] = useState(60) const codCountDownRef = useRef(0) const [form] = Form.useForm(); useEffect(() => { // 水环境跳转自动登录 const structId = getUrlParams(window.location.search)?.structId; if (structId) { sessionStorage.setItem('structId', structId); dispatch(login({ username: 'SuperAdmin', password: '123456' })); } }, []) useEffect(() => { if (user && user.authorized) { dispatch(push('/systemManagement')); } }, [user]) useEffect(() => { if (codSending) { setCodeCountDown(59) codCountDownRef.current = 59 codCountDownInterval = setInterval(() => { codCountDownRef.current -= 1 if (codCountDownRef.current == 0) { setCodSending(false) setCodeCountDown(60) clearInterval(codCountDownInterval) codCountDownInterval = null } else { setCodeCountDown(codCountDownRef.current) } }, 1000); } else { if (codCountDownInterval) { clearInterval(codCountDownInterval) codCountDownInterval = null setCodeCountDown(60) } } }, [codSending]) return (
{/* */}
系统登录
{ form.validateFields().then(r => { dispatch(login({ username: r.username, password: r.password })); }) .catch(err => { dispatch({ type: LOGIN_ERROR, payload: { error: '请输入账号名和密码' } }) }) }} style={{ width: '100%', height: 400, display: 'flex', alignItems: 'center', flexDirection: 'column' }} > 账户 } style={{ width: 380, margin: '6px 0px 6px 0' }} placeholder="" /> 密码 } style={{ width: 380, margin: '6px 0' }} placeholder="" />
); } function mapStateToProps(state) { const { auth, global } = state; return { user: auth.user, error: auth.error, isRequesting: auth.isRequesting, } } export default connect(mapStateToProps)(Login); function getUrlParams(url) { if (!url) return; let arr = url.split('?'); let params = arr[1].split('&'); let obj = {}; for (let i = 0; i < params.length; i++) { let param = params[i].split('='); obj[param[0]] = param[1]; } return obj; }