对接服务端

1.个人信息-我的求助
master
pan 5 years ago
parent 372531e0c3
commit ad8d70634b
  1. 6
      src/Main.tsx
  2. 2
      src/account/Register.tsx
  3. 22
      src/entity.ts
  4. 2
      src/index.css
  5. 8
      src/interface.ts
  6. 2
      src/my/MyHelp.tsx
  7. 17
      src/my/MyInfo.tsx
  8. 8
      src/my/MyMessage.tsx
  9. 120
      src/my/SeekHelp.tsx
  10. 43
      src/result.ts
  11. 4
      src/sub/IndexMenu.tsx
  12. 14
      src/sub/Volunteer.tsx

@ -147,11 +147,7 @@ export class Main extends React.Component<
break; break;
case DialogType.message: case DialogType.message:
this.setState({ this.setState({
my:{menuName:dialogType,content:<MyMessage onUserUpdate={(user:User)=>{ my:{menuName:dialogType,content:<MyMessage cookies={this.props.cookies} user={this.props.cookies.get(user_cookie)}/>,open:true}
this.setState({userType:user.userType})
this.props.cookies.set(user_type_cookie,user.userType)
}}
user={this.props.cookies.get(user_cookie)}/>,open:true}
}) })
break; break;
} }

@ -166,7 +166,7 @@ export class Register extends React.Component<RegisterProps, RegisterState>{
<Address value={this.state.serviceAddress} onChange={(value:string)=>this.setState({serviceAddress:value})}/> <Address value={this.state.serviceAddress} onChange={(value:string)=>this.setState({serviceAddress:value})}/>
<Input col={4} name="userType" desc="用户身份" as="select" onChange={(value:string)=>this.setState({userType: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.seekHelp}></option>,<option key={"userType2"} value={UserType.help}></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()}}/>

@ -91,13 +91,13 @@ export interface MyHelpState extends ActivityDetail{
//我的求助信息 //我的求助信息
export interface SeekHelpState extends BaseHelp,ActivityId{ export interface SeekHelpState extends BaseHelp,ActivityId{
//求助时间 //求助时间
time:number; seekHelpTime:number;
//活动报名志愿者 //报名人数
applyVolunteerList:Array<User>; apply:number;
//活动参加志愿者 //参加人数
joinVolunteerList:Array<User>; join:number;
//活动完成志愿者 //完成人数
completeVolunteerList:Array<User>; complete:number;
} }
@ -241,7 +241,9 @@ export interface UserEdit{
newPassword:string; newPassword:string;
//确认新密码 //确认新密码
confirmNewPwd:string; confirmNewPwd:string;
result:JSX.Element|null result:JSX.Element|null;
//缓存用户身份
oldUserType?:String;
} }
@ -337,9 +339,9 @@ export interface LoginState{
} }
/** /**
* *
*/ */
export enum VolunteerStatus { export enum ActivityStatus {
apply = "apply", apply = "apply",
join = "join", join = "join",
complete = "complete" complete = "complete"

@ -110,7 +110,7 @@
} }
/** /**
*求助信息高 *求助信息
*/ */
.seek-help-height{ .seek-help-height{
height: 400px; height: 400px;

@ -19,7 +19,7 @@ export const API={
//更新 //更新
update:prefix.user+"/update", update:prefix.user+"/update",
//更新密码 //更新密码
updatePwd:prefix.user+"/updatePwd" updatePwd:prefix.user+"/updatePwd",
}, },
main:{ main:{
activity: { activity: {
@ -28,7 +28,11 @@ export const API={
//查找活动列表 //查找活动列表
find: prefix.activity + "/find", find: prefix.activity + "/find",
//报名活动 //报名活动
apply:prefix.activity+ "/apply" apply:prefix.activity+ "/apply",
//求助信息统计
seekHelp:prefix.activity+"/seekHelp",
//求助信息志愿者
seekHelpUser:prefix.activity+"/seekHelpUser"
} }
} }
} }

