完善我的帮助、我的求助分页逻辑

master
pan 5 years ago
parent 054518bbaa
commit 80b54263b8
  1. 22
      src/my/MyHelp.tsx
  2. 49
      src/my/SeekHelp.tsx
  3. 9
      src/result.ts

@ -5,11 +5,12 @@ import moment from "moment";
import {JSONResponse, Method, request} from "../interface"; import {JSONResponse, Method, request} from "../interface";
import {EmptyBodyTransform, HelpRes, HelpTransform, PageDataMessage, SimpleMessage} from "../result"; import {EmptyBodyTransform, HelpRes, HelpTransform, PageDataMessage, SimpleMessage} from "../result";
import {MyDialog} from "../ui/MyDialog"; import {MyDialog} from "../ui/MyDialog";
import {changeActivity} from "../public"; import {changeActivity, scrollBottom} from "../public";
import {Input} from "../ui/InputGroup"; import {Input} from "../ui/InputGroup";
import {Cookies} from "react-cookie"; import {Cookies} from "react-cookie";
import {time_score} from "../account/PropCookie"; import {time_score} from "../account/PropCookie";
import {Api, prefix} from "../api"; import {Api, prefix} from "../api";
import {SimpleSnackbar} from "../ui/toast";
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"
@ -24,12 +25,14 @@ export class MyHelp extends React.Component<{
{ {
data?:Array<HelpEntity>, data?:Array<HelpEntity>,
page?:PageProps ,
result:JSX.Element|null, result:JSX.Element|null,
//活动评价 //活动评价
activeScore:number, activeScore:number,
historyId:number|null; historyId:number|null;
timeScore?:string; timeScore?:string;
//分页信息
page?:PageProps;
scrollTip:string|null
}>{ }>{
@ -39,7 +42,8 @@ export class MyHelp extends React.Component<{
this.state= { this.state= {
activeScore: 5, activeScore: 5,
result:null, result:null,
historyId:null historyId:null,
scrollTip:null
} }
} }
@ -133,7 +137,9 @@ export class MyHelp extends React.Component<{
switch (res.customResult) { switch (res.customResult) {
case PageDataMessage.ok: case PageDataMessage.ok:
that.setState({ that.setState({
data:res.dataList data: (that.state.data||[]).concat(res.dataList||[]),
page: res.page,
scrollTip: page > 1 ? '成功加载第' + page + '页数据' : null,
}) })
break break
case PageDataMessage.fail: case PageDataMessage.fail:
@ -146,8 +152,11 @@ export class MyHelp extends React.Component<{
} }
render() { render() {
let that=this
return ( return (
<div className="overflow-auto my-help-height w-100"> <div className="overflow-auto my-help-height w-100" onScroll={event => scrollBottom(event,this,function () {
that.loadMyHelp((that.state.page?.currentPage||1)+1)
})}>
{this.state.data?this.state.data.length===0?<h3 className="text-info text-center"></h3>:this.state.data.map((help:HelpEntity,index:number)=> {this.state.data?this.state.data.length===0?<h3 className="text-info text-center"></h3>:this.state.data.map((help:HelpEntity,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>
@ -215,6 +224,9 @@ export class MyHelp extends React.Component<{
<Button variant={"info"} block={true} className="col-3 ml-auto mr-auto mt-3" onClick={()=>this.score()}></Button> <Button variant={"info"} block={true} className="col-3 ml-auto mr-auto mt-3" onClick={()=>this.score()}></Button>
</div>} open={this.state.historyId!==null} titleId="score-dialog" menuName="评分" onClose={()=>this.setState({historyId:null})}/> </div>} open={this.state.historyId!==null} titleId="score-dialog" menuName="评分" onClose={()=>this.setState({historyId:null})}/>
{this.state.scrollTip!==null?<SimpleSnackbar message={this.state.scrollTip} onClose={()=>this.setState({scrollTip:null})} duration={1000}/>:null}
</div> </div>
) )
} }

@ -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 {ActivityStatus, SeekHelpState, User} from "../entity"; import {ActivityStatus, PageProps, 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";
@ -9,9 +9,17 @@ import Draggable from "react-draggable";
import {MyDialog} from "../ui/MyDialog"; import {MyDialog} from "../ui/MyDialog";
import {MyInfo} from "./MyInfo"; import {MyInfo} from "./MyInfo";
import {Method, request} from "../interface"; import {Method, request} from "../interface";
import {SeekHelpInfoRes, SeekHelpInfoTransform, SeekHelpUser, SeekHelpUserTransform, SimpleMessage} from "../result"; import {
import {getStatus} from "../public"; PageDataMessage,
SeekHelpInfoRes,
SeekHelpInfoTransform,
SeekHelpUser,
SeekHelpUserTransform,
SimpleMessage
} from "../result";
import {getStatus, scrollBottom} from "../public";
import {Api, prefix} from "../api"; import {Api, prefix} from "../api";
import {SimpleSnackbar} from "../ui/toast";
const titleId="seek-help-dialog" const titleId="seek-help-dialog"
@ -34,6 +42,9 @@ export class SeekHelp extends React.Component<{ user:string },
userId?:string; userId?:string;
//操作反馈弹窗 //操作反馈弹窗
result:JSX.Element|null; result:JSX.Element|null;
//分页信息
page?:PageProps;
scrollTip:string|null
}>{ }>{
@ -44,30 +55,35 @@ export class SeekHelp extends React.Component<{ user:string },
data:[], data:[],
open:false, open:false,
openUserInfo:false, openUserInfo:false,
result:null result:null,
scrollTip:null
} }
} }
componentDidMount() { componentDidMount() {
this.loadHelp() this.loadHelp(1)
} }
/** /**
* *
*/ */
loadHelp(){ loadHelp(page:number){
let that=this let that=this
request(Api.main.activity.seekHelp,Method.GET, {},new SeekHelpInfoTransform(),function (res:SeekHelpInfoRes) { request(Api.main.activity.seekHelp,Method.GET, {
currentPage:String(page)
},new SeekHelpInfoTransform(),function (res:SeekHelpInfoRes) {
switch (res.customResult) { switch (res.customResult) {
case SimpleMessage.fail: case PageDataMessage.ok:
that.setState({ that.setState({
result:<h3 className="text-danger text-center"></h3> data: (that.state.data||[]).concat(res.dataList||[]),
}); page: res.page,
scrollTip: page > 1 ? '成功加载第' + page + '页数据' : null,
})
break break
case SimpleMessage.ok: case PageDataMessage.fail:
that.setState({ that.setState({
data:res.dataList result:<h3 className="text-danger text-center"></h3>
}) });
break break
} }
}) })
@ -102,8 +118,11 @@ export class SeekHelp extends React.Component<{ user:string },
render() { render() {
let that=this
return ( return (
<div className="overflow-auto seek-help-height w-100"> <div className="overflow-auto seek-help-height w-100" onScroll={event => scrollBottom(event,this,function () {
that.loadHelp((that.state.page?.currentPage||1)+1)
})}>
{this.state.data?this.state.data.length===0?<h3 className="text-info text-center"></h3>:this.state.data.map((help:SeekHelpState, index:number)=> {this.state.data?this.state.data.length===0?<h3 className="text-info text-center"></h3>: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>
@ -158,6 +177,8 @@ export class SeekHelp extends React.Component<{ user:string },
<MyDialog content={this.state.result} open={this.state.result!==null} titleId="seek-help-dialog" <MyDialog content={this.state.result} open={this.state.result!==null} titleId="seek-help-dialog"
menuName="求助信息提示" onClose={()=>this.setState({result:null})} /> menuName="求助信息提示" onClose={()=>this.setState({result:null})} />
{this.state.scrollTip!==null?<SimpleSnackbar message={this.state.scrollTip} onClose={()=>this.setState({scrollTip:null})} duration={1000}/>:null}
</div> </div>
) )
} }

@ -200,22 +200,17 @@ export class ModifyPwdTransform extends EmptyBodyDiffMsg<ModifyPwdMessage>{
} }
export class SeekHelpInfoRes extends JSONResponse<SimpleMessage>{ export class SeekHelpInfoRes extends PageDataRes{
dataList?:Array<SeekHelpState> dataList?:Array<SeekHelpState>
} }
/** /**
* *
*/ */
export class SeekHelpInfoTransform extends TransformData<SimpleMessage, SeekHelpInfoRes>{ export class SeekHelpInfoTransform extends PageDataTransform<SeekHelpInfoRes>{
protected newObject(): SeekHelpInfoRes { protected newObject(): SeekHelpInfoRes {
return new SeekHelpInfoRes(); return new SeekHelpInfoRes();
} }
protected transformBody(data: any) {
this.target.dataList=data.body
}
} }
export class SeekHelpUser extends JSONResponse<SimpleMessage>{ export class SeekHelpUser extends JSONResponse<SimpleMessage>{

Loading…
Cancel
Save