import React from "react"; import {Input} from "../ui/InputGroup"; import {Button, Form} from 'react-bootstrap' import {RegisterProps, RegisterState} from "../entity"; import {JSONResponse, Method, request} from "../interface"; import {API} from "../api"; import {RegisterRes, RegisterTransform} from "../result"; import {MyDialog} from "../ui/MyDialog"; import {register} from '../public' /** * 注册 */ export class Register extends React.Component{ constructor(props: Readonly) { super(props) this.state={ confirmPwd: "", managerId:"", password:"", tipContent:null } } //注册 register(){ let that=this request(API.account.register,Method.POST, { managerId:this.state.managerId, password:this.state.password },new RegisterTransform(),function (res:JSONResponse) { switch (res.customResult) { case RegisterRes.ok: that.setState({ tipContent:

注册成功

}) break case RegisterRes.fail: that.setState({ tipContent:

注册失败,请联系管理员

}) break case RegisterRes.user_repeat: that.setState({ tipContent:

注册失败,账号:{that.state.managerId}已存在

}) break } }) } //检查密码 checkPwd(){ return this.state.confirmPwd.length>0&&this.state.password===this.state.confirmPwd } //检查表单 check(){ return this.isNotEmpty(this.state.managerId,this.state.password) &&this.checkPwd() } //检查是否为空 isNotEmpty(...value:(string | number)[]){ for(let index in value){ if(value[index].toString().length===0){ return false } } return true } render() { return (
{ this.setState({...this.state,...{managerId:value}})}} valid={{check:this.isNotEmpty(this.state.managerId)}}/> {this.setState({password:value})}} valid={{check:this.isNotEmpty(this.state.password)}}/> {this.setState({confirmPwd:value})}} valid={{check:this.checkPwd(), invalid:this.state.confirmPwd.length>0&&this.state.password!==this.state.confirmPwd?"密码和确认密码不一致":"验证失败"}}/>
this.setState({ tipContent:null })}/>
); } }