InfiniteLoader滚动加载

author: 闫申申

定义

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

图片展示

InfiniteLoader 滚动加载 - 图1

代码演示

  1. import InfiniteLoader from 'pile/dist/components/infiniteloader'
  2. import PermissionsCard from 'pile/dist/components/permissionsCard'
  3. const _Ringloading = React.createClass({
  4. getInitialState() {
  5. return {
  6. list:[],
  7. totle : 20,
  8. stage : 5,
  9. disSwipe : false,
  10. direction : "top",
  11. swipeSucc : false,
  12. isSwipeIng : false,
  13. checkStateChange : 1
  14. }
  15. },
  16. componentDidMount() { // 计算初始化的高度
  17. let {direction} = this.state
  18. this.setState({
  19. list : this.initInitList(direction)
  20. })
  21. },
  22. initInitList(direction){
  23. let start = 1,
  24. end = 6,
  25. newA = []
  26. for (var i = start; i < end; i++) {
  27. if (direction === "top") {
  28. newA.unshift(i)
  29. }else{
  30. newA.push(i)
  31. }
  32. }
  33. return newA
  34. },
  35. onSwipingBack(){},
  36. onSwipedBack(){
  37. let self = this,
  38. {list,totle,stage,direction} = this.state,
  39. listLen = list.length
  40. setTimeout(function(){
  41. if(!(totle == 0 || (totle > 0 && totle == listLen))){
  42. let i = listLen + 1,
  43. l = i + stage,
  44. newList = list
  45. // 重赋值
  46. for (; i < l; i ++ ) {
  47. if (direction === "top") {
  48. newList.unshift(i)
  49. }else{
  50. newList.push(i)
  51. }
  52. }
  53. // 重置 list
  54. self.setState({
  55. list : newList
  56. })
  57. }
  58. self.setState({
  59. disSwipe : totle <= listLen + stage ? true : false,
  60. swipeSucc : true
  61. })
  62. },1000)
  63. },
  64. changeDir(o){
  65. let {direction} = this.state
  66. if (o === direction) {
  67. return false
  68. }
  69. this.setState({
  70. direction : o,
  71. disSwipe : false,
  72. list : this.initInitList(o),
  73. swipeSucc : false
  74. })
  75. },
  76. changeState(){
  77. this.setState({
  78. checkStateChange :3
  79. })
  80. },
  81. render() {
  82. let {list,totle,disSwipe,direction,swipeSucc,isSwipeIng,checkStateChange} = this.state
  83. return (
  84. <InfiniteLoader
  85. direction={direction}
  86. swipeSucc={swipeSucc}
  87. onSwipingBack={this.onSwipingBack}
  88. onSwipedBack={this.onSwipedBack}
  89. disSwipe={disSwipe}
  90. height={`${document.body.clientHeight}px`}
  91. defaultbackground="#fff"
  92. >
  93. {list.map(function(res,index){
  94. return (
  95. <div key = {index}>
  96. <PermissionsCard
  97. iconHTML={>}
  98. titleHTML = {`微信支付合作商谈 - ${res}`}
  99. messageHTML = "1月12日-1月20日"
  100. labelTitle = "过期未审批"
  101. labelType="fail"
  102. href="javascript:;"
  103. />
  104. </div>
  105. )
  106. })}
  107. </InfiniteLoader>
  108. )
  109. }
  110. })

属性

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

原文: https://didi.github.io/pile.js/docs/2017/08/develop-components-infiniteloader.html