当前位置: 首页 > 文档资料 > Pile.js 中文文档 >

InfiniteLoader 滚动加载

优质
小牛编辑
129浏览
2023-12-01

定义

滚动加载组件,可选方向(向上滚动、向下滚动)。

图片展示

代码演示


import InfiniteLoader from 'pile/dist/components/infiniteloader'
import PermissionsCard from 'pile/dist/components/permissionsCard'
const _Ringloading = React.createClass({
  getInitialState() {
return {
  list:[],
  totle : 20,
  stage : 5,
  disSwipe : false,
  direction : "top",
  swipeSucc : false,
  isSwipeIng : false,
  checkStateChange : 1
}
  },
  componentDidMount() {  // 计算初始化的高度
let {direction} = this.state
this.setState({
  list : this.initInitList(direction)
})
  },
  initInitList(direction){
let start = 1,
  end = 6,
  newA = []
for (var i = start; i < end; i++) {
  if (direction === "top") {
    newA.unshift(i)
  }else{
    newA.push(i)
  }
}
return newA
  },
  onSwipingBack(){},
  onSwipedBack(){
let self = this,
  {list,totle,stage,direction} = this.state,
  listLen = list.length
setTimeout(function(){
  if(!(totle == 0 || (totle > 0 && totle == listLen))){
    let i = listLen + 1,
      l = i + stage,
      newList = list
    // 重赋值
    for (; i < l; i ++ ) {
      if (direction === "top") {
newList.unshift(i)
      }else{
newList.push(i)
      }
    }
    // 重置 list
    self.setState({
      list : newList
    })
  }
  self.setState({
    disSwipe : totle <= listLen + stage ? true : false,
    swipeSucc : true
  })
},1000)
  },
  changeDir(o){
let {direction} = this.state
if (o === direction) {
  return false
}
this.setState({
  direction : o,
  disSwipe : false,
  list : this.initInitList(o),
  swipeSucc : false
})
  },
  changeState(){
this.setState({
  checkStateChange :3
})
  },
  render() {
let {list,totle,disSwipe,direction,swipeSucc,isSwipeIng,checkStateChange} = this.state
return (
  <InfiniteLoader
    direction={direction}
    swipeSucc={swipeSucc}
    onSwipingBack={this.onSwipingBack}
    onSwipedBack={this.onSwipedBack}
    disSwipe={disSwipe}
    height={`${document.body.clientHeight}px`}
    defaultbackground="#fff"
  >
    {list.map(function(res,index){
      return (
<div key = {index}>
  <PermissionsCard
iconHTML={>}
titleHTML = {`微信支付合作商谈 - ${res}`}
messageHTML = "1月12日-1月20日"
labelTitle = "过期未审批"
labelType="fail"
href="javascript:;"
  />
</div>
      )
    })}
  </InfiniteLoader>    
)
  }
})

属性

参数描述数据类型默认值
direction滚动方向,向上:up,向下:downstringtop
onSwipingBack滚动中回调function
onSwipedBack滚动结束的回调function
disSwipe禁止滚动,true:禁止滚动,false:可以滚动boolfalse
swipeSucc提示加载成功与load切换,true:成功,false:loadboolfalse
defaultbackground默认区域背景颜色string""
dropDownRefreshText下拉刷新时文字提示string"下拉刷新"
dropUpRefreshText上拉刷新时文字提示string"上拉刷新"
loadMoreText加载更多时文字提示string"加载更多"
loosenRefreshText松开刷新时文字提示string"松开刷新"
loadedText加载成功时文字提示string"加载成功"
dataIsNewText无新内容时文字提示string"数据已是最新"
loadingText加载中时文字提示string"加载中..."