|
@@ -1,141 +1,142 @@
|
|
-import React, { Component } from 'react';
|
|
|
|
|
|
+import React, { useRef, useState } from 'react';
|
|
import { connect } from 'umi';
|
|
import { connect } from 'umi';
|
|
-import { Checkbox, Form, Select, Input, Button } from 'antd';
|
|
|
|
|
|
+import { Form, Select, Input, Button, message } from 'antd';
|
|
import { queryDepList } from '@/Project/services/user';
|
|
import { queryDepList } from '@/Project/services/user';
|
|
import styles from './index.less';
|
|
import styles from './index.less';
|
|
import { UserOutlined, LockOutlined } from '@ant-design/icons';
|
|
import { UserOutlined, LockOutlined } from '@ant-design/icons';
|
|
|
|
|
|
const { Option } = Select;
|
|
const { Option } = Select;
|
|
|
|
|
|
-class LoginPage extends Component {
|
|
|
|
- formRef = null;
|
|
|
|
- state = {
|
|
|
|
- type: 'account',
|
|
|
|
- depList: [],
|
|
|
|
- hasName: false,
|
|
|
|
- };
|
|
|
|
- constructor(props) {
|
|
|
|
- super(props);
|
|
|
|
- this.formRef = React.createRef();
|
|
|
|
- }
|
|
|
|
- componentDidMount = () => {};
|
|
|
|
- onHandleChange = async (name) => {
|
|
|
|
- var res = await queryDepList(name);
|
|
|
|
- this.setState({
|
|
|
|
- depList: res.data,
|
|
|
|
- hasName: true,
|
|
|
|
- });
|
|
|
|
- this.formRef.current.setFieldsValue({
|
|
|
|
- DepId: res.data[0]?.ID + '',
|
|
|
|
- });
|
|
|
|
|
|
+function Login(props) {
|
|
|
|
+ const {
|
|
|
|
+ submitting,
|
|
|
|
+ params,
|
|
|
|
+ dispatch,
|
|
|
|
+ initState: { refresh },
|
|
|
|
+ } = props;
|
|
|
|
+ const [depList, setDepList] = useState([]);
|
|
|
|
+ const [hasName, setHasName] = useState(false);
|
|
|
|
+ const formRef = useRef();
|
|
|
|
+
|
|
|
|
+ const onHandleChange = async (name) => {
|
|
|
|
+ if (!name) {
|
|
|
|
+ setDepList([]);
|
|
|
|
+ setHasName(false);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ var res = await queryDepList(name);
|
|
|
|
+ setDepList(res.data);
|
|
|
|
+ setHasName(true);
|
|
|
|
+ formRef.current.setFieldsValue({
|
|
|
|
+ DepId: res.data[0]?.ID + '',
|
|
|
|
+ });
|
|
|
|
+ } catch (error) {
|
|
|
|
+ setDepList([]);
|
|
|
|
+ setHasName(true);
|
|
|
|
+ message.error('用户名不存在');
|
|
|
|
+ }
|
|
};
|
|
};
|
|
|
|
|
|
- handleSubmit = (values) => {
|
|
|
|
- const { type } = this.state;
|
|
|
|
- const { dispatch } = this.props;
|
|
|
|
|
|
+ const handleSubmit = (values) => {
|
|
dispatch({
|
|
dispatch({
|
|
type: 'login/login',
|
|
type: 'login/login',
|
|
payload: {
|
|
payload: {
|
|
...values,
|
|
...values,
|
|
// 防止浏览器自动填充
|
|
// 防止浏览器自动填充
|
|
password: values.password2,
|
|
password: values.password2,
|
|
- type,
|
|
|
|
},
|
|
},
|
|
- callback: () => {
|
|
|
|
- this.props.params.gotoA();
|
|
|
|
|
|
+ callback: (token) => {
|
|
|
|
+ params.login(token);
|
|
|
|
+ refresh();
|
|
},
|
|
},
|
|
});
|
|
});
|
|
};
|
|
};
|
|
-
|
|
|
|
- render() {
|
|
|
|
- const { depList, hasName } = this.state;
|
|
|
|
- const { submitting } = this.props;
|
|
|
|
- return (
|
|
|
|
- <div className={styles.main}>
|
|
|
|
- <div className={styles.content}>
|
|
|
|
- <Form
|
|
|
|
- name="basic"
|
|
|
|
- className={styles.inp_box}
|
|
|
|
- labelCol={{ span: 0 }}
|
|
|
|
- wrapperCol={{ span: 24 }}
|
|
|
|
- onFinish={this.handleSubmit}
|
|
|
|
- autoComplete="new-password"
|
|
|
|
- ref={this.formRef}
|
|
|
|
|
|
+ return (
|
|
|
|
+ <div className={styles.main}>
|
|
|
|
+ <div className={styles.content}>
|
|
|
|
+ <Form
|
|
|
|
+ name="basic"
|
|
|
|
+ className={styles.inp_box}
|
|
|
|
+ labelCol={{ span: 0 }}
|
|
|
|
+ wrapperCol={{ span: 24 }}
|
|
|
|
+ onFinish={handleSubmit}
|
|
|
|
+ autoComplete="new-password"
|
|
|
|
+ ref={formRef}
|
|
|
|
+ >
|
|
|
|
+ <Form.Item
|
|
|
|
+ label=""
|
|
|
|
+ name="username"
|
|
|
|
+ autoComplete="off"
|
|
|
|
+ rules={[{ required: true, message: '请输入用户名' }]}
|
|
>
|
|
>
|
|
- <Form.Item
|
|
|
|
- label=""
|
|
|
|
- name="username"
|
|
|
|
|
|
+ <Input
|
|
|
|
+ prefix={<UserOutlined className={styles.prefixIcon} />}
|
|
|
|
+ className={styles.inp}
|
|
|
|
+ size="large"
|
|
autoComplete="off"
|
|
autoComplete="off"
|
|
- rules={[{ required: true, message: '请输入用户名' }]}
|
|
|
|
- >
|
|
|
|
- <Input
|
|
|
|
- prefix={<UserOutlined className={styles.prefixIcon} />}
|
|
|
|
- className={styles.inp}
|
|
|
|
- size="large"
|
|
|
|
- autoComplete="off"
|
|
|
|
- placeholder="请输入用户名"
|
|
|
|
- onBlur={(e) => this.onHandleChange(e.target.value)}
|
|
|
|
- />
|
|
|
|
- </Form.Item>
|
|
|
|
- {hasName && (
|
|
|
|
- <Form.Item
|
|
|
|
- label=""
|
|
|
|
- name="DepId"
|
|
|
|
- rules={[{ required: true, message: '请输入用户名' }]}
|
|
|
|
- >
|
|
|
|
- <Select placeholder="请选择部门" size="large">
|
|
|
|
- {depList.map((item) => (
|
|
|
|
- <Option value={item.ID + ''} key={item.ID}>
|
|
|
|
- {item.Name}
|
|
|
|
- </Option>
|
|
|
|
- ))}
|
|
|
|
- </Select>
|
|
|
|
- </Form.Item>
|
|
|
|
- )}
|
|
|
|
-
|
|
|
|
|
|
+ placeholder="请输入用户名"
|
|
|
|
+ onBlur={(e) => onHandleChange(e.target.value)}
|
|
|
|
+ />
|
|
|
|
+ </Form.Item>
|
|
|
|
+ {hasName && (
|
|
<Form.Item
|
|
<Form.Item
|
|
label=""
|
|
label=""
|
|
- // 不使用password,防止浏览器自动填充表单
|
|
|
|
- name="password2"
|
|
|
|
- className={styles.inp}
|
|
|
|
- rules={[{ required: true, message: '请输入密码' }]}
|
|
|
|
|
|
+ name="DepId"
|
|
|
|
+ rules={[{ required: true, message: '请选择部门' }]}
|
|
>
|
|
>
|
|
- <Input.Password
|
|
|
|
- prefix={<LockOutlined className={styles.prefixIcon} />}
|
|
|
|
- className={styles.inp}
|
|
|
|
- size="large"
|
|
|
|
- placeholder="请输入密码"
|
|
|
|
- autoComplete="new-password"
|
|
|
|
- />
|
|
|
|
|
|
+ <Select placeholder="请选择部门" size="large">
|
|
|
|
+ {depList.map((item) => (
|
|
|
|
+ <Option value={item.ID + ''} key={item.ID}>
|
|
|
|
+ {item.Name}
|
|
|
|
+ </Option>
|
|
|
|
+ ))}
|
|
|
|
+ </Select>
|
|
</Form.Item>
|
|
</Form.Item>
|
|
|
|
+ )}
|
|
|
|
|
|
- {/* <Form.Item
|
|
|
|
- name="remember"
|
|
|
|
- valuePropName="checked"
|
|
|
|
- wrapperCol={{ offset: 8, span: 16 }}
|
|
|
|
|
|
+ <Form.Item
|
|
|
|
+ label=""
|
|
|
|
+ // 不使用password,防止浏览器自动填充表单
|
|
|
|
+ name="password2"
|
|
|
|
+ className={styles.inp}
|
|
|
|
+ rules={[{ required: true, message: '请输入密码' }]}
|
|
>
|
|
>
|
|
- <Checkbox>自动登录</Checkbox>
|
|
|
|
- </Form.Item> */}
|
|
|
|
|
|
+ <Input.Password
|
|
|
|
+ prefix={<LockOutlined className={styles.prefixIcon} />}
|
|
|
|
+ className={styles.inp}
|
|
|
|
+ size="large"
|
|
|
|
+ placeholder="请输入密码"
|
|
|
|
+ autoComplete="new-password"
|
|
|
|
+ />
|
|
|
|
+ </Form.Item>
|
|
|
|
|
|
- <Form.Item>
|
|
|
|
- <Button
|
|
|
|
- size="large"
|
|
|
|
- style={{ width: '100%', marginTop: 24 }}
|
|
|
|
- loading={submitting}
|
|
|
|
- type="primary"
|
|
|
|
- htmlType="submit"
|
|
|
|
- >
|
|
|
|
- 登录
|
|
|
|
- </Button>
|
|
|
|
- </Form.Item>
|
|
|
|
- </Form>
|
|
|
|
- </div>
|
|
|
|
|
|
+ {/* <Form.Item
|
|
|
|
+ name="remember"
|
|
|
|
+ valuePropName="checked"
|
|
|
|
+ wrapperCol={{ offset: 8, span: 16 }}
|
|
|
|
+ >
|
|
|
|
+ <Checkbox>自动登录</Checkbox>
|
|
|
|
+ </Form.Item> */}
|
|
|
|
+
|
|
|
|
+ <Form.Item>
|
|
|
|
+ <Button
|
|
|
|
+ size="large"
|
|
|
|
+ style={{ width: '100%', marginTop: 24 }}
|
|
|
|
+ loading={submitting}
|
|
|
|
+ type="primary"
|
|
|
|
+ htmlType="submit"
|
|
|
|
+ >
|
|
|
|
+ 登录
|
|
|
|
+ </Button>
|
|
|
|
+ </Form.Item>
|
|
|
|
+ </Form>
|
|
</div>
|
|
</div>
|
|
- );
|
|
|
|
- }
|
|
|
|
|
|
+ </div>
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
export default connect(({ login, loading }) => ({
|
|
export default connect(({ login, loading }) => ({
|
|
login,
|
|
login,
|
|
submitting: loading.effects['login/login'],
|
|
submitting: loading.effects['login/login'],
|
|
-}))(LoginPage);
|
|
|
|
|
|
+}))(Login);
|