import React from "react"; import {Button, Form, Tab, Table, Tabs} from "react-bootstrap"; import {ManagerEntity, PageProps} from "./entity"; import {Input} from "./ui/InputGroup"; import {Cookies} from "react-cookie"; import {MyDialog} from "./ui/MyDialog"; import {JSONResponse, Method, request} from "./interface"; import {API} from "./api"; import {EmptyBodyTransform, ManagerList, ManagerTransform, PageDataMessage, SimpleMessage} from "./result"; import {manager_cookie} from "./account/PropCookie"; import {register} from './public' import {Page} from "./ui/Page"; enum Type { modify, register } class EditManager extends React.Component< { onClick:Function; type:Type; }, { managerId?:string, password:string; confirmPwd:string; }>{ constructor(props: Readonly) { super(props); this.state={ password:"", confirmPwd:"", } } isDisable(){ return !(this.state.password.length>0 &&this.state.confirmPwd.length>0&&this.state.password===this.state.confirmPwd&&((this.state.managerId&&this.state.managerId.length>0)||!this.state.managerId)) } render() { return (
{this.props.type===Type.modify?null: this.setState({ managerId:value }) } valid={{check:this.state.managerId?this.state.managerId.length>0:false}}/> } this.setState({ password:value }) } valid={{check:this.state.password.length>0}}/> { this.setState({ confirmPwd:value }) }} valid={{check:this.state.confirmPwd.length>0&&this.state.password===this.state.confirmPwd, invalid:this.state.confirmPwd.length>0&&this.state.password!==this.state.confirmPwd?"密码和确认密码不一致":"验证失败"}}/>
) } } /** * 管理员管理 */ export class Manager extends React.Component< { cookies:Cookies; }, { //管理员列表数据 managerList?:Array; //弹框界面 dialog:JSX.Element|null; //操作反馈 tipContent:JSX.Element|null; page?:PageProps; }>{ constructor(props: Readonly) { super(props); this.state={ tipContent: null, dialog:null } } /** * 修改密码 */ private modifyPwd(managerId:string,password:string) { let that=this request(API.account.update,Method.POST, { managerId:managerId, password:password },new EmptyBodyTransform(),function (res:JSONResponse) { switch (res.customResult) { case SimpleMessage.ok: that.setState({ tipContent:

密码修改成功

, dialog:null }) break case SimpleMessage.fail: that.setState({ tipContent:

密码修改失败

}) break } }) } /** * 加载管理员数据 */ loadManager(page:number){ let that=this request(API.account.list,Method.GET,{ currentPage:page+"" },new ManagerTransform(),function (res:ManagerList) { switch (res.customResult) { case PageDataMessage.ok: that.setState({ managerList:res.dataList, page: res.page }) break case PageDataMessage.fail: that.setState({ tipContent:

加载数据失败,请联系管理员

}) break } }) } /** * 检查密码 */ checkPwd(modify:any){ if(modify.password.length>0&&modify.confirmPwd.length>0&&modify.password===modify.confirmPwd){ return { check:true } }else if(modify.confirmPwd.length>0&&modify.confirmPwd.length>0){ return { check:false, invalid:'两次密码输入不一致' } }else if(modify.password.length>0&&modify.confirmPwd.length===0){ return { check:false, invalid: '确认密码为空' } }else{ return { check:undefined } } } componentDidMount() { this.loadManager(1) } render() { return ( {this.state.managerList? this.state.managerList.map((manager:ManagerEntity, index:number)=> ) :null }
# 管理员名 操作
{index + 1} {manager.managerId} {this.props.cookies.get(manager_cookie)===manager.managerId?null: }
{this.state.page?this.loadManager(page)} currentPage={this.state.page.currentPage} totalPage={this.state.page.totalPage} pageSize={this.state.page.pageSize}/>:null} {this.state.dialog} this.setState({ tipContent:null })}/>
); } /** * 删除管理员 * @param managerId */ private delete(managerId: string) { let that=this request(API.account.delete+managerId,Method.POST, {},new EmptyBodyTransform(), function (res:JSONResponse) { switch (res.customResult) { case SimpleMessage.ok: that.setState({ tipContent:

删除成功

, }) that.loadManager(1) break case SimpleMessage.fail: that.setState({ tipContent:

删除失败,请联系管理员

, }) break } }) } }