|
@@ -1,14 +1,66 @@
|
|
|
-import { Component } from '@angular/core';
|
|
|
-import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
|
|
|
-import { ExploreContainerComponent } from '../explore-container/explore-container.component';
|
|
|
+ import { CommonModule } from '@angular/common';
|
|
|
+ import { Component } from '@angular/core';
|
|
|
+import { InfiniteScrollCustomEvent, IonicModule } from '@ionic/angular';
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-forum',
|
|
|
templateUrl: 'forum.page.html',
|
|
|
styleUrls: ['forum.page.scss'],
|
|
|
standalone: true,
|
|
|
- imports: [IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent],
|
|
|
+ imports: [CommonModule,IonicModule],
|
|
|
})
|
|
|
+
|
|
|
export class ForumPage {
|
|
|
- constructor() { }
|
|
|
+
|
|
|
+ posts: Array<{ title: string; author: string; publishDate: Date; likes: number; comments: number }> = [];
|
|
|
+ allPosts: Array<{ title: string; author: string; publishDate: Date; likes: number; comments: number }> = [];
|
|
|
+ pageSize: number = 10;
|
|
|
+ currentPage: number = 0;
|
|
|
+
|
|
|
+ constructor() {
|
|
|
+
|
|
|
+ this.allPosts = this.getPosts();
|
|
|
+ this.loadMorePosts();
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnInit() {}
|
|
|
+
|
|
|
+ getPosts() {
|
|
|
+
|
|
|
+ return [
|
|
|
+ { title: '帖子1', author: '用户A', publishDate: new Date(), likes: 10, comments: 5 },
|
|
|
+ { title: '帖子2', author: '用户B', publishDate: new Date(), likes: 20, comments: 10 },
|
|
|
+
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ loadMorePosts(event?: InfiniteScrollCustomEvent) {
|
|
|
+ const nextPosts = this.allPosts.slice(this.currentPage * this.pageSize, (this.currentPage + 1) * this.pageSize);
|
|
|
+ console.log('加载的帖子:', nextPosts);
|
|
|
+ this.posts.push(...nextPosts);
|
|
|
+ console.log('当前帖子数量:', this.posts.length);
|
|
|
+ this.currentPage++;
|
|
|
+
|
|
|
+ if (event) {
|
|
|
+ event.target.complete();
|
|
|
+ if (nextPosts.length < this.pageSize) {
|
|
|
+ event.target.disabled = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ filterPosts(event: any) {
|
|
|
+ const query = event.target.value.toLowerCase();
|
|
|
+ this.posts = this.allPosts.filter(post => post.title.toLowerCase().includes(query));
|
|
|
+ console.log('过滤后的帖子:', this.posts);
|
|
|
+ }
|
|
|
+ openPostDetail(post: any) {
|
|
|
+
|
|
|
+ console.log('打开帖子详情:', post);
|
|
|
+ }
|
|
|
}
|