完成活动或者从个人信息修改用户身份时,分别刷新时间币和用户身份

master
pan 5 years ago
parent b7e821a70f
commit 7757aa593d
  1. 40
      src/Main.tsx
  2. 4
      src/entity.ts
  3. 4
      src/interface.ts
  4. 26
      src/my/MyHelp.tsx
  5. 27
      src/my/MyInfo.tsx
  6. 17
      src/my/MyMessage.tsx
  7. 8
      src/public.tsx
  8. 20
      src/result.ts

@ -38,7 +38,6 @@ export class Main extends React.Component<
// //
cookies:Cookies; cookies:Cookies;
}, },
{ {
//菜单 //菜单
menu:Menu; menu:Menu;
@ -52,12 +51,17 @@ export class Main extends React.Component<
open:boolean; open:boolean;
}, },
//用户身份 //用户身份
userType?:string; userType:string;
//用户时间币
timeScore:number;
//用户id
userId:string;
//显示欢迎信息 //显示欢迎信息
result:boolean; result:boolean;
} }
>{ >{
constructor(props: Readonly<any>) { constructor(props: Readonly<any>) {
super(props); super(props);
//默认菜单 //默认菜单
@ -71,7 +75,9 @@ export class Main extends React.Component<
//我的菜单 //我的菜单
my:{menuName: "",content:null,open:false}, my:{menuName: "",content:null,open:false},
result:Boolean(this.props.cookies.get(welcome_cookie)), result:Boolean(this.props.cookies.get(welcome_cookie)),
userType:this.props.cookies.get(user_type_cookie) userType:this.props.cookies.get(user_type_cookie),
userId:this.props.cookies.get(user_cookie),
timeScore:this.props.cookies.get(time_score)
} }
} }
@ -137,17 +143,19 @@ export class Main extends React.Component<
switch (dialogType) { switch (dialogType) {
case DialogType.friend: case DialogType.friend:
this.setState({ this.setState({
my:{menuName:dialogType,content:<MyFriend user={this.props.cookies.get(user_cookie)}/>,open:true} my:{menuName:dialogType,content:<MyFriend user={this.state.userId}/>,open:true}
}) })
break; break;
case DialogType.leaveWord: case DialogType.leaveWord:
this.setState({ this.setState({
my:{menuName:dialogType,content:<MyLeaveWord user={this.props.cookies.get(user_cookie)}/>,open:true} my:{menuName:dialogType,content:<MyLeaveWord user={this.state.userId}/>,open:true}
}) })
break; break;
case DialogType.message: case DialogType.message:
this.setState({ this.setState({
my:{menuName:dialogType,content:<MyMessage cookies={this.props.cookies} user={this.props.cookies.get(user_cookie)}/>,open:true} my:{menuName:dialogType,content:<MyMessage refreshFun={(value:User)=> {
this.refreshInfo(value)
}} cookies={this.props.cookies} user={this.state.userId}/>,open:true}
}) })
break; break;
} }
@ -172,11 +180,11 @@ export class Main extends React.Component<
<Dropdown> <Dropdown>
<Dropdown.Toggle variant="secondary" id="dropdown-basic"> <Dropdown.Toggle variant="secondary" id="dropdown-basic">
{this.props.cookies.get(user_cookie)} {this.state.userId}
</Dropdown.Toggle> </Dropdown.Toggle>
<Dropdown.Menu> <Dropdown.Menu>
<Dropdown.Item>:<span className="text-center text-info">{this.props.cookies.get(time_score)}</span></Dropdown.Item> <Dropdown.Item>:<span className="text-center text-info">{this.state.timeScore}</span></Dropdown.Item>
{[DialogType.friend,DialogType.leaveWord,DialogType.message].map((type:DialogType,index:number)=><Dropdown.Item disabled={this.state.my.open} key={"dropdown"+index} onClick={()=>this.openDialog(type)}>{type}</Dropdown.Item>)} {[DialogType.friend,DialogType.leaveWord,DialogType.message].map((type:DialogType,index:number)=><Dropdown.Item disabled={this.state.my.open} key={"dropdown"+index} onClick={()=>this.openDialog(type)}>{type}</Dropdown.Item>)}
<Dropdown.Item onClick={()=>this.props.logout()}></Dropdown.Item> <Dropdown.Item onClick={()=>this.props.logout()}></Dropdown.Item>
</Dropdown.Menu> </Dropdown.Menu>
@ -191,7 +199,7 @@ export class Main extends React.Component<
</Nav> </Nav>
</Navbar> </Navbar>
<MyDialog content={<h1 className="text-info text-center">{this.props.cookies.get(user_cookie)}</h1>} open={this.state.result} titleId="login-tip" menuName="登录提示" onClose={()=>{ <MyDialog content={<h1 className="text-info text-center">{this.state.userId}</h1>} open={this.state.result} titleId="login-tip" menuName="登录提示" onClose={()=>{
this.setState({result:false}) this.setState({result:false})
this.props.cookies.remove(welcome_cookie) this.props.cookies.remove(welcome_cookie)
}}/> }}/>
@ -200,4 +208,18 @@ export class Main extends React.Component<
</div> </div>
); );
} }
/**
*
* @param value
*/
private refreshInfo(value:any) {
if('userType' in value) {
this.props.cookies.set(user_type_cookie, value.userType)
}
if('timeScore' in value){
this.props.cookies.set(time_score,value.timeScore)
}
this.setState(value)
}
} }

