Square.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="square-container">
  3. <div class="title">全部任务</div>
  4. <div class="square-list-container" v-loading="loading" type="flex" align="middle">
  5. <el-row v-if="list != null && list.length != 0" type="flex" align="middle" justify="center" style="font-size: 14px;">
  6. <el-col :span="5">任务封面</el-col>
  7. <el-col :span="4">任务名称</el-col>
  8. <el-col :span="4">任务类型</el-col>
  9. <el-col :span="4">任务预算</el-col>
  10. <el-col :span="4">领取次数</el-col>
  11. <el-col :span="3">操作</el-col>
  12. </el-row>
  13. <task-item v-if="list!=null&&list.length>0" v-for="(item,index) in list" :key="index" :task="item"/>
  14. <!--<div v-if="loading" class="loading">-->
  15. <!--<span></span>-->
  16. <!--<span></span>-->
  17. <!--<span></span>-->
  18. <!--<span></span>-->
  19. <!--<span></span>-->
  20. <!--<span></span>-->
  21. <!--<span></span>-->
  22. <!--</div>-->
  23. <div v-if="list==null || list.length === 0" class="nomore">暂无任务</div>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. import TaskItem from '@/components/commons/TaskItem'
  29. import Http from '@/js/http.js'
  30. import Apis from '@/js/api.js'
  31. import {notify} from '@/constants/index'
  32. export default {
  33. name: 'Square',
  34. components: {TaskItem},
  35. data () {
  36. return {
  37. loading: true,
  38. nomore: false,
  39. list: [],
  40. }
  41. },
  42. mounted () {
  43. window.addEventListener('scroll', this.throttle(this.setpage, 1000), false)
  44. },
  45. created () {
  46. this.loadData()
  47. },
  48. methods: {
  49. throttle (func, wait, options) {
  50. let context, args, result
  51. let timeout = null
  52. let previous = 0
  53. if (!options) options = {}
  54. let later = function () {
  55. previous = options.leading === false ? 0 : Number(new Date())
  56. timeout = null
  57. result = func.apply(context, args)
  58. if (!timeout) context = args = null
  59. }
  60. return (..._args) => {
  61. let now = Number(new Date())
  62. if (!previous && options.leading === false) previous = now
  63. let remaining = wait - (now - previous)
  64. context = this
  65. args = _args
  66. if (remaining <= 0 || remaining > wait) {
  67. clearTimeout(timeout)
  68. timeout = null
  69. previous = now
  70. result = func.apply(context, args)
  71. if (!timeout) context = args = null
  72. } else if (!timeout && options.trailing !== false) {
  73. timeout = setTimeout(later, remaining)
  74. }
  75. return result
  76. }
  77. },
  78. setpage () {
  79. if (this.nomore && !this.loading) return //到达底部不再执行
  80. var scrollTop =
  81. document.documentElement.scrollTop || document.body.scrollTop
  82. //变量windowHeight是可视区的高度
  83. var windowHeight =
  84. document.documentElement.clientHeight || document.body.clientHeight
  85. //变量scrollHeight是滚动条的总高度
  86. var scrollHeight =
  87. document.documentElement.scrollHeight || document.body.scrollHeight
  88. // console.log(scrollTop, windowHeight, scrollHeight);
  89. //滚动条到底部的条件
  90. if (scrollTop + windowHeight + 5 >= scrollHeight) {
  91. console.log('加载更多数据')
  92. // this.loading=true;
  93. //获取数据请求 请求结束后
  94. //成功设置 this.list =[...this.list,...this.list1]; this.loading=false;
  95. //失败设置 没有更多 this.nomore = true; this.loading = false;
  96. // window.setTimeout(()=>{this.loading=false;
  97. // console.log(this.list);},5000)
  98. }
  99. else {
  100. this.loading = false
  101. }
  102. window.clearTimeout()
  103. },
  104. loadData () {
  105. console.log('loadData')
  106. this.showLoading()
  107. Http.get(Apis.PAGE.SQUARE_PAGE).then((res) => {
  108. this.list = res.crowdTaskVOList
  109. this.hideLoading()
  110. }).catch((error) => {
  111. notify('error', '任务加载失败' + error.data)
  112. })
  113. },
  114. showLoading () {
  115. this.loading = true
  116. },
  117. hideLoading () {
  118. this.loading = false
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="less" scoped>
  124. .square-container {
  125. padding: 40px 80px;
  126. }
  127. .nomore {
  128. text-align: center;
  129. font-size: 1.4rem;
  130. color: #8a8a8a;
  131. padding: 5px;
  132. }
  133. </style>