You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
help_admin/src/account/Login.tsx

90 lines
3.5 KiB

import React from "react";
import {Button, Form} from 'react-bootstrap'
import {Input} from "../ui/InputGroup";
import {LoginProps, LoginState} from "../entity";
import {Method, request} from "../interface";
import {API} from "../api";
import {LoginMessage, LoginRes, LoginTransform} from "../result";
import {MyDialog} from "../ui/MyDialog";
/**
* 登陆表单组件
*/
export class Login extends React.Component<LoginProps, LoginState>{
constructor(props: Readonly<LoginProps>) {
super(props)
this.state={
managerId:"",
password:"",
tipContent:null
}
}
//检查是否为空
isNotEmpty(...value:(string | number)[]){
for(let index in value){
if(value[index].toString().length===0){
return false
}
}
return true
}
//登录
login(){
let that=this
request(API.account.login,Method.POST, {
managerId:this.state.managerId,
password:this.state.password
},new LoginTransform(),function (res:LoginRes) {
switch (res.customResult) {
case LoginMessage.ok:
that.props.onLoginSuccess(res)
break
case LoginMessage.valid_fail:
that.setState({
tipContent:<h3 className="text-center text-danger"></h3>
})
break
case LoginMessage.fail:
that.setState({
tipContent:<h3 className="text-center text-danger"></h3>
})
break
}
})
}
render() {
return (
<div className="d-flex align-items-center" style={{backgroundColor:"#FFF8F8",height:"937px",overflow:"hidden"}}>
<div style={{height:300,backgroundColor:"#ffffff",width:"800px",float:"left",overflow:"hidden",marginTop:"-50px",border:"3px solid #ffffff",borderRadius:15,boxShadow:"0 0 10px #939292"}} className="container">
<div style={{float:"left",marginTop:"20px",marginLeft:"270px",color:"#1D45FF",fontFamily:"微软雅黑",fontSize:20}}>+</div>
<div style={{marginTop:70}}>
<Form>
<Input style={{}} name="managerId" type="text" desc="管理员账号" value={this.state.managerId}
onChange={(value: string)=>{this.setState({managerId:value})}} valid={{check:this.state.managerId.length>0}}/>
<Input name="password" type="password" desc="管理员密码" value={this.state.password}
onChange={(value: string)=>{this.setState({password:value})}} valid={{check:this.state.password.length>0}}/>
<Button variant="success" className="mt-3 col-2 mr-3" disabled={!(this.state.managerId.length>0&&this.state.password.length>0)} onClick={()=>this.login()}></Button>
<Button variant="info" className="mt-3 col-2" onClick={()=>this.props.toRegister()}></Button>
</Form>
</div>
</div>
<MyDialog content={this.state.tipContent} open={this.state.tipContent!=null} titleId={"login-dialog"}
menuName={"提示"} onClose={()=>this.setState({
tipContent:null
})}/>
</div>
);
}
}