community.component.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { Component } from '@angular/core';
  2. // 引用服务
  3. import { Router } from '@angular/router';
  4. // 引入Parse第三方库
  5. import * as Parse from "parse"
  6. (Parse as any).serverURL = "http://metapunk.cn:9999/parse"
  7. Parse.initialize("dev")
  8. @Component({
  9. selector: 'app-community',
  10. templateUrl: './community.component.html',
  11. styleUrls: ['./community.component.scss']
  12. })
  13. export class CommunityComponent {
  14. scienceList: Array<Parse.Object> = []
  15. recommendList: Array<Parse.Object> = []
  16. attentionList: Array<Parse.Object> = []
  17. // 依赖注入
  18. constructor(private router: Router) {
  19. this.initPage();
  20. }
  21. // 首次进入页面,默认加载首批数据
  22. async initPage() {
  23. this.scienceList = await this.getScienceData()
  24. this.recommendList = await this.gteRecommendData()
  25. this.attentionList = await this.gteAttentionData()
  26. }
  27. // 数据加载相关函数
  28. async getScienceData() {
  29. let query = new Parse.Query("PetScience");
  30. let list = await query.find();
  31. return list
  32. }
  33. async gteRecommendData() {
  34. let query = new Parse.Query("PetRecommend");
  35. let list = await query.find();
  36. return list
  37. }
  38. async gteAttentionData() {
  39. let query = new Parse.Query("PetAttention");
  40. let list = await query.find();
  41. return list
  42. }
  43. cate: string = "推荐"
  44. // 跳转函数
  45. goScienceDetail(science: Parse.Object) {
  46. this.router.navigate(["/lesson/community/scienceDetail"], {
  47. queryParams: science
  48. })
  49. }
  50. goRecommendDetail(recommend: Parse.Object) {
  51. this.router.navigate(["/lesson/community/recommendDetail"], {
  52. queryParams: recommend
  53. })
  54. }
  55. goAttentionDetail(attention: Parse.Object) {
  56. this.router.navigate(["/lesson/community/attentionDetail"], {
  57. queryParams: attention
  58. })
  59. }
  60. goHateDetail(attention: Parse.Object) {
  61. this.router.navigate(["/lesson/community/hateDetail"], {
  62. queryParams: attention
  63. })
  64. }
  65. // 888
  66. }