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.
110 lines
2.6 KiB
110 lines
2.6 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';
|
|
import {MessageInterface, MessageUtil} from '../message/message.service';
|
|
import {NoticeService} from './notice/notice.service';
|
|
import {TranslateService} from '@ngx-translate/core';
|
|
|
|
/**
|
|
* 论坛组件
|
|
*/
|
|
@Component({
|
|
selector: 'app-forum',
|
|
templateUrl: './forum.component.html',
|
|
styleUrls: ['./forum.component.scss']
|
|
})
|
|
export class ForumComponent implements OnInit, MessageInterface {
|
|
|
|
/**
|
|
* 公告信息
|
|
*/
|
|
notices: Array<Notice>;
|
|
|
|
/**
|
|
* 帖子信息
|
|
*/
|
|
posts: Forum;
|
|
|
|
// 激活帖子索引
|
|
currentIndex = 0;
|
|
loadNoticesStatus = this.prefix('load_notices');
|
|
|
|
constructor(
|
|
private router: Router,
|
|
private forumService: ForumService,
|
|
private noticeService: NoticeService,
|
|
private messageUtil: MessageUtil,
|
|
private translate: TranslateService
|
|
) {
|
|
}
|
|
|
|
getActive(): Active {
|
|
return this.posts.list[this.currentIndex] as Active;
|
|
}
|
|
|
|
getComplaint(): Complaint {
|
|
return this.posts.list[this.currentIndex] as Complaint;
|
|
}
|
|
|
|
/**
|
|
* 获取公告信息
|
|
*/
|
|
getAllNotices() {
|
|
this.noticeService.getAllNotices().subscribe(res => {
|
|
this.loadNoticesStatus = this.prefix(res.message);
|
|
if (res.result === Result.OK) {
|
|
this.notices = res.noticeList;
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 获取所有帖子
|
|
*/
|
|
getAllPosts(page) {
|
|
this.posts = null;
|
|
this.forumService.getAllPosts(page).subscribe(res => {
|
|
if (res.result === Result.OK) {
|
|
console.debug('获取帖子信息成功');
|
|
this.posts = res.body;
|
|
}
|
|
});
|
|
}
|
|
|
|
// 删除公告
|
|
deleteNotice(noticeId) {
|
|
this.translate.get(this.prefix('confirm_delete')).subscribe(r => {
|
|
if (confirm(r)) {
|
|
this.noticeService.deleteNotice({id: noticeId}).subscribe(res => {
|
|
this.messageUtil.alert(this.prefix(res.message));
|
|
location.href = '/forum';
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 审核帖子
|
|
*/
|
|
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);
|
|
}
|
|
|
|
prefix(key: string): string {
|
|
return 'server.forum.notice.' + key;
|
|
}
|
|
}
|
|
|