Square.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <div class="square-container">
  3. <div class="title">全部任务</div>
  4. <div class="square-list-container">
  5. <task-item v-for="(item,index) in list" :key="index" :taskId="item.id" />
  6. <div v-if="loading" class="loading">
  7. <span></span>
  8. <span></span>
  9. <span></span>
  10. <span></span>
  11. <span></span>
  12. <span></span>
  13. <span></span>
  14. </div>
  15. <div v-if="nomore" class="nomore">没有更多</div>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. import TaskItem from "@/components/commons/TaskItem";
  21. export default {
  22. name: "Square",
  23. components: { TaskItem },
  24. data() {
  25. return {
  26. loading: false,
  27. nomore:false,
  28. list: [
  29. {
  30. id: 0,
  31. title: "发送群文件测试",
  32. platform: [0, 1],
  33. description: "任务描述文字xxxx",
  34. price: "30",
  35. 业务类型: 1,
  36. participantNum: 30,
  37. status: 0
  38. },
  39. {
  40. id: 1,
  41. title: "多人聊天发送文件测试",
  42. platform: [0],
  43. description: "任务描述文字xxxx",
  44. price: "10",
  45. 业务类型: 0,
  46. participantNum: 0,
  47. status: 1
  48. },
  49. {
  50. id: 2,
  51. title: "浏览器波洞星球",
  52. platform: [1],
  53. description: "任务描述文字xxxx",
  54. price: "10",
  55. 业务类型: 2,
  56. participantNum: 21,
  57. status: 0
  58. },
  59. {
  60. id: 3,
  61. title: "举报支持选择聊天记录(安全)",
  62. platform: [0, 1, 2],
  63. description: "任务描述文字xxxx",
  64. price: "0",
  65. 业务类型: 1,
  66. participantNum: 1,
  67. status: 1
  68. },
  69. {
  70. id: 4,
  71. title: "发送群文件测试",
  72. platform: [0, 1],
  73. description: "任务描述文字xxxx",
  74. price: "30",
  75. 业务类型: 1,
  76. participantNum: 30,
  77. status: 0
  78. },
  79. {
  80. id: 5,
  81. title: "多人聊天发送文件测试",
  82. platform: [0],
  83. description: "任务描述文字xxxx",
  84. price: "10",
  85. 业务类型: 0,
  86. participantNum: 0,
  87. status: 1
  88. },
  89. {
  90. id: 6,
  91. title: "浏览器波洞星球",
  92. platform: [1],
  93. description: "任务描述文字xxxx",
  94. price: "10",
  95. 业务类型: 2,
  96. participantNum: 21,
  97. status: 0
  98. },
  99. {
  100. id: 7,
  101. title: "举报支持选择聊天记录(安全)",
  102. platform: [0, 1, 2],
  103. description: "任务描述文字xxxx",
  104. price: "0",
  105. 业务类型: 1,
  106. participantNum: 1,
  107. status: 1
  108. },
  109. {
  110. id: 8,
  111. title: "发送群文件测试",
  112. platform: [0, 1],
  113. description: "任务描述文字xxxx",
  114. price: "30",
  115. 业务类型: 1,
  116. participantNum: 30,
  117. status: 0
  118. },
  119. {
  120. id: 9,
  121. title: "多人聊天发送文件测试",
  122. platform: [0],
  123. description: "任务描述文字xxxx",
  124. price: "10",
  125. 业务类型: 0,
  126. participantNum: 0,
  127. status: 1
  128. },
  129. {
  130. id: 10,
  131. title: "浏览器波洞星球",
  132. platform: [1],
  133. description: "任务描述文字xxxx",
  134. price: "10",
  135. 业务类型: 2,
  136. participantNum: 21,
  137. status: 0
  138. },
  139. {
  140. id: 11,
  141. title: "举报支持选择聊天记录(安全)",
  142. platform: [0, 1, 2],
  143. description: "任务描述文字xxxx",
  144. price: "0",
  145. 业务类型: 1,
  146. participantNum: 1,
  147. status: 1
  148. }
  149. ],
  150. list1: [
  151. {
  152. id: 0,
  153. title: "1发送群文件测试",
  154. platform: [0, 1],
  155. description: "任务描述文字xxxx",
  156. price: "30",
  157. serviceType: 1,
  158. participantNum: 30,
  159. status: 0
  160. },
  161. {
  162. id: 1,
  163. title: "多人聊天发送文件测试",
  164. platform: [0],
  165. description: "任务描述文字xxxx",
  166. price: "10",
  167. serviceType: 0,
  168. participantNum: 0,
  169. status: 1
  170. },
  171. {
  172. id: 2,
  173. title: "浏览器波洞星球",
  174. platform: [1],
  175. description: "任务描述文字xxxx",
  176. price: "10",
  177. serviceType: 2,
  178. participantNum: 21,
  179. status: 0
  180. },
  181. {
  182. id: 3,
  183. title: "举报支持选择聊天记录(安全)",
  184. platform: [0, 1, 2],
  185. description: "任务描述文字xxxx",
  186. price: "0",
  187. serviceType: 1,
  188. participantNum: 1,
  189. status: 1
  190. },
  191. {
  192. id: 4,
  193. title: "发送群文件测试",
  194. platform: [0, 1],
  195. description: "任务描述文字xxxx",
  196. price: "30",
  197. serviceType: 1,
  198. participantNum: 30,
  199. status: 0
  200. },
  201. {
  202. id: 5,
  203. title: "多人聊天发送文件测试",
  204. platform: [0],
  205. description: "任务描述文字xxxx",
  206. price: "10",
  207. serviceType: 0,
  208. participantNum: 0,
  209. status: 1
  210. },
  211. {
  212. id: 6,
  213. title: "浏览器波洞星球",
  214. platform: [1],
  215. description: "任务描述文字xxxx",
  216. price: "10",
  217. serviceType: 2,
  218. participantNum: 21,
  219. status: 0
  220. },
  221. {
  222. id: 7,
  223. title: "举报支持选择聊天记录(安全)",
  224. platform: [0, 1, 2],
  225. description: "任务描述文字xxxx",
  226. price: "0",
  227. serviceType: 1,
  228. participantNum: 1,
  229. status: 1
  230. },
  231. {
  232. id: 8,
  233. title: "发送群文件测试",
  234. platform: [0, 1],
  235. description: "任务描述文字xxxx",
  236. price: "30",
  237. serviceType: 1,
  238. participantNum: 30,
  239. status: 0
  240. },
  241. {
  242. id: 9,
  243. title: "多人聊天发送文件测试",
  244. platform: [0],
  245. description: "任务描述文字xxxx",
  246. price: "10",
  247. serviceType: 0,
  248. participantNum: 0,
  249. status: 1
  250. },
  251. {
  252. id: 10,
  253. title: "浏览器波洞星球",
  254. platform: [1],
  255. description: "任务描述文字xxxx",
  256. price: "10",
  257. serviceType: 2,
  258. participantNum: 21,
  259. status: 0
  260. },
  261. {
  262. id: 11,
  263. title: "举报支持选择聊天记录(安全)",
  264. platform: [0, 1, 2],
  265. description: "任务描述文字xxxx",
  266. price: "0",
  267. serviceType: 1,
  268. participantNum: 1,
  269. status: 1
  270. }
  271. ]
  272. };
  273. },
  274. mounted() {
  275. window.addEventListener("scroll", this.throttle(this.setpage, 1000), false);
  276. },
  277. methods: {
  278. throttle(func, wait, options) {
  279. let context, args, result;
  280. let timeout = null;
  281. let previous = 0;
  282. if (!options) options = {};
  283. let later = function() {
  284. previous = options.leading === false ? 0 : Number(new Date());
  285. timeout = null;
  286. result = func.apply(context, args);
  287. if (!timeout) context = args = null;
  288. };
  289. return (..._args) => {
  290. let now = Number(new Date());
  291. if (!previous && options.leading === false) previous = now;
  292. let remaining = wait - (now - previous);
  293. context = this;
  294. args = _args;
  295. if (remaining <= 0 || remaining > wait) {
  296. clearTimeout(timeout);
  297. timeout = null;
  298. previous = now;
  299. result = func.apply(context, args);
  300. if (!timeout) context = args = null;
  301. } else if (!timeout && options.trailing !== false) {
  302. timeout = setTimeout(later, remaining);
  303. }
  304. return result;
  305. };
  306. },
  307. setpage() {
  308. if (this.nomore && !this.loading) return; //到达底部不再执行
  309. var scrollTop =
  310. document.documentElement.scrollTop || document.body.scrollTop;
  311. //变量windowHeight是可视区的高度
  312. var windowHeight =
  313. document.documentElement.clientHeight || document.body.clientHeight;
  314. //变量scrollHeight是滚动条的总高度
  315. var scrollHeight =
  316. document.documentElement.scrollHeight || document.body.scrollHeight;
  317. // console.log(scrollTop, windowHeight, scrollHeight);
  318. //滚动条到底部的条件
  319. if (scrollTop + windowHeight + 5 >= scrollHeight) {
  320. console.log("加载更多数据");
  321. // this.loading=true;
  322. //获取数据请求 请求结束后
  323. //成功设置 this.list =[...this.list,...this.list1]; this.loading=false;
  324. //失败设置 没有更多 this.nomore = true; this.loading = false;
  325. // window.setTimeout(()=>{this.loading=false;
  326. // console.log(this.list);},5000)
  327. }
  328. else{this.loading=false;}
  329. window.clearTimeout();
  330. }
  331. }
  332. };
  333. </script>
  334. <style lang="less" scoped>
  335. .square-container {
  336. padding: 40px 80px;
  337. }
  338. .nomore{
  339. text-align: center;
  340. font-size: 1.4rem;
  341. color: #8a8a8a;
  342. padding: 5px;
  343. }
  344. </style>