@ -7,7 +7,7 @@ import {myActivityObj} from "../ui/TestData";
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 }, { data:Array<MyHelpState> }>{ export class MyHelp extends React.Component<{ undefined?:undefined }, { data:Array<MyHelpState> }>{

@ -13,6 +13,8 @@ import {
} from "../result"; } from "../result";
import {MyDialog} from "../ui/MyDialog"; import {MyDialog} from "../ui/MyDialog";
import {Address} from "../ui/Address"; import {Address} from "../ui/Address";
import {Cookies} from "react-cookie";
import {user_type_cookie} from "../account/PropCookie";
/** /**
* *
@ -23,7 +25,7 @@ export class MyInfo extends React.Component<
isOwn:boolean; isOwn:boolean;
isMyFriend:boolean; isMyFriend:boolean;
isAdd:boolean; isAdd:boolean;
onUserUpdate?:Function; cookies?:Cookies;
}, UserEdit>{ }, UserEdit>{
private ages:Array<number> private ages:Array<number>
@ -76,7 +78,8 @@ export class MyInfo extends React.Component<
serviceAddress:res.info?.serviceAddress, serviceAddress:res.info?.serviceAddress,
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
});break });break
} }
@ -145,7 +148,10 @@ export class MyInfo extends React.Component<
}) })
let that=this let that=this
let isUpdateUserType=this.state.userType!==this.state.oldUserType
if(isUpdateUserType&&this.props.cookies){
this.props.cookies.set(user_type_cookie,this.state.userType)
}
request(API.account.update,Method.POST, { request(API.account.update,Method.POST, {
headImg:this.state.headImg||"", headImg:this.state.headImg||"",
name:this.state.name||"", name:this.state.name||"",
@ -166,7 +172,10 @@ export class MyInfo extends React.Component<
that.loadInfo(); that.loadInfo();
//TODO 更新用户身份 //TODO 更新用户身份
that.setState({ that.setState({
result:<h3 className="text-info text-center"></h3> result:<div className="text-center">
<h3 className="text-info text-center"></h3>
{isUpdateUserType?<Button variant={"info"} onClick={()=>window.location.reload()}></Button>:null}
</div>
}) })
break break
} }

@ -3,7 +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"; import {Cookies} from "react-cookie";
enum Menu { enum Menu {
info="个人信息", info="个人信息",
@ -14,7 +14,7 @@ enum Menu {
/** /**
* *
*/ */
export class MyMessage extends React.Component<{ user:string,onUserUpdate:Function }, { subMenu:Menu,page:JSX.Element }>{ export class MyMessage extends React.Component<{ user:string,cookies:Cookies }, { subMenu:Menu,page:JSX.Element }>{
constructor(props: Readonly<any>) { constructor(props: Readonly<any>) {
@ -22,7 +22,7 @@ export class MyMessage extends React.Component<{ user:string,onUserUpdate:Functi
this.state={ this.state={
subMenu:Menu.info, subMenu:Menu.info,
page:<MyInfo onUserUpdate={(user:User)=>this.props.onUserUpdate(user)} userId={this.props.user} isMyFriend={false} isOwn={true} isAdd={false}/> page:<MyInfo cookies={this.props.cookies} userId={this.props.user} isMyFriend={false} isOwn={true} isAdd={false}/>
} }
} }
@ -31,7 +31,7 @@ export class MyMessage extends React.Component<{ user:string,onUserUpdate:Functi
this.setState({subMenu:menu}) this.setState({subMenu:menu})
switch (menu) { switch (menu) {
case Menu.info: case Menu.info:
this.setState({page:<MyInfo onUserUpdate={(user:User)=>this.props.onUserUpdate(user)} userId={this.props.user} isMyFriend={false} isOwn={true} isAdd={false}/>}) this.setState({page:<MyInfo cookies={this.props.cookies} userId={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/>})

@ -1,6 +1,6 @@
import React from "react"; import React from "react";
import {Button, ButtonGroup, Col, Container, Image, ListGroup, Row} from "react-bootstrap"; import {Button, ButtonGroup, Col, Container, Image, ListGroup, Row} from "react-bootstrap";
import {SeekHelpState, User, VolunteerStatus} from "../entity"; import {ActivityStatus, SeekHelpState, User} from "../entity";
import moment from "moment"; import moment from "moment";
import Dialog from "@material-ui/core/Dialog"; import Dialog from "@material-ui/core/Dialog";
import {CloseDialog} from "../ui/CloseDialog"; import {CloseDialog} from "../ui/CloseDialog";
@ -8,21 +8,30 @@ import {Paper, Tooltip} from "@material-ui/core";
import Draggable from "react-draggable"; import Draggable from "react-draggable";
import {MyDialog} from "../ui/MyDialog"; import {MyDialog} from "../ui/MyDialog";
import {MyInfo} from "./MyInfo"; import {MyInfo} from "./MyInfo";
import {userObj} from "../ui/TestData"; import {API, Method, prefix, request} from "../interface";
import {SeekHelpInfoRes, SeekHelpInfoTransform, SeekHelpUser, SeekHelpUserTransform, SimpleMessage} from "../result";
const titleId="seek-help-dialog" const titleId="seek-help-dialog"
/** /**
* *
*/ */
export class SeekHelp extends React.Component<{ user:string }, export class SeekHelp extends React.Component<{ user:string },
{ {
data:Array<SeekHelpState>; //求助信息
data?:Array<SeekHelpState>;
//志愿者列表弹框打开状态
open:boolean; open:boolean;
//筛选的活动状态
status?:string; status?:string;
//志愿者列表
volunteerList?:Array<User>; volunteerList?:Array<User>;
//打开用户信息弹框
openUserInfo:boolean; openUserInfo:boolean;
//查看用户信息用户id
userId?:string; userId?:string;
//操作反馈弹窗
result:JSX.Element|null;
}>{ }>{
@ -32,7 +41,8 @@ export class SeekHelp extends React.Component<{ user:string },
this.state={ this.state={
data:[], data:[],
open:false, open:false,
openUserInfo:false openUserInfo:false,
result:null
} }
} }
@ -44,63 +54,64 @@ export class SeekHelp extends React.Component<{ user:string },
* *
*/ */
loadHelp(){ loadHelp(){
this.setState({data:[ let that=this
{ request(API.main.activity.seekHelp,Method.GET, {},new SeekHelpInfoTransform(),function (res:SeekHelpInfoRes) {
applyVolunteerList: [userObj,userObj], switch (res.customResult) {
completeVolunteerList: [], case SimpleMessage.fail:
joinVolunteerList: [], that.setState({
activityImg: "logo512.png", result:<h3 className="text-danger text-center"></h3>
content: "活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容", });
time: new Date().getTime(), break
title:"活动标题", case SimpleMessage.ok:
//活动Id console.debug("求助信息"+res.dataList)
activityId:123, that.setState({
}, data:res.dataList
{ })
applyVolunteerList: [], }
completeVolunteerList: [], })
joinVolunteerList: [],
activityImg: "logo512.png",
content: "活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容",
time: new Date().getTime(),
title:"活动标题",
//活动Id
activityId:123,
},
{
applyVolunteerList: [],
completeVolunteerList: [],
joinVolunteerList: [],
activityImg: "logo512.png",
content: "活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容活动内容",
time: new Date().getTime(),
title:"活动标题",
//活动Id
activityId:123,
}
]})
console.debug(this.state) }
//打开志愿者列表
openVolunteerList(activityId:number,status:ActivityStatus){
let that=this
request(API.main.activity.seekHelpUser+"?activityId="+activityId+"&activityStatus="+status,Method.GET,{},
new SeekHelpUserTransform(),function (res:SeekHelpUser) {
switch (res.customResult) {
case SimpleMessage.fail:
that.setState({
result:<h3 className="text-danger text-center"></h3>
});
break
case SimpleMessage.ok:
that.setState({
volunteerList:res.dataList,
open:true,
status:that.getStatus(status)
})
break
}
})
} }
getStatus(status:VolunteerStatus){ //活动状态转换
getStatus(status:ActivityStatus){
switch (status) { switch (status) {
case VolunteerStatus.apply:return "报名" case ActivityStatus.apply:return "报名"
case VolunteerStatus.join:return "参加" case ActivityStatus.join:return "参与"
case VolunteerStatus.complete:return "完成" case ActivityStatus.complete:return "完成"
} }
} }
render() { render() {
return ( return (
<div className="overflow-auto seek-help-height"> <div className="overflow-auto seek-help-height w-100">
{this.state.data.map((help:SeekHelpState, index:number)=> {this.state.data?this.state.data.map((help:SeekHelpState, index:number)=>
<div key={"list"+index} className="mt-3 mb-3 border-info border"> <div key={"list"+index} className="mt-3 mb-3 border-info border">
<Container> <Container>
<Row> <Row>
<Col xs={4}> <Col xs={4}>
<Image src={help.activityImg} className="activityImage"/> <Image src={help.activityImg?prefix.image+help.activityImg:""} className="activityImage"/>
</Col> </Col>
<Col> <Col>
<h5>{help.title}</h5> <h5>{help.title}</h5>
@ -109,20 +120,20 @@ export class SeekHelp extends React.Component<{ user:string },
</Row> </Row>
<Row> <Row>
<Col xs={4} className="mt-auto mb-auto"> <Col xs={4} className="mt-auto mb-auto">
<span>{moment(help.time).format("YYYY-MM-DD HH:mm:ss")}</span> <span>{moment(help.seekHelpTime).format("YYYY-MM-DD HH:mm:ss")}</span>
</Col> </Col>
<Col> <Col>
<ButtonGroup> <ButtonGroup>
<Button variant={"primary"} disabled={help.applyVolunteerList.length===0} onClick={()=>this.setState({open:true,status:this.getStatus(VolunteerStatus.apply),volunteerList:help.applyVolunteerList})}>:{help.applyVolunteerList.length}</Button> <Button variant={"primary"} disabled={help.apply===0} onClick={()=>this.openVolunteerList(help.activityId,ActivityStatus.apply)}>:{help.apply}</Button>
<Button variant={"success"} disabled={help.joinVolunteerList.length===0} onClick={()=>this.setState({open:true,status:this.getStatus(VolunteerStatus.join),volunteerList:help.joinVolunteerList})}>:{help.joinVolunteerList.length}</Button> <Button variant={"success"} disabled={help.join===0} onClick={()=>this.openVolunteerList(help.activityId,ActivityStatus.join)}>:{help.join}</Button>
<Button variant={"light"} disabled={help.completeVolunteerList.length===0} onClick={()=>this.setState({open:true,status:this.getStatus(VolunteerStatus.complete),volunteerList:help.completeVolunteerList})}>:{help.completeVolunteerList.length}</Button> <Button variant={"light"} disabled={help.complete===0} onClick={()=>this.openVolunteerList(help.activityId,ActivityStatus.complete)}>:{help.complete}</Button>
</ButtonGroup> </ButtonGroup>
</Col> </Col>
</Row> </Row>
</Container> </Container>
</div> </div>
)} ):null}
<Dialog hideBackdrop={true} open={this.state.open} <Dialog hideBackdrop={true} open={this.state.open}
PaperComponent={(props)=> PaperComponent={(props)=>
@ -146,6 +157,9 @@ export class SeekHelp extends React.Component<{ user:string },
<MyDialog titleId="view-user" menuName="用户信息" <MyDialog titleId="view-user" menuName="用户信息"
content={<MyInfo isOwn={false} isMyFriend={false} isAdd={true} userId={this.state.userId?this.state.userId:""}/>} content={<MyInfo isOwn={false} isMyFriend={false} isAdd={true} userId={this.state.userId?this.state.userId:""}/>}
open={this.state.openUserInfo} onClose={()=>this.setState({openUserInfo:false})}/> open={this.state.openUserInfo} onClose={()=>this.setState({openUserInfo:false})}/>
<MyDialog content={this.state.result} open={this.state.result!==null} titleId="seek-help-dialog"
menuName="求助信息提示" onClose={()=>this.setState({result:null})} />
</div> </div>
) )
} }

@ -2,7 +2,7 @@
* *
*/ */
import {JSONResponse, Result, TransformData} from "./interface"; import {JSONResponse, Result, TransformData} from "./interface";
import {ActivityDetail, PageProps, User, UserEdit, UserType} from "./entity"; import {ActivityDetail, PageProps, SeekHelpState, User, UserEdit, UserType} from "./entity";
/** /**
* body响应 * body响应
@ -160,7 +160,7 @@ export class FindUserTransform extends PageDataTransform<FindUserRes>{
export class ActivityDetailRes extends JSONResponse<SimpleMessage>{ export class ActivityDetailRes extends JSONResponse<SimpleMessage>{
activity?:ActivityDetail activity?:ActivityDetail
} }
//活动详情转换
export class ActivityDetailTransform extends TransformData<SimpleMessage, ActivityDetailRes>{ export class ActivityDetailTransform extends TransformData<SimpleMessage, ActivityDetailRes>{
protected newObject(): ActivityDetailRes { protected newObject(): ActivityDetailRes {
return new ActivityDetailRes(); return new ActivityDetailRes();
@ -174,7 +174,7 @@ export class ActivityDetailTransform extends TransformData<SimpleMessage, Activi
export class FindUserInfo extends JSONResponse<SimpleMessage>{ export class FindUserInfo extends JSONResponse<SimpleMessage>{
info?:UserEdit info?:UserEdit
} }
//查找用户信息转换
export class FindUserInfoTransform extends TransformData<SimpleMessage, FindUserInfo>{ export class FindUserInfoTransform extends TransformData<SimpleMessage, FindUserInfo>{
protected newObject(): FindUserInfo { protected newObject(): FindUserInfo {
return new FindUserInfo(); return new FindUserInfo();
@ -192,13 +192,50 @@ export enum ModifyPwdMessage {
fail='fail' fail='fail'
} }
/**
*
*/
export class ModifyPwdTransform extends EmptyBodyDiffMsg<ModifyPwdMessage>{ export class ModifyPwdTransform extends EmptyBodyDiffMsg<ModifyPwdMessage>{
protected newObject(): JSONResponse<ModifyPwdMessage> { protected newObject(): JSONResponse<ModifyPwdMessage> {
return new JSONResponse<ModifyPwdMessage>(); return new JSONResponse<ModifyPwdMessage>();
} }
}
export class SeekHelpInfoRes extends JSONResponse<SimpleMessage>{
dataList?:Array<SeekHelpState>
}
/**
*
*/
export class SeekHelpInfoTransform extends TransformData<SimpleMessage, SeekHelpInfoRes>{
protected newObject(): SeekHelpInfoRes {
return new SeekHelpInfoRes();
}
protected transformBody(data: any) {
this.target.dataList=data.body
}
} }
export class SeekHelpUser extends JSONResponse<SimpleMessage>{
dataList?:Array<User>
}
/**
*
*/
export class SeekHelpUserTransform extends TransformData<SimpleMessage, SeekHelpUser>{
protected newObject(): SeekHelpUser {
return new SeekHelpUser();
}
protected transformBody(data: any) {
this.target.dataList=data.body
}
}

@ -2,7 +2,7 @@ import React from "react";
import {Button, Card, Col, Container, Image, ListGroup, Row} from "react-bootstrap"; import {Button, Card, Col, Container, Image, ListGroup, Row} from "react-bootstrap";
import {Page} from "../ui/Page"; import {Page} from "../ui/Page";
import {ActivityDetail, PageProps, UserType, VolunteerStatus} from "../entity"; import {ActivityDetail, ActivityStatus, PageProps, UserType} from "../entity";
import {MyDialog} from "../ui/MyDialog"; import {MyDialog} from "../ui/MyDialog";
import {Activity} from "../ui/Activity"; import {Activity} from "../ui/Activity";
import {Input} from "../ui/InputGroup"; import {Input} from "../ui/InputGroup";
@ -63,7 +63,7 @@ export class IndexMenu extends React.Component<{ cookies:Cookies },
request(API.main.activity.apply,Method.POST,{ request(API.main.activity.apply,Method.POST,{
activityId:activityId+"", activityId:activityId+"",
activityStatus:VolunteerStatus.join.toString() activityStatus:ActivityStatus.apply.toString()
},new EmptyBodyTransform(),function (res:JSONResponse<SimpleMessage>) { },new EmptyBodyTransform(),function (res:JSONResponse<SimpleMessage>) {
switch (res.customResult) { switch (res.customResult) {
case SimpleMessage.ok: case SimpleMessage.ok:

@ -84,12 +84,14 @@ export class Volunteer extends React.Component<{ undefined?:undefined },
serviceAddress:this.state.form.serviceAddress serviceAddress:this.state.form.serviceAddress
}})}/> }})}/>
<Address onChange={(value:string)=>this.setState({ <div className="mt-3">
form:{ <Address onChange={(value:string)=>this.setState({
keyword:this.state.form.keyword, form:{
serviceAddress:value keyword:this.state.form.keyword,
} serviceAddress:value
})}/> }
})}/>
</div>
<Button className="col-1 mt-3 mb-3" variant="info" onClick={()=>console.info(this.state.form)}></Button> <Button className="col-1 mt-3 mb-3" variant="info" onClick={()=>console.info(this.state.form)}></Button>

Loading…
Cancel
Save