page-lesson.component.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { Component } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. // 引入Parse第三方库
  4. import * as Parse from "parse"
  5. (Parse as any).serverURL = "http://metapunk.cn:9999/parse"
  6. Parse.initialize("dev")
  7. @Component({
  8. selector: 'app-page-lesson',
  9. templateUrl: './page-lesson.component.html',
  10. styleUrls: ['./page-lesson.component.scss']
  11. })
  12. export class PageLessonComponent {
  13. constructor(private router: Router) { this.initPage(); }
  14. courseList: Array<Parse.Object> = []
  15. // 首次进入页面,默认加载首批数据
  16. async initPage() {
  17. this.courseList = await this.getMenuData()
  18. }
  19. // 数据加载相关函数
  20. async getMenuData() {
  21. let query = new Parse.Query("PetFood");
  22. query.limit(this.pageSize);
  23. query.include('courseAuthor')
  24. if (this.searchInput) {
  25. query.contains(this.searchType, this.searchInput)
  26. }
  27. if (this.skip) {
  28. query.skip(this.skip)
  29. }
  30. query.addAscending("no")
  31. let list = await query.find();
  32. console.log(list);
  33. return list
  34. }
  35. // 搜索功能相关函数与属性
  36. searchInput: string = ``
  37. searchType: string = `foodName`
  38. async search() {
  39. this.skip = 0; // 每次搜索条件变化,从第一条重新加载
  40. this.courseList = await this.getMenuData();
  41. }
  42. // 触底加载函数逻辑
  43. pageSize = 10
  44. skip: number = 0 // 跳过多少条进行加载
  45. async onBottomLoad(event: any, infiScroll: any) {
  46. console.log("onBottomLoad", this.courseList.length)
  47. this.skip = this.courseList.length;
  48. let list = await this.getMenuData();
  49. this.courseList = this.courseList.concat(list)
  50. infiScroll?.complete();
  51. }
  52. goLessonDetail(lesson: any) {
  53. this.router.navigate(["/lesson/lesson/detail"], { queryParams: lesson })
  54. }
  55. }