This commit is contained in:
2024-01-15 00:42:28 +08:00
parent 8a37345ffc
commit deb5a2ea11
6 changed files with 78 additions and 2 deletions

View File

@@ -0,0 +1,56 @@
import React, { useState, SetStateAction } from 'react';
import Modal from 'antd/lib/modal/Modal';
import { Input } from 'antd';
import Form, { FormInstance } from 'antd/lib/form/Form';
import FormItem from 'antd/lib/form/FormItem';
import { trailwayAddUser } from '../../service';
type AddUserState = {
isShow: boolean;
};
class AddUser extends React.Component<{}, AddUserState> {
private formRef = React.createRef<FormInstance>();
constructor(props: {}) {
super(props);
this.state = {
isShow: false,
};
}
handleOk = () => {
console.log(this.formRef.current?.submit());
};
switchShow = () => {
this.setState((state) => ({
isShow: !state.isShow,
}));
};
handleFinish = (values: any) => {
return trailwayAddUser(values).then((resp: any) => {
if (resp.code == 200) {
this.switchShow();
}
});
};
render() {
return (
<Modal title="增加用户" visible={this.state.isShow} onOk={this.handleOk}>
<Form ref={this.formRef} onFinish={this.handleFinish}>
<FormItem name="username">
<Input placeholder="账户" />
</FormItem>
<FormItem name="password">
<Input placeholder="密码" />
</FormItem>
</Form>
</Modal>
);
}
}
export default AddUser;