'use strict'; import React, { useState, useEffect, useRef } from 'react'; import { connect } from 'react-redux'; import { push } from 'react-router-redux'; import SHA1 from 'crypto-js/sha1'; import Hex from 'crypto-js/enc-hex'; import { ApiTable } from '$utils' import { Request } from '@peace/utils' import { Button, Input, Form, Row, Col, message, Tabs } from 'antd'; import { login, LOGIN_ERROR } from '../actions/auth'; import { ExclamationCircleOutlined } from '@ant-design/icons'; import { Uploads } from '$components' import '../style.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) useEffect(() => { }, []) useEffect(() => { if (user && user.authorized) { dispatch(push('/homePage')); } }, [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]) const doLogin = () => { if (curTabKey == 1) { if (!username || !password) dispatch({ type: LOGIN_ERROR, payload: { error: '请输入账号名和密码' } }); setInputChanged(false) dispatch(login({ username, password })); } else { if (!phone || !code) dispatch({ type: LOGIN_ERROR, payload: { error: '请输入手机号和验证码' } }); dispatch(login({ phone, code })); } } const enterHandler = e => { if (e.key === 'Enter') { doLogin() } }; return (

政务数据资源中心

{ setCurTabKey(k) }}>
用户名
{ setUserName(e.target.value) setInputChanged(true) }} />
密码
{ setPassword(e.target.value) setInputChanged(true) }} />
手机号
{ setPhone(e.target.value) setInputChanged(true) }} />
验证码
{ setCode(e.target.value) setInputChanged(true) }} />
{ inputChanged || !error ? - : {error} }
); } function mapStateToProps(state) { const { auth } = state; console.log(auth.error); return { user: auth.user, error: auth.error, isRequesting: auth.isRequesting } } export default connect(mapStateToProps)(Login);