import React from "react"; import {Dropdown, Nav, Navbar} from "react-bootstrap"; import {IndexMenu} from "./sub/IndexMenu"; import {Volunteer} from "./sub/Volunteer"; import {SendHelp} from "./sub/SendHelp"; import {MyFriend} from "./my/MyFriend"; import {MyDialog} from "./ui/MyDialog"; import {MyLeaveWord} from "./my/MyLeaveWord"; import {MyMessage} from "./my/MyMessage"; import {User, UserType} from "./entity"; import {Cookies} from "react-cookie"; import {time_score, user_cookie, user_type_cookie, welcome_cookie} from "./account/PropCookie"; import {backEnd} from "./api"; /** * 菜单标记 */ enum Menu { index, volunteer, myHelp } /** * 我的弹框菜单列表 */ enum DialogType { friend="我的好友", leaveWord="我的留言", message="个人信息" } /** * 主菜单 */ export class Main extends React.Component< { logout:Function; // cookies:Cookies; }, { //菜单 menu:Menu; //子菜单 subMenu:JSX.Element; friendList:Array; //我的菜单 my:{ menuName:string; content:JSX.Element|null; open:boolean; }, //用户身份 userType:string; //用户时间币 timeScore:number; //用户id userId:string; //显示欢迎信息 result:boolean; //打开个人信息变化提示 changeTip:JSX.Element|null; } >{ constructor(props: Readonly) { super(props); //默认菜单 this.state={ //一级菜单 menu:Menu.index, //二级菜单 subMenu:, //我的好友信息 friendList:[], //我的菜单 my:{menuName: "",content:null,open:false}, result:Boolean(this.props.cookies.get(welcome_cookie)), userType:this.props.cookies.get(user_type_cookie), userId:this.props.cookies.get(user_cookie), timeScore:this.props.cookies.get(time_score), changeTip:null } } //获取菜单名颜色 getMenuColor(menu:Menu){ if(this.state.menu===menu){ return { color:"white", backgroundColor:"blue" } }else{ return { color:"blue", backgroundColor: "white" } } } //切换菜单 changeMenu(menu:Menu){ this.setState({ menu:menu }) switch (menu) { case Menu.index: this.setState({ subMenu: });break; case Menu.volunteer: this.setState({ subMenu: });break; case Menu.myHelp: this.setState({ subMenu:this.onSendActivityOK()}/> });break; } } //活动发布成功 onSendActivityOK(){ this.changeMenu(Menu.index) } /** * 关闭弹窗 */ closeDialog(){ this.setState({ my:{...this.state.my,...{menuName:"",content:null,open:false}}}) console.debug(this.state.my) } /** * 打开弹窗 */ openDialog(dialogType:DialogType){ switch (dialogType) { case DialogType.friend: this.setState({ my:{menuName:dialogType,content:,open:true} }) break; case DialogType.leaveWord: this.setState({ my:{menuName:dialogType,content:,open:true} }) break; case DialogType.message: this.setState({ my:{menuName:dialogType,content: { this.refreshInfo(value) }} cookies={this.props.cookies} user={this.state.userId}/>,open:true} }) break; } } render() { return (
互联网+互助平台 欢迎用户{this.state.userId}登录本系统} open={this.state.result} titleId="login-tip" menuName="登录提示" onClose={()=>{ this.setState({result:false}) this.props.cookies.remove(welcome_cookie) }}/> this.setState({ changeTip:null })}/> {this.state.subMenu}
); } /** * 刷新用户信息 * @param value */ private refreshInfo(value:any) { if('userType' in value) { this.props.cookies.set(user_type_cookie, value.userType) this.setState({ userType:value.userType, changeTip:

已刷新用户身份

}) } if('timeScore' in value){ this.props.cookies.set(time_score,value.timeScore) this.setState({ timeScore:value.timeScore, changeTip:

已刷新时间币

}) } } }