diff --git a/src/components/management/AddUser.tsx b/src/components/management/AddUser.tsx index 133edb6..94dc5e4 100644 --- a/src/components/management/AddUser.tsx +++ b/src/components/management/AddUser.tsx @@ -26,7 +26,10 @@ class AddUser extends React.Component { handleOk = () => { this.formRef.current?.submit(); - this.props.onSuccess(); + }; + + handleCancel = () => { + this.switchShow(); }; switchShow = () => { @@ -39,13 +42,20 @@ class AddUser extends React.Component { trailwayAddUser(values).then((resp: any) => { if (resp.code == 200) { this.switchShow(); + this.props.onSuccess(); } }); }; render() { return ( - +
diff --git a/src/components/management/ChangePwd.tsx b/src/components/management/ChangePwd.tsx new file mode 100644 index 0000000..1da07ce --- /dev/null +++ b/src/components/management/ChangePwd.tsx @@ -0,0 +1,73 @@ +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, trailwayChangePwd } from '../../service'; + +type ChangePwdState = { + isShow: boolean; + userId: Number; +}; + +type ChangePwdProps = { + showChangePwd?: () => void; +}; + +class ChangePwd extends React.Component { + private formRef = React.createRef(); + + constructor(props: ChangePwdProps) { + super(props); + this.state = { + isShow: false, + userId: 0, + }; + } + + handleOk = () => { + this.formRef.current?.submit(); + }; + + handleCancel = () => { + this.switchShow(0); + }; + + switchShow = (id: Number) => { + this.setState((state) => ({ + isShow: !state.isShow, + userId: id, + })); + }; + + handleFinish = (id: Number, values: any) => { + trailwayChangePwd(id, values).then((resp: any) => { + if (resp.code == 200) { + this.switchShow(0); + } + }); + }; + + render() { + return ( + + this.handleFinish(this.state.userId, values)} + > + + + + + + ); + } +} + +export default ChangePwd; diff --git a/src/components/management/UserManage.tsx b/src/components/management/UserManage.tsx index 2b3892c..fe09901 100644 --- a/src/components/management/UserManage.tsx +++ b/src/components/management/UserManage.tsx @@ -5,11 +5,14 @@ import React from 'react'; import { Table, Input, Button } from 'antd'; import { trailwayDelUser, trailwayListUsers } from '../../service'; import AddUser from './AddUser'; +import ChangePwd from './ChangePwd'; class UserManage extends React.Component { constructor(props: {}) { super(props); } + private addUserRef = React.createRef(); + private changePwdRef = React.createRef(); state = { filterDropdownVisible: false, @@ -22,10 +25,6 @@ class UserManage extends React.Component { componentDidMount() { this.refreshUser(); } - - onInputChange = (e: any) => { - this.setState({ searchText: e.target.value }); - }; refreshUser = () => { trailwayListUsers().then((res) => { this.setState({ @@ -33,12 +32,19 @@ class UserManage extends React.Component { }); }); }; - handleSwitchShow = () => { + showAddUser = () => { + this.addUserRef.current?.switchShow(); console.log('handleSwitchShow'); }; + showChangePwd = (userId: Number) => { + this.changePwdRef.current?.switchShow(userId); + }; handleDel = (id: Number) => { - trailwayDelUser(id); - this.refreshUser(); + trailwayDelUser(id).then((res) => { + if (res.code == 200) { + this.refreshUser(); + } + }); }; render() { const columns = [ @@ -63,8 +69,12 @@ class UserManage extends React.Component { title: '操作', render: (record: any) => (
- - - + + +
record.id} + />