diff --git a/src/entity.ts b/src/entity.ts index 703b246..8ee1354 100644 --- a/src/entity.ts +++ b/src/entity.ts @@ -346,3 +346,38 @@ export enum ActivityStatus { join = "join", complete = "complete" } + +/** + * 留言信息 + */ +export interface LeaveWord { + // 留言用户id + userId:string; + // 留言用户姓名 + name:string; + // 留言用户头像 + headImg:string; + // 留言类型 + type:LeaveWordType; + // 活动id + activityId:number|null; + // 留言用户简介 + info:string; + //活动标题 + title:string; + //活动内容 + content:string; +} + +export enum LeaveWordType { + //推荐 + recommend = "recommend", + //报名 + apply = "apply", + //参与 + join = "join", + //完成 + complete = "complete", + //好友验证 + friend = "friend" +} diff --git a/src/interface.ts b/src/interface.ts index 9a5f6c9..0f7991c 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -20,6 +20,8 @@ export const API={ update:prefix.user+"/update", //更新密码 updatePwd:prefix.user+"/updatePwd", + //查看留言 + leaveWord:prefix.user+"/find/leaveWord" }, main:{ activity: { diff --git a/src/my/MyLeaveWord.tsx b/src/my/MyLeaveWord.tsx index 953252c..88079db 100644 --- a/src/my/MyLeaveWord.tsx +++ b/src/my/MyLeaveWord.tsx @@ -1,85 +1,67 @@ import React from "react"; import {Button, Col, Container, Image, Row} from "react-bootstrap"; -import {ActivityDetail, User} from "../entity"; +import {LeaveWord, LeaveWordType} from "../entity"; import {Tooltip} from "@material-ui/core"; import {MyDialog} from "../ui/MyDialog"; import {MyInfo} from "./MyInfo"; import {Activity} from "../ui/Activity"; -import {activityObj, userObj} from "../ui/TestData"; - -enum LeaveWordType { - //推荐 - recommend="recommend", - //报名 - apply="apply", - //参与 - join="join", - //完成 - complete="complete", - //好友验证 - friend="friend" -} - -interface Type1{ - activity:ActivityDetail; - user:User; - type:LeaveWordType; -} - -interface Type2 { - user:User; - type:LeaveWordType; -} +import {API, Method, prefix, request} from "../interface"; +import {LeaveWordRes, LeaveWordTransform, PageDataMessage} from "../result"; /** * 我的留言 */ -export class MyLeaveWord extends React.Component<{ user:string }, +export class MyLeaveWord extends React.Component< { + user:string + }, +{ //留言信息 - data:Array; + data?:Array; //打开用户信息弹框 openUserInfo:boolean; //用户id userId?:string; - //打开活动信息弹框 - openActivity:boolean; //活动详情 - activity?:ActivityDetail; + activityId:number|null, + //加载提示 + result:JSX.Element|null }>{ constructor(props: Readonly) { super(props); - this.state={data:[],openUserInfo:false,openActivity:false} + this.state={ + result:

留言列表加载中

, + activityId: null, + data:[], + openUserInfo:false + } } componentDidMount() { - this.loadLeaveWord() + this.loadLeaveWord(1) } /** * 加载留言 */ - loadLeaveWord(){ - this.setState({ - data:[ - { - user:userObj, - activity:activityObj, - type:LeaveWordType.recommend - }, - { - user:userObj, - activity:activityObj, - type:LeaveWordType.apply - }, - { - user:userObj, - type:LeaveWordType.friend - } - ] + loadLeaveWord(page:number){ + + let that=this + + request(API.account.leaveWord+"?currentPage="+page,Method.GET,{},new LeaveWordTransform(),function (res:LeaveWordRes) { + switch (res.customResult) { + case PageDataMessage.ok: + that.setState({ + data:res.dataList + });break + case PageDataMessage.fail: + that.setState({ + result:

留言列表加载失败

+ }) + } }) } @@ -102,18 +84,18 @@ export class MyLeaveWord extends React.Component<{ user:string }, * @param data * @param index */ - getData(data:Type1|Type2,index:number){ + getData(data:LeaveWord,index:number){ let body - if("activity" in data ){ + if(data.activityId!=null){ body=
-
{data.activity.title}
+
{data.title}
-

{data.activity.content}

+

{data.content}

- +
}else{ @@ -123,7 +105,7 @@ export class MyLeaveWord extends React.Component<{ user:string },
~
-

{data.user.info}

+

{data.info}

@@ -141,12 +123,12 @@ export class MyLeaveWord extends React.Component<{ user:string }, - - {data.user.name} + + {data.name} {data.type===LeaveWordType.friend? - this.setState({openUserInfo:true,userId:data.user.userId})}/> + this.setState({openUserInfo:true,userId:data.userId})}/> :null} {body} @@ -160,14 +142,14 @@ export class MyLeaveWord extends React.Component<{ user:string }, render() { return (
- {this.state.data.map((data,index) =>this.getData(data,index))} + {this.state.data?this.state.data.map((data,index) =>this.getData(data,index)):this.state.result} } open={this.state.openUserInfo} onClose={()=>this.setState({openUserInfo:false})}/> - {this.state.activity?} - open={this.state.openActivity} titleId="view-activity" menuName="活动详情" - onClose={()=>this.setState({activity:undefined,openActivity:false})}/>:null} + } + open={this.state.activityId!=null} titleId="view-activity" menuName="活动详情" + onClose={()=>this.setState({activityId:null})}/>
) } diff --git a/src/result.ts b/src/result.ts index b170de7..5f808d2 100644 --- a/src/result.ts +++ b/src/result.ts @@ -2,7 +2,7 @@ * 返回信息 */ import {JSONResponse, Result, TransformData} from "./interface"; -import {ActivityDetail, PageProps, SeekHelpState, User, UserEdit, UserType} from "./entity"; +import {ActivityDetail, LeaveWord, PageProps, SeekHelpState, User, UserEdit, UserType} from "./entity"; /** * 空body响应 @@ -127,7 +127,6 @@ export abstract class PageDataTransform extends Transform */ export class FindActivityRes extends PageDataRes{ dataList?:Array> - page?:PageProps } /** @@ -145,7 +144,6 @@ export class FindActivityTransform extends PageDataTransform{ */ export class FindUserRes extends PageDataRes{ dataList?:Array> - page?:PageProps } /** @@ -237,5 +235,16 @@ export class SeekHelpUserTransform extends TransformData +} +export class LeaveWordTransform extends PageDataTransform{ + protected newObject(): LeaveWordRes { + return new LeaveWordRes(); + } +} diff --git a/src/sub/IndexMenu.tsx b/src/sub/IndexMenu.tsx index c2c12fb..d9b9289 100644 --- a/src/sub/IndexMenu.tsx +++ b/src/sub/IndexMenu.tsx @@ -7,15 +7,7 @@ import {MyDialog} from "../ui/MyDialog"; import {Activity} from "../ui/Activity"; import {Input} from "../ui/InputGroup"; import {API, JSONResponse, Method, prefix, request} from "../interface"; -import { - ActivityDetailRes, - ActivityDetailTransform, - EmptyBodyTransform, - FindActivityRes, - FindActivityTransform, - PageDataMessage, - SimpleMessage -} from "../result"; +import {EmptyBodyTransform, FindActivityRes, FindActivityTransform, PageDataMessage, SimpleMessage} from "../result"; import {Cookies} from "react-cookie"; import {user_type_cookie} from "../account/PropCookie"; @@ -23,18 +15,16 @@ import {user_type_cookie} from "../account/PropCookie"; * 首页 */ export class IndexMenu extends React.Component<{ cookies:Cookies }, + { //活动数据 activityList?:Array>; //分页信息 page?:PageProps; - //活动 - activity?:ActivityDetail; - //打开活动 - openActivity:boolean; //检索活动标题 title:string; result:JSX.Element|null; + activeId:number|null; }>{ @@ -43,7 +33,8 @@ export class IndexMenu extends React.Component<{ cookies:Cookies }, super(props); this.state={ - result: null,openActivity:false, + activeId: null, + result: null, title:"" } } @@ -79,29 +70,6 @@ export class IndexMenu extends React.Component<{ cookies:Cookies }, }) } - /** - * 查找活动 - * @param activityId - */ - loadActivityWithId(activityId:number){ - console.debug("activityId="+activityId) - - let that=this - request(API.main.activity.find+"/"+activityId,Method.GET,{},new ActivityDetailTransform(),function(res:ActivityDetailRes){ - switch (res.customResult) { - case SimpleMessage.fail: - that.setState({ - result:

活动详情加载失败,请联系管理员

- });break; - case SimpleMessage.ok: - that.setState({ - openActivity:true, - activity:res.activity - });break; - } - }) - } - /** * 加载活动列表 * @param page @@ -152,7 +120,7 @@ export class IndexMenu extends React.Component<{ cookies:Cookies }, - + {this.props.cookies.get(user_type_cookie)===UserType.help?:null} @@ -175,12 +143,12 @@ export class IndexMenu extends React.Component<{ cookies:Cookies }, {this.state.page?this.loadActivity(page)} currentPage={this.state.page.currentPage} totalPage={this.state.page.totalPage} pageSize={this.state.page.pageSize}/>:null} - {this.state.activity?{ + { this.apply(activeId) - this.setState({activity:undefined,openActivity:false}) + this.setState({activeId:null}) }} />} - open={this.state.openActivity} titleId="view-active" menuName="活动详情" - onClose={()=>this.setState({activity:undefined,openActivity:false})}/>:null} + open={this.state.activeId!=null} titleId="view-active" menuName="活动详情" + onClose={()=>this.setState({activeId:null})}/> this.setState({result:null})}/> diff --git a/src/sub/SendHelp.tsx b/src/sub/SendHelp.tsx index 75be812..03c7fb0 100644 --- a/src/sub/SendHelp.tsx +++ b/src/sub/SendHelp.tsx @@ -159,7 +159,9 @@ export class SendHelp extends React.Component<{ onSendActivityOK:Function }, Sen this.setState({activityImgFile:value})} /> {/*服务地点*/} -
this.setState({serviceAddress:value})}/> +
+
this.setState({serviceAddress:value})}/> +
0?"":"d-none")}> diff --git a/src/ui/Activity.tsx b/src/ui/Activity.tsx index 3094ea8..2513c93 100644 --- a/src/ui/Activity.tsx +++ b/src/ui/Activity.tsx @@ -2,14 +2,15 @@ import React from "react"; import {Button, Image} from "react-bootstrap"; import {ActivityDetail} from "../entity"; import moment from "moment"; -import {prefix} from "../interface"; +import {API, Method, prefix, request} from "../interface"; +import {ActivityDetailRes, ActivityDetailTransform, SimpleMessage} from "../result"; /** * 活动信息 */ export class Activity extends React.Component< { - activity:ActivityDetail; + activityId:number|null; /** * 显示报名按钮 */ @@ -18,20 +19,63 @@ export class Activity extends React.Component< * 报名方法 */ applyFunction?:Function; - }, { undefined?:undefined }>{ + }, + { + activity?:ActivityDetail , + result:JSX.Element + }>{ + + + constructor(props: Readonly<{ activityId: number | null; showButton: boolean; applyFunction?: Function }>) { + super(props); + + this.state={ + result:

活动详情加载中

+ } + } + + componentDidMount() { + if(this.props.activityId) { + this.loadActivityWithId() + } + } + + /** + * 查找活动 + */ + loadActivityWithId(){ + let that=this + + request(API.main.activity.find+"/"+this.props.activityId,Method.GET,{},new ActivityDetailTransform(),function(res:ActivityDetailRes){ + switch (res.customResult) { + case SimpleMessage.fail: + that.setState({ + result:

活动详情加载失败,请联系管理员

+ });break; + case SimpleMessage.ok: + that.setState({ + activity:res.activity + });break; + } + }) + } render() { return (
-
- + {this.state.activity? +
+
+ +
+

{this.state.activity.title}

+

{this.state.activity.content}

+
{"活动开始时间:"+moment(this.state.activity.activityStartTime).format("YYYY-MM-DD HH:mm:ss")}
+
{"活动结束时间:"+moment(this.state.activity.activityStartTime).format("YYYY-MM-DD HH:mm:ss")}
+ {this.props.showButton?
:null} +
+ :this.state.result}
-

{this.props.activity.title}

-

{this.props.activity.content}

-
{"活动开始时间:"+moment(this.props.activity.activityStartTime).format("YYYY-MM-DD HH:mm:ss")}
-
{"活动结束时间:"+moment(this.props.activity.activityStartTime).format("YYYY-MM-DD HH:mm:ss")}
- {this.props.showButton?
:null} -
); } }