From cf0e21530e1e6cab9d9e4badd79c8eb85f685668 Mon Sep 17 00:00:00 2001 From: red-deng-deng <1924913374@qq.com> Date: Fri, 21 Jan 2022 17:11:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E4=B8=AD=E5=BF=83=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E6=95=B0=E6=8D=AE=E8=BF=87=E5=A4=9A=EF=BC=8C=E9=80=A0?= =?UTF-8?q?=E6=88=90=E5=8D=A1=E9=A1=BF=EF=BC=8C=E6=87=92=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/exchangepage/template/main.js | 83 +++++++++++++++++++++---- 1 file changed, 70 insertions(+), 13 deletions(-) diff --git a/src/pages/exchangepage/template/main.js b/src/pages/exchangepage/template/main.js index 4d407f55..9625f31e 100644 --- a/src/pages/exchangepage/template/main.js +++ b/src/pages/exchangepage/template/main.js @@ -31,6 +31,7 @@ export default class mytemplate extends React.Component{ typeList:[{id:-1,title:"全部"}], tabIndex:0, sourceIndex:0, + page:1, typeIndex:0, system_template:[], preview_visible:false, @@ -38,6 +39,7 @@ export default class mytemplate extends React.Component{ top:"", toTopshow:false, toTopFlag:false, + endreq:true, center:"", bottom:"" } @@ -64,7 +66,7 @@ export default class mytemplate extends React.Component{ }) }).catch(err=>{ }); - let data={page:1,limit:10000} + let data={page:1,limit:10} getSystemTemplate(data).then(res=>{ handelResponse(res,(req,msg)=>{ this.setState({system_template:req.data}) @@ -77,9 +79,57 @@ export default class mytemplate extends React.Component{ //监听滚动条滚动事件 this.refs.component.addEventListener('scroll',(event)=>{ let scrolHeight=event.target.scrollTop; - console.log('滚动事件',event); if(scrolHeight>300){ this.setState({toTopFlag:true}); + let isBottom=event.target.scrollHeight-event.target.clientHeight; + if(isBottom==event.target.scrollTop){ + + let endreq=this.state.endreq; + if(endreq){ + let page=this.state.page;//请求 + page=page+1; + console.log(91,this.state); + let data={page:page,limit:10} + if(this.state.sourceIndex==0){//系统模板 + if(this.state.typeIndex>0){ + data.type_id=this.state.typeIndex; + } + let preResult=this.state.system_template; + getSystemTemplate(data).then(res=>{ + handelResponse(res,(req,msg)=>{ + if(req.data.length>0){ + let addres=preResult.concat(req.data) + this.setState({system_template:addres,page:page}) + }else{ + this.setState({endreq:false}); + } + + },(err)=>{ + + }) + }).catch(err=>{ + }); + }else{ + let preResult=this.state.system_template; + getTheme(data).then(res=>{ + handelResponse(res,(req,msg)=>{ + if(req.data.length>0){ + let addres=preResult.concat(req.data) + this.setState({system_template:addres,page:page}) + }else{ + this.setState({endreq:false}); + } + + + },(err)=>{ + + }) + }).catch(err=>{ + }); + } + + } + } }else{ this.setState({toTopFlag:false}); } @@ -98,25 +148,30 @@ export default class mytemplate extends React.Component{ window.location.href= "/#/edittemplate" } typeClick(e){ - this.setState({typeIndex:e}) + this.setState({typeIndex:e,page:1}) if(e == -1)//全部 { - let data={page:1,limit:10000} + let data={page:1,limit:10} getSystemTemplate(data).then(res=>{ handelResponse(res,(req,msg)=>{ console.log(req) - this.setState({system_template:req.data}) + this.setState({system_template:req.data}) + if(req.data.length<10){ + this.setState({endreq:false}); + } },(err)=>{ }) }).catch(err=>{ }); }else{ - let data={type_id:e,page:1,limit:10000} + let data={type_id:e,page:1,limit:10} getSystemTemplate(data).then(res=>{ handelResponse(res,(req,msg)=>{ this.setState({system_template:req.data}) - + if(req.data.length<10){ + this.setState({endreq:false}); + } },(err)=>{ }) @@ -126,14 +181,14 @@ export default class mytemplate extends React.Component{ } } sourceClick(e){ - this.setState({sourceIndex:e}) - + this.setState({sourceIndex:e,page:1,endreq:true}) + if(e == 0) { - let data={page:1,limit:10000} + let data={page:1,limit:10} getSystemTemplate(data).then(res=>{ handelResponse(res,(req,msg)=>{ - console.log(req) + this.setState({system_template:req.data}) },(err)=>{ @@ -143,7 +198,7 @@ export default class mytemplate extends React.Component{ }); } else{ - let data={page:1,limit:10000} + let data={page:1,limit:10} getTheme(data).then(res=>{ handelResponse(res,(req,msg)=>{ this.setState({system_template:req.data}) @@ -353,7 +408,9 @@ export default class mytemplate extends React.Component{ :null } -
到底部了哟,没有了哦
+
+ {this.state.endreq?'正在加载中...':'到底部了哟,没有了哦'} +