@ -194,6 +194,8 @@ export interface User{
chatStatus?:boolean; chatStatus?:boolean;
//是否我的好友 //是否我的好友
isMyFriend?:boolean; isMyFriend?:boolean;
//时间币
timeScore?:boolean;
} }
/** /**
@ -232,8 +234,6 @@ export interface UserEdit{
newPassword:string; newPassword:string;
//确认新密码 //确认新密码
confirmNewPwd:string; confirmNewPwd:string;
//缓存用户身份
oldUserType?:String;
} }

@ -33,7 +33,9 @@ export const API={
//刷新聊天室状态 //刷新聊天室状态
refreshChat:prefix.user+"/chat/status", refreshChat:prefix.user+"/chat/status",
//查找用户 //查找用户
findUser:prefix.user+"/find/name" findUser:prefix.user+"/find/name",
//查找本人信息
findOwn:prefix.user+"/find/own"
}, },
main:{ main:{
activity: { activity: {

@ -7,13 +7,19 @@ import {EmptyBodyTransform, HelpRes, HelpTransform, PageDataMessage, SimpleMessa
import {MyDialog} from "../ui/MyDialog"; import {MyDialog} from "../ui/MyDialog";
import {changeActivity} from "../public"; import {changeActivity} from "../public";
import {Input} from "../ui/InputGroup"; import {Input} from "../ui/InputGroup";
import {Cookies} from "react-cookie";
import {time_score} from "../account/PropCookie";
const classList="border-info border d-flex justify-content-center align-items-center" const classList="border-info border d-flex justify-content-center align-items-center"
/** /**
* *
*/ */
export class MyHelp extends React.Component<{ undefined?:undefined }, export class MyHelp extends React.Component<{
//刷新用户信息
refreshFun?:Function;
cookies?:Cookies;
},
{ {
data?:Array<HelpEntity>, data?:Array<HelpEntity>,
@ -22,6 +28,7 @@ export class MyHelp extends React.Component<{ undefined?:undefined },
//活动评价 //活动评价
activeScore:number, activeScore:number,
historyId:number|null; historyId:number|null;
timeScore?:string;
}>{ }>{
@ -90,8 +97,12 @@ export class MyHelp extends React.Component<{ undefined?:undefined },
{help.hasEnd?null: {help.hasEnd?null:
<Button className="w-100" onClick={()=>{ <Button className="w-100" onClick={()=>{
let that=this let that=this
changeActivity(help.activityId,ActivityStatus.complete, this,function () { changeActivity(help.activityId,ActivityStatus.complete, this,function (timeScore:string) {
that.setState({
timeScore:timeScore
})
that.loadMyHelp(1) that.loadMyHelp(1)
}) })
}} variant={"info"}></Button>}</Col> }} variant={"info"}></Button>}</Col>
<Col className={classList}/> <Col className={classList}/>
@ -178,9 +189,16 @@ export class MyHelp extends React.Component<{ undefined?:undefined },
</div> </div>
):<h3 className="text-center text-info"></h3>} ):<h3 className="text-center text-info"></h3>}
<MyDialog content={this.state.result} open={this.state.result!==null} titleId="my_help_dialog" menuName="提示" onClose={()=>this.setState({ <MyDialog content={this.state.result} open={this.state.result!==null} titleId="my_help_dialog" menuName="提示" onClose={()=>{
this.setState({
result:null result:null
})}/> })
if(this.props.cookies?.get(time_score)!==this.state.timeScore&&this.props.refreshFun) {
this.props.refreshFun({
timeScore:this.state.timeScore
})
}
}}/>
<MyDialog content={ <MyDialog content={
<div> <div>

@ -21,6 +21,8 @@ import {user_type_cookie} from "../account/PropCookie";
*/ */
export class MyInfo extends React.Component< export class MyInfo extends React.Component<
{ {
//刷新用户信息
refreshFun?:Function,
//查看用户id //查看用户id
userId:string; userId:string;
//查看本人 //查看本人
@ -88,7 +90,6 @@ export class MyInfo extends React.Component<
info:res.info?.info, info:res.info?.info,
userType:res.info?.userType, userType:res.info?.userType,
sex:res.info?.sex, sex:res.info?.sex,
oldUserType:res.info?.userType,
contentEditable:false, contentEditable:false,
modifyPassword:false, modifyPassword:false,
@ -96,7 +97,8 @@ export class MyInfo extends React.Component<
newPassword:"", newPassword:"",
confirmNewPwd:"", confirmNewPwd:"",
} }
});break })
break
} }
}) })
@ -164,10 +166,10 @@ export class MyInfo extends React.Component<
}) })
let that=this let that=this
let isUpdateUserType=this.state.userEdit.userType!==this.state.userEdit.oldUserType // let isUpdateUserType=this.state.userEdit.userType!==this.state.userEdit.oldUserType
if(isUpdateUserType&&this.props.cookies){ // if(isUpdateUserType&&this.props.cookies){
this.props.cookies.set(user_type_cookie,this.state.userEdit.userType) // this.props.cookies.set(user_type_cookie,this.state.userEdit.userType)
} // }
request(API.account.update,Method.POST, { request(API.account.update,Method.POST, {
headImg:this.state.userEdit.headImg||"", headImg:this.state.userEdit.headImg||"",
name:this.state.userEdit.name||"", name:this.state.userEdit.name||"",
@ -187,10 +189,10 @@ export class MyInfo extends React.Component<
case SimpleMessage.ok: case SimpleMessage.ok:
that.loadInfo(); that.loadInfo();
//TODO 更新用户身份 //TODO 更新用户身份
that.setState({ that.setState({
result:<div className="text-center"> result:<div className="text-center">
<h3 className="text-info text-center"></h3> <h3 className="text-info text-center"></h3>
{isUpdateUserType?<Button variant={"info"} onClick={()=>window.location.reload()}></Button>:null}
</div> </div>
}) })
break break
@ -353,9 +355,16 @@ export class MyInfo extends React.Component<
</Row> </Row>
} }
<MyDialog content={this.state.result} open={this.state.result!==null} titleId="myinfo-dialog" menuName="用户提示" onClose={()=>this.setState({ <MyDialog content={this.state.result} open={this.state.result!==null} titleId="myinfo-dialog" menuName="用户提示" onClose={()=>{
this.setState({
result:null result:null
})}/> })
if(this.props.cookies?.get(user_type_cookie)!==this.state.userEdit.userType&&this.props.refreshFun) {
this.props.refreshFun({
userType:this.state.userEdit.userType
})
}
}}/>
</Container> </Container>
) )
} }

