You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
pocketcommunityweb/src/app/forum/forum.component.ts

89 lines
1.8 KiB

import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {ForumService} from './forum.service';
import {Result} from '../interface/Result';
import {Active, Complaint, Forum} from '../interface/ForumType';
import {Notice} from '../interface/Notice';
/**
* 论坛组件
*/
@Component({
selector: 'app-forum',
templateUrl: './forum.component.html',
styleUrls: ['./forum.component.scss']
})
export class ForumComponent implements OnInit {
/**
* 公告信息
*/
notices: Array<Notice>;
/**
* 帖子信息
*/
posts: Forum;
// 激活帖子索引
currentIndex = 0;
constructor(
private router: Router,
private forumService: ForumService
) {
}
getActive(): Active {
return this.posts.list[this.currentIndex] as Active;
}
getComplaint(): Complaint {
return this.posts.list[this.currentIndex] as Complaint;
}
/**
* 获取公告信息
*/
getAllNotices() {
this.forumService.getAllNotices().subscribe(res => {
if (res.result === Result.OK) {
console.debug('获取公告信息成功');
this.notices = res.body;
}
});
}
/**
* 获取所有帖子
*/
getAllPosts(page) {
this.posts = null;
this.forumService.getAllPosts(page).subscribe(res => {
if (res.result === Result.OK) {
console.debug('获取帖子信息成功');
this.posts = res.body;
}
});
}
/**
* 审核帖子
*/
checkPost(status) {
this.forumService.checkPost(this.posts.list[this.currentIndex].id, status).subscribe(res => {
if (res.result === Result.OK) {
this.posts.list.splice(this.currentIndex, 1);
} else {
alert('审核操作失败,请重试');
}
});
}
ngOnInit(): void {
this.getAllNotices();
this.getAllPosts(1);
}
}