card-detail.page.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { Component, OnInit, } from '@angular/core';
  2. import { ActivatedRoute, Router } from '@angular/router';
  3. import { CommonModule } from '@angular/common';
  4. import { FormsModule } from '@angular/forms';
  5. import { IonContent, IonHeader,IonItem,IonList, IonThumbnail,IonTitle, IonToolbar,IonFooter, IonButtons,IonButton, IonBackButton} from '@ionic/angular/standalone';
  6. @Component({
  7. selector: 'app-card-detail',
  8. templateUrl: './card-detail.page.html',
  9. styleUrls: ['./card-detail.page.scss'],
  10. standalone: true,
  11. imports: [IonContent, IonHeader,IonThumbnail,IonList, IonTitle,IonItem,IonFooter, IonToolbar,IonButtons,IonButton, IonBackButton, CommonModule, FormsModule]
  12. })
  13. export class CardDetailPage implements OnInit {
  14. content: {
  15. title: string;
  16. editor: string;
  17. date: string;
  18. issue: string;
  19. detail: string;
  20. images: string[]; // 明确指定为字符串数组
  21. video: string;
  22. audio: string;
  23. } = {
  24. title: '',
  25. editor: '',
  26. date: '',
  27. issue: '',
  28. detail: '',
  29. images: [], // 初始化为空数组
  30. video: '',
  31. audio: ''
  32. };
  33. constructor(private activatedRoute: ActivatedRoute, private router: Router) { }
  34. ngOnInit() {
  35. const id = this.activatedRoute.snapshot.paramMap.get('id'); // 获取内容ID
  36. this.loadContent(id);
  37. }
  38. loadContent(id: string | null) {
  39. // 模拟加载内容,实际中应从服务获取数据
  40. this.content = {
  41. // title: `内容标题 ${id}`,
  42. title: `清平调`,
  43. editor: `文|编辑部`,
  44. // editor: `编者姓名 ${id}`,
  45. date: '2024-11-30',
  46. issue: `第1期`,
  47. // issue: `第${id}期`,
  48. detail: ` 云想衣裳花想容,春风拂槛露华浓。若非群玉山头见,会向瑶台月下逢。`,
  49. // detail: `这里是详细内容 ${id}...`,
  50. images: ['../assets/image/01/Vx_03.jpg', ], // 示例图片路径
  51. video: 'assets/video/sample.mp4', // 示例视频路径
  52. audio: 'assets/audio/sample.mp3' // 示例音频路径
  53. };
  54. }
  55. goBack() {
  56. this.router.navigate(['/tabs/tab1']); // 返回到 Tab1
  57. }
  58. prevContent() {
  59. const prevId = parseInt(this.content.issue.replace('第', '').replace('期', '')) - 1; // 简单逻辑示例
  60. if (prevId > 0) {
  61. this.router.navigate(['/card-detail'], { queryParams: { id: prevId } });
  62. }
  63. }
  64. nextContent() {
  65. const nextId = parseInt(this.content.issue.replace('第', '').replace('期', '')) + 1; // 简单逻辑示例
  66. this.router.navigate(['/card-detail'], { queryParams: { id: nextId } });
  67. }
  68. }