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

88 lines
3.0 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={{height:window.screen.availHeight+'px'}}>
<div className="container">
<Form>
<Input 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>
<MyDialog content={this.state.tipContent} open={this.state.tipContent!=null} titleId={"login-dialog"}
menuName={"提示"} onClose={()=>this.setState({
tipContent:null
})}/>
</div>
);
}
}