knowledge-video.component.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { Component, OnInit } from '@angular/core';
  2. import { ActivatedRoute, Router } from '@angular/router';
  3. import { IonBackButton, IonButtons, IonTitle, IonToolbar } from '@ionic/angular/standalone';
  4. import { IonIcon } from '@ionic/angular/standalone';
  5. import { IonHeader } from '@ionic/angular/standalone';
  6. import { IonContent, IonItem, IonList } from '@ionic/angular/standalone';
  7. import { addIcons } from 'ionicons';
  8. import { arrowBackOutline } from 'ionicons/icons';
  9. import { CloudObject, CloudQuery } from 'src/lib/ncloud';
  10. addIcons({ arrowBackOutline })
  11. @Component({
  12. selector: 'app-knowledge-video',
  13. templateUrl: './knowledge-video.component.html',
  14. styleUrls: ['./knowledge-video.component.scss'],
  15. standalone: true,
  16. imports: [
  17. IonContent, IonList, IonItem,IonHeader, IonIcon, IonTitle, IonToolbar, IonButtons, IonBackButton
  18. ]
  19. })
  20. export class KnowledgeVideoComponent implements OnInit {
  21. knowledge: CloudObject | null = null; // 初始化为 null
  22. constructor(private route: ActivatedRoute, private loute: Router) {}
  23. ngOnInit() {
  24. const objectId = this.route.snapshot.paramMap.get('id'); // 获取传递的 ObjectId
  25. if (objectId) { // 检查 objectId 是否为 null
  26. this.loadKnowledge(objectId); // 加载对应的知识信息
  27. } else {
  28. console.error("No ObjectId found in route parameters.");
  29. }
  30. }
  31. async loadKnowledge(objectId: string) {
  32. let query = new CloudQuery("videoknowledge");
  33. query.equalTo("title", objectId); // 根据 ObjectId 查询
  34. const knowledge = await query.first(); // 获取单条记录
  35. if (knowledge) {
  36. this.knowledge = knowledge; // 将获取的知识信息赋值给 knowledge 属性
  37. } else {
  38. console.error("Knowledge not found for ObjectId:", objectId);
  39. // 可以考虑在这里处理找不到知识的情况,比如导航到错误页面或者显示提示
  40. }
  41. }
  42. goToLastPage(){
  43. this.loute.navigate(['/tabs/knowledge-total'])
  44. }
  45. }