|
@@ -3,7 +3,8 @@ import { userStore } from '@/store/mobx'
|
|
|
import { iFromValues, iLoginProps, iRetrieveFormProps } from '@/types/login'
|
|
|
import consts from '@/utils/consts'
|
|
|
import { Button, Form, Input, Modal } from 'antd'
|
|
|
-import React, { Component } from 'react'
|
|
|
+import React, { useState, useEffect } from 'react'
|
|
|
+import { useAliveController } from 'react-activation'
|
|
|
import { RouteComponentProps, withRouter } from 'react-router-dom'
|
|
|
import { apiProject } from "./api"
|
|
|
import styles from './index.module.scss'
|
|
@@ -17,51 +18,50 @@ const initLoginState = {
|
|
|
}
|
|
|
|
|
|
type iState = typeof initLoginState
|
|
|
-class NormalLoginForm extends Component<iLoginProps, iState> {
|
|
|
-
|
|
|
- constructor(props: iLoginProps) {
|
|
|
- super(props)
|
|
|
- this.state = initLoginState
|
|
|
- }
|
|
|
- onFinish = (values: iFromValues) => {
|
|
|
+const NormalLoginForm:React.FC<iLoginProps> = () => {
|
|
|
+ const { clear } = useAliveController()
|
|
|
+ useEffect(() => {
|
|
|
+ clear()
|
|
|
+ }, [])
|
|
|
+ const [ state, setState ] = useState<iState>(initLoginState)
|
|
|
+ const onFinish = (values: iFromValues) => {
|
|
|
userStore.login(values)
|
|
|
}
|
|
|
|
|
|
- handleProjectCode = async (e: any) => {
|
|
|
+
|
|
|
+ const handleProjectCode = async (e: any) => {
|
|
|
const projectCode = e.target?.value
|
|
|
const { code = -1, data = [] } = await apiProject(projectCode)
|
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
|
if (data.length && data[0].name) {
|
|
|
- this.setState({ projectInfo: data[0].name })
|
|
|
+ setState({ ...state, projectInfo: data[0].name })
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- setVisible = (label: boolean) => {
|
|
|
- this.setState({ visible: label })
|
|
|
+ const setVisible = (label: boolean) => {
|
|
|
+ setState({ ...state, visible: label })
|
|
|
}
|
|
|
|
|
|
- handleForgetPsw = () => {
|
|
|
- this.setState({ visible: !this.state.visible })
|
|
|
+ const handleForgetPsw = () => {
|
|
|
+ setState({ ...state, visible: !state.visible })
|
|
|
}
|
|
|
|
|
|
- render() {
|
|
|
- const { projectInfo } = this.state
|
|
|
return (
|
|
|
<Form
|
|
|
name="normal_login"
|
|
|
className={styles.loginForm}
|
|
|
// initialValues={{ password: '123456', code : '234' }}
|
|
|
- onFinish={this.onFinish}
|
|
|
+ onFinish={onFinish}
|
|
|
>
|
|
|
<h4>纵横工程建设项目管理系统</h4>
|
|
|
- <h5 className={[ 'project-title' ].join(' ')} >{projectInfo}</h5>
|
|
|
+ <h5 className={[ 'project-title' ].join(' ')} >{state.projectInfo}</h5>
|
|
|
<Form.Item
|
|
|
name="code"
|
|
|
rules={[ { required: true, message: '请输入项目编号!' } ]}
|
|
|
>
|
|
|
- <Input placeholder="项目编号" onChange={this.handleProjectCode} autoFocus/>
|
|
|
+ <Input placeholder="项目编号" onChange={handleProjectCode} autoFocus/>
|
|
|
</Form.Item>
|
|
|
<Form.Item
|
|
|
name="account"
|
|
@@ -82,10 +82,9 @@ class NormalLoginForm extends Component<iLoginProps, iState> {
|
|
|
{/* <div className={styles.textRight}>
|
|
|
<span onClick={this.handleForgetPsw}>忘记密码?</span>
|
|
|
</div> */}
|
|
|
- <RetrieveForm visible={this.state.visible} setVisible={this.setVisible} />
|
|
|
+ <RetrieveForm visible={state.visible} setVisible={setVisible} />
|
|
|
</Form>
|
|
|
)
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
// 找回密码Form表单
|