@ -14,15 +14,24 @@ enum Menu {
/** /**
* *
*/ */
export class MyMessage extends React.Component<{ user:string,cookies:Cookies }, { subMenu:Menu,page:JSX.Element }>{ export class MyMessage extends React.Component<{
user:string,
cookies:Cookies,
//刷新用户信息
refreshFun?:Function,
}, {
subMenu:Menu,
page:JSX.Element
}>{
private defaultMenu=<MyInfo refreshFun={(value:any)=>this.props.refreshFun?this.props.refreshFun(value):null} cookies={this.props.cookies} userId={this.props.user} isOwn={true} isAdd={false}/>
constructor(props: Readonly<any>) { constructor(props: Readonly<any>) {
super(props); super(props);
this.state={ this.state={
subMenu:Menu.info, subMenu:Menu.info,
page:<MyInfo cookies={this.props.cookies} userId={this.props.user} isOwn={true} isAdd={false}/> page:this.defaultMenu
} }
} }
@ -31,10 +40,10 @@ export class MyMessage extends React.Component<{ user:string,cookies:Cookies },
this.setState({subMenu:menu}) this.setState({subMenu:menu})
switch (menu) { switch (menu) {
case Menu.info: case Menu.info:
this.setState({page:<MyInfo cookies={this.props.cookies} userId={this.props.user} isOwn={true} isAdd={false}/>}) this.setState({page:this.defaultMenu})
break break
case Menu.help: case Menu.help:
this.setState({page:<MyHelp/>}) this.setState({page:<MyHelp cookies={this.props.cookies} refreshFun={(value:any)=>this.props.refreshFun?this.props.refreshFun(value):null}/>})
break break
case Menu.seekHelp: case Menu.seekHelp:
this.setState({page:<SeekHelp user={this.props.user}/>}) this.setState({page:<SeekHelp user={this.props.user}/>})

@ -1,7 +1,7 @@
// 一些组件公用函数 // 一些组件公用函数
import {API, JSONResponse, Method, request} from "./interface"; import {API, Method, request} from "./interface";
import {ActivityStatus} from "./entity"; import {ActivityStatus} from "./entity";
import {EmptyBodyTransform, SimpleMessage} from "./result"; import {ChangeActivityRes, ChangeActivityTransform, SimpleMessage} from "./result";
import React from "react"; import React from "react";
export function changeActivity(activityId:number,activityStatus:ActivityStatus,that:React.Component,callback:Function){ export function changeActivity(activityId:number,activityStatus:ActivityStatus,that:React.Component,callback:Function){
@ -9,10 +9,10 @@ export function changeActivity(activityId:number,activityStatus:ActivityStatus,t
request(API.main.activity.apply,Method.POST,{ request(API.main.activity.apply,Method.POST,{
activityId:activityId+"", activityId:activityId+"",
activityStatus:activityStatus.toString() activityStatus:activityStatus.toString()
},new EmptyBodyTransform(),function (res:JSONResponse<SimpleMessage>) { },new ChangeActivityTransform(),function (res:ChangeActivityRes) {
switch (res.customResult) { switch (res.customResult) {
case SimpleMessage.ok: case SimpleMessage.ok:
callback() callback(res.timeScore)
that.setState({ that.setState({
result:<h3 className="text-info text-center">{getStatus(activityStatus)}</h3> result:<h3 className="text-info text-center">{getStatus(activityStatus)}</h3>
});break });break

@ -275,3 +275,23 @@ export class UserTransform extends PageDataTransform<UserRes>{
} }
} }
/**
*
*/
export class ChangeActivityRes implements JSONResponse<SimpleMessage>{
timeScore?:number;
customResult?:SimpleMessage;
result?: Result;
}
export class ChangeActivityTransform extends TransformData<SimpleMessage, ChangeActivityRes>{
protected newObject(): ChangeActivityRes {
return new ChangeActivityRes();
}
protected transformBody(data: any) {
this.target.timeScore=data.body
}
}

Loading…
Cancel
Save