主界面切换身份

master
pan 5 years ago
parent d23bcb2baa
commit 5839a28099
  1. 4
      src/App.tsx
  2. 23
      src/Main.tsx
  3. 14
      src/account/Register.tsx
  4. 4
      src/entity.ts
  5. 16
      src/my/MyInfo.tsx
  6. 7
      src/my/MyMessage.tsx

@ -14,6 +14,7 @@ class App extends React.Component<{ allCookies:any;cookies:Cookies }, { page?:JS
super(props); super(props);
this.state={} this.state={}
} }
componentDidMount() { componentDidMount() {
@ -48,8 +49,9 @@ class App extends React.Component<{ allCookies:any;cookies:Cookies }, { page?:JS
console.debug("user_cookie="+user) console.debug("user_cookie="+user)
this.props.cookies.set(user_cookie,user) this.props.cookies.set(user_cookie,user)
this.setState({ this.setState({
page:<Main user={user} logout={()=>this.logout()}/> page:<Main logout={()=>this.logout()} user={user}/>
}) })
} }

@ -7,7 +7,7 @@ import {MyFriend} from "./my/MyFriend";
import {MyDialog} from "./ui/MyDialog"; import {MyDialog} from "./ui/MyDialog";
import {MyLeaveWord} from "./my/MyLeaveWord"; import {MyLeaveWord} from "./my/MyLeaveWord";
import {MyMessage} from "./my/MyMessage"; import {MyMessage} from "./my/MyMessage";
import {User} from "./entity"; import {User, UserEdit, UserType} from "./entity";
/** /**
* *
@ -30,16 +30,22 @@ enum DialogType {
/** /**
* *
*/ */
export class Main extends React.Component<{ user:string,logout:Function }, export class Main extends React.Component<
{ user:string,userType?:string,logout:Function},
{ {
//菜单
menu:Menu; menu:Menu;
//子菜单
subMenu:JSX.Element; subMenu:JSX.Element;
friendList:Array<User>; friendList:Array<User>;
//我的菜单
my:{ my:{
menuName:string; menuName:string;
content:JSX.Element|null; content:JSX.Element|null;
open:boolean; open:boolean;
} },
//用户身份
userType?:string;
} }
>{ >{
@ -125,12 +131,16 @@ export class Main extends React.Component<{ user:string,logout:Function },
break; break;
case DialogType.message: case DialogType.message:
this.setState({ this.setState({
my:{menuName:dialogType,content:<MyMessage user={this.props.user}/>,open:true} my:{menuName:dialogType,content:<MyMessage onUserUpdate={(user:UserEdit)=>this.setState({userType:user.userType})} user={this.props.user}/>,open:true}
}) })
break; break;
} }
} }
onUserUpdate(user:UserEdit){
console.debug(user)
}
render() { render() {
return ( return (
<div> <div>
@ -159,7 +169,10 @@ export class Main extends React.Component<{ user:string,logout:Function },
</Dropdown.Menu> </Dropdown.Menu>
</Dropdown> </Dropdown>
<Navbar.Brand className="ml-3"></Navbar.Brand>
{(this.state.userType||this.props.userType)?<Navbar.Brand className="ml-3">{(this.state.userType||this.props.userType)===UserType.help.toString()?"等待接受帮助":"等待前往帮助"}</Navbar.Brand>:null}
<MyDialog titleId="my-dialog" menuName={this.state.my.menuName} content={this.state.my.content} open={this.state.my.open} onClose={()=>this.closeDialog()}/> <MyDialog titleId="my-dialog" menuName={this.state.my.menuName} content={this.state.my.content} open={this.state.my.open} onClose={()=>this.closeDialog()}/>
</Nav> </Nav>

@ -69,18 +69,6 @@ export class Register extends React.Component<RegisterProps, RegisterState>{
&&this.state.headImg!==headimgTip&&this.checkPwd()&&this.checkMobile()&&this.checkEmail() &&this.state.headImg!==headimgTip&&this.checkPwd()&&this.checkMobile()&&this.checkEmail()
} }
//解析身份
getType(type:String){
switch (type) {
case UserType.help.toString():
return "帮助信息"
case UserType.seekHelp.toString():
return "求助信息"
}
return ""
}
/** /**
* *
*/ */
@ -120,7 +108,7 @@ export class Register extends React.Component<RegisterProps, RegisterState>{
<Address onChange={(value:string)=>this.setState({address:value})}/> <Address onChange={(value:string)=>this.setState({address:value})}/>
<Input col={4} name="userType" desc="用户身份" as="select" onChange={(value:string)=>this.setState({userType:this.getType(value)})} <Input col={4} name="userType" desc="用户身份" as="select" onChange={(value:string)=>this.setState({userType:value})}
options={[<option value="" key={"userType0"}></option>,<option key={"userType1"} value={UserType.help}></option>,<option key={"userType2"} value={UserType.seekHelp}></option>]}/> options={[<option value="" key={"userType0"}></option>,<option key={"userType1"} value={UserType.help}></option>,<option key={"userType2"} value={UserType.seekHelp}></option>]}/>
<Input col={4} name="mobile" desc="电话" onChange={(value:string)=>this.setState({mobile:+value})} valid={{check:this.checkMobile()}}/> <Input col={4} name="mobile" desc="电话" onChange={(value:string)=>this.setState({mobile:+value})} valid={{check:this.checkMobile()}}/>

@ -167,8 +167,8 @@ export interface MyDialogProps extends CloseDialogProps{
} }
export enum UserType { export enum UserType {
seekHelp, seekHelp="seekHelp",
help help="help"
} }
/** /**

@ -1,6 +1,6 @@
import React from "react"; import React from "react";
import {Button, Col, Container, Form, FormControl, Image, Row} from "react-bootstrap"; import {Button, Col, Container, Form, FormControl, Image, Row} from "react-bootstrap";
import {UserEdit} from "../entity"; import {UserEdit, UserType} from "../entity";
import {Input} from "../ui/InputGroup"; import {Input} from "../ui/InputGroup";
@ -14,6 +14,8 @@ export class MyInfo extends React.Component<
userId?:string; userId?:string;
isMyFriend:boolean; isMyFriend:boolean;
isAdd:boolean; isAdd:boolean;
//更新用户信息回调
onUserUpdate?:Function;
}, UserEdit>{ }, UserEdit>{
@ -61,6 +63,7 @@ export class MyInfo extends React.Component<
email:"admin@qq.com", email:"admin@qq.com",
address:"上海高新区", address:"上海高新区",
info:"个人简介", info:"个人简介",
userType:UserType.help.toString()
}) })
} }
@ -103,6 +106,9 @@ export class MyInfo extends React.Component<
contentEditable:false contentEditable:false
}) })
if(this.props.onUserUpdate) {
this.props.onUserUpdate({userType: this.state.userType})
}
console.debug(this.state) console.debug(this.state)
} }
@ -153,6 +159,14 @@ export class MyInfo extends React.Component<
<FormControl value={this.state.email} onChange={(e)=>this.setState({email:e.target.value})}/> <FormControl value={this.state.email} onChange={(e)=>this.setState({email:e.target.value})}/>
:this.state.email} :this.state.email}
</Col> </Col>
<Col className="border-info border p-3 text-center">
{this.state.contentEditable?
<FormControl value={this.state.userType} as={"select"} onChange={(e)=>this.setState({userType:e.target.value})}>
<option value={UserType.help}></option>
<option value={UserType.seekHelp}></option>
</FormControl>:
this.state.userType===UserType.help?"等待接受帮助":"等待前往帮助"}
</Col>
</Row> </Row>
<Row> <Row>
<Col className="border-info border p-3 text-center"> <Col className="border-info border p-3 text-center">

@ -3,6 +3,7 @@ import {Button, ButtonGroup, Col, Container, Row} from "react-bootstrap";
import {MyInfo} from "./MyInfo"; import {MyInfo} from "./MyInfo";
import {MyHelp} from "./MyHelp"; import {MyHelp} from "./MyHelp";
import {SeekHelp} from "./SeekHelp"; import {SeekHelp} from "./SeekHelp";
import {User} from "../entity";
enum Menu { enum Menu {
info="个人信息", info="个人信息",
@ -13,7 +14,7 @@ enum Menu {
/** /**
* *
*/ */
export class MyMessage extends React.Component<{ user:string }, { subMenu:Menu,page:JSX.Element }>{ export class MyMessage extends React.Component<{ user:string,onUserUpdate:Function }, { subMenu:Menu,page:JSX.Element }>{
constructor(props: Readonly<any>) { constructor(props: Readonly<any>) {
@ -21,7 +22,7 @@ export class MyMessage extends React.Component<{ user:string }, { subMenu:Menu,p
this.state={ this.state={
subMenu:Menu.info, subMenu:Menu.info,
page:<MyInfo ownUserId={this.props.user} isMyFriend={false} isOwn={true} isAdd={false}/> page:<MyInfo onUserUpdate={(user:User)=>this.props.onUserUpdate(user)} ownUserId={this.props.user} isMyFriend={false} isOwn={true} isAdd={false}/>
} }
} }
@ -30,7 +31,7 @@ export class MyMessage extends React.Component<{ user:string }, { subMenu:Menu,p
this.setState({subMenu:menu}) this.setState({subMenu:menu})
switch (menu) { switch (menu) {
case Menu.info: case Menu.info:
this.setState({page:<MyInfo ownUserId={this.props.user} isMyFriend={false} isOwn={true} isAdd={false}/>}) this.setState({page:<MyInfo onUserUpdate={(user:User)=>this.props.onUserUpdate(user)} ownUserId={this.props.user} isMyFriend={false} isOwn={true} isAdd={false}/>})
break break
case Menu.help: case Menu.help:
this.setState({page:<MyHelp/>}) this.setState({page:<MyHelp/>})

Loading…
Cancel
Save