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/forum.component.ts

139 lines
3.2 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, Score} from '../../interface/ForumType';
import {Notice} from '../../interface/Notice';
import {MessageInterface, MessageUtil} from '../../message/message.service';
import {NoticeService} from '../notice/notice.service';
import {TranslateService} from '@ngx-translate/core';
import {ForumNewResponse} from '../../interface/Response';
/**
* 论坛组件
*/
@Component({
selector: 'app-forum',
templateUrl: './forum.component.html',
styleUrls: ['./forum.component.scss']
})
export class ForumComponent implements OnInit, MessageInterface {
/**
* 公告信息
*/
notices: Array<Notice>;
/**
* 帖子信息
*/
posts: ForumNewResponse;
// 激活帖子索引
currentIndex = 0;
// 公告提示信息
loadNoticesStatus = 'load_notices';
// 帖子提示信息
loadPostsStatus = 'load_posts';
// 日期格式
dateFormat = 'yyyy-MM-dd';
// 帖子类型
activeType = 'active';
complanType = 'complan';
topicType = 'topic';
scoreType = 'score';
// 审核状态
okType = 'ok';
failType = 'fail';
// 当前页数
currentPage = 1;
constructor(
private router: Router,
private forumService: ForumService,
private noticeService: NoticeService,
private messageUtil: MessageUtil,
private translate: TranslateService
) {
}
getForum(): Forum {
return this.posts.forumList.list[this.currentIndex];
}
getActive(): Active {
return this.getForum().activeDto;
}
getComplaint(): Complaint {
return this.getForum().complainDto;
}
getScore(): Score {
return this.getForum().score;
}
/**
* 获取公告信息
*/
getAllNotices() {
this.noticeService.getAllNotices().subscribe(res => {
this.loadNoticesStatus = res.message;
if (res.result === Result.OK) {
this.notices = res.noticeList;
}
});
}
/**
* 获取所有帖子
*/
getAllPosts(page) {
this.currentPage = page;
this.posts = null;
this.forumService.getAllPosts(page).subscribe(res => {
this.loadPostsStatus = res.message;
if (res.result === Result.OK) {
console.debug('获取帖子信息成功');
this.posts = res;
}
});
}
// 删除公告
deleteNotice(noticeId) {
this.translate.get(this.prefix('notice.confirm_delete')).subscribe(r => {
if (confirm(r)) {
this.noticeService.deleteNotice({id: noticeId}).subscribe(res => {
this.messageUtil.alert(this.prefix('notice.' + res.message));
location.reload();
});
}
});
}
/**
* 审核帖子
*/
checkPost(status) {
this.forumService.checkPost(this.getForum().id, status).subscribe(res => {
this.messageUtil.alert(this.prefix('posts.' + res.message));
if (res.result === Result.OK) {
this.getAllPosts(this.currentPage);
}
});
}
ngOnInit(): void {
this.getAllNotices();
this.getAllPosts(this.currentPage);
}
prefix(key: string): string {
return 'server.forum.' + key;
}
}