You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
4.3 KiB
126 lines
4.3 KiB
'use strict';
|
|
import React, { useState, useEffect } from 'react';
|
|
import { connect } from 'react-redux';
|
|
import { push } from 'react-router-redux';
|
|
import { Button, Input, Form, Row, Col, message } from 'antd';
|
|
import { login } from '../actions/auth';
|
|
import './style.less';
|
|
import leftTop from '../../quanju/containers/footer/conserve/left/left-top';
|
|
|
|
const FormItem = Form.Item;
|
|
const Login = props => {
|
|
const { dispatch, user, error, isRequesting } = props
|
|
const [username, setUserName] = useState('')
|
|
const [password, setPassword] = useState('')
|
|
const [inputChanged, setInputChanged] = useState(false)
|
|
|
|
useEffect(() => {
|
|
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
if (error) {
|
|
message.error(error);
|
|
setPassword('')
|
|
}
|
|
}, [error])
|
|
|
|
useEffect(() => {
|
|
const allroutes = JSON.parse(sessionStorage.getItem('allRoutes')) || []
|
|
let hasAuth = []
|
|
if (user && user.authorized) {
|
|
hasAuth = allroutes?.filter((item) => { return user?.userResources.find((child) => { return child.resourceId === item.authCode }) })
|
|
if (user?.username === 'SuperAdmin') {
|
|
dispatch(push('/fillion/infor'))
|
|
}
|
|
else if (hasAuth && hasAuth.length > 0) {
|
|
const path = hasAuth[0].path
|
|
//console.log('sasa', `${path}`)
|
|
dispatch(push(path))
|
|
} else {
|
|
dispatch(push('/noContent'))
|
|
}
|
|
}
|
|
|
|
//user && user.authorized ? dispatch(push('/screen/cockpit')) : null
|
|
}, [user])
|
|
|
|
const enterHandler = e => {
|
|
if (e.key === 'Enter') {
|
|
setInputChanged(false)
|
|
dispatch(login(username, password));
|
|
}
|
|
};
|
|
|
|
|
|
const handleLogin = () => {
|
|
let reg_user = "SuperAdmin";
|
|
let reg_tel = /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/; //11位手机号码正则
|
|
if (username == reg_user || reg_tel.test(username)) {
|
|
setInputChanged(false)
|
|
dispatch(login(username, password))
|
|
return
|
|
}
|
|
if (username == "" || password == "") {
|
|
setInputChanged(false)
|
|
dispatch(login(username, password))
|
|
return
|
|
}
|
|
setInputChanged(false)
|
|
dispatch(login(username, password))
|
|
}
|
|
|
|
|
|
return (
|
|
<div className='login'>
|
|
{/* <div className='left'></div> */}
|
|
<div className='right'>
|
|
<div className='loginBox'>
|
|
<h1>南昌县智慧交通监管系统</h1>
|
|
<Form onKeyDown={enterHandler}>
|
|
<FormItem>
|
|
<div className='loginFormTit'>用户名</div>
|
|
<Input
|
|
className='loginInp'
|
|
type="text"
|
|
value={username}
|
|
maxlength={11}
|
|
onChange={e => {
|
|
//('e.target.value', e.target.value)
|
|
setUserName(e.target.value)
|
|
setInputChanged(true)
|
|
}}
|
|
/>
|
|
</FormItem>
|
|
<div className='loginFormTit'>密码</div>
|
|
<FormItem>
|
|
<Input
|
|
className='loginInp'
|
|
type="password"
|
|
value={password}
|
|
|
|
onChange={e => {
|
|
//console.log('setPassword', e.target.value)
|
|
setPassword(e.target.value)
|
|
setInputChanged(true)
|
|
}}
|
|
/>
|
|
</FormItem>
|
|
</Form>
|
|
<Button type="primary" className='loginBtn' loading={isRequesting} onClick={handleLogin}>登录</Button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function mapStateToProps(state) {
|
|
const { auth } = state;
|
|
return {
|
|
user: auth.user,
|
|
error: auth.error,
|
|
isRequesting: auth.isRequesting
|
|
}
|
|
}
|
|
|
|
export default connect(mapStateToProps)(Login);
|