完善论坛接口

change
panqihua 5 years ago
parent f5530d4259
commit ba49ee7658
  1. 1
      src/app/account/login/login.component.ts
  2. 5
      src/app/app.component.ts
  3. 122
      src/app/forum/forum.component.html
  4. 49
      src/app/forum/forum.component.ts
  5. 18
      src/app/forum/forum.service.ts
  6. 5
      src/app/forum/notice/notice.component.ts
  7. 91
      src/app/interface/ForumType.ts
  8. 2
      src/app/interface/HttpInterface.ts
  9. 19
      src/app/interface/Info.ts
  10. 8
      src/app/interface/Page.ts
  11. 7
      src/app/interface/Response.ts
  12. 15
      src/assets/i18n/en-US.json
  13. 13
      src/assets/i18n/zh-CN.json

@ -35,7 +35,6 @@ export class LoginComponent extends Commons implements OnInit, MessageInterface
}
ngOnInit(): void {
}
// 登陆方法

@ -67,6 +67,11 @@ export class AppComponent implements OnInit, MessageInterface {
doNavigationStart(evt: RouterEvent, isLogin: boolean, managerName: string) {
that.isLogin = isLogin;
that.managerName = managerName;
if (isLogin && evt.url === '/login') {
that.router.navigateByUrl('/forum');
} else if (!isLogin && evt.url === '/forum') {
that.router.navigateByUrl('/login');
}
}
});

@ -1,7 +1,7 @@
<!--公告轮播-->
<ng-container *ngIf="notices;else load_notice_err">
<h1 *ngIf="notices.length==0;else notice_temp"
class="text-center col-12 m-3">{{'server.forum.notice.zero'|translate}}</h1>
class="text-center col-12 m-3">{{prefix('notice.zero')|translate}}</h1>
<ng-template #notice_temp>
<div id="carouselExampleControls" class="carousel slide bg-info m-3" data-ride="carousel">
<div class="carousel-inner">
@ -14,7 +14,7 @@
<h1 class="text-center mb-3">{{ 'forum.notice' | translate }}</h1>
<button [title]="this.prefix('delete')|translate" (click)="deleteNotice(notice.id)"
class="position-absolute delete_notice btn btn-outline-danger">
<svg t="1586720093778" class="icon" viewBox="0 0 1024 1024"
<svg class="icon" viewBox="0 0 1024 1024"
xmlns="http://www.w3.org/2000/svg" width="50" height="50">
<path
d="M810.666667 273.493333L750.506667 213.333333 512 451.84 273.493333 213.333333 213.333333 273.493333 451.84 512 213.333333 750.506667 273.493333 810.666667 512 572.16 750.506667 810.666667 810.666667 750.506667 572.16 512z"
@ -60,7 +60,7 @@
<div class="spinner-border load" role="status">
<span class="sr-only">Loading...</span>
</div>
<h1>{{loadNoticesStatus|translate}}</h1>
<h1>{{this.prefix('notice.' + loadNoticesStatus)|translate}}</h1>
</div>
</ng-template>
@ -70,22 +70,39 @@
<!-- 审核帖标识-->
<h1 class="text-info col-12 text-center">{{ 'forum.check' | translate }}</h1>
<ng-container *ngIf="posts;else ggg">
<ng-container *ngIf="posts;else load_posts_err">
<h1 *ngIf="posts.forumList.empty;else post_temp"
class="text-center col-12 m-3">{{prefix('posts.zero')|translate}}</h1>
<ng-template #post_temp>
<div class="col-3">
<!--帖子列表-->
<ul class="list-group">
<!-- 帖子列表-->
<li class="list-group-item" (click)="currentIndex=i" [class.active]="currentIndex===i" *ngFor="let post of posts.list;index as i">{{post.title}}</li>
<li class="list-group-item" (click)="currentIndex=i" [class.active]="currentIndex===i"
*ngFor="let post of posts.forumList.list;index as i">{{post.title}}</li>
</ul>
<!-- 分页按钮-->
<ul class="pagination ml-5 mt-3">
<li class="page-item" [class.disabled]="posts.page.currentPage-1===0"><a class="page-link btn" (click)="getAllPosts(posts.page.currentPage-1)">{{'button.prev_page'|translate}}</a></li>
<li class="page-item active"><a class="page-link btn" (click)="getAllPosts(posts.page.currentPage)">{{posts.page.currentPage}}</a></li>
<li class="page-item"><a class="page-link btn" *ngIf="posts.page.currentPage+1<=posts.page.page" (click)="getAllPosts(posts.page.currentPage+1)">{{posts.page.currentPage+1}}</a></li>
<li class="page-item"><a class="page-link btn" *ngIf="posts.page.currentPage+2<=posts.page.page" (click)="getAllPosts(posts.page.currentPage+2)">{{posts.page.currentPage+2}}</a></li>
<li class="page-item" [class.disabled]="posts.page.currentPage===posts.page.page"><a class="page-link btn" (click)="getAllPosts(posts.page.currentPage+1)">{{'button.next_page'|translate}}</a></li>
<li class="page-item" [class.disabled]="posts.forumList.currentPage-1===0"><a class="page-link btn"
(click)="getAllPosts(posts.forumList.currentPage-1)">{{'button.prev_page'|translate}}</a>
</li>
<li class="page-item active"><a class="page-link btn"
(click)="getAllPosts(posts.forumList.currentPage)">{{posts.forumList.currentPage}}</a>
</li>
<li class="page-item"><a class="page-link btn"
*ngIf="posts.forumList.currentPage+1<=posts.forumList.totalPage"
(click)="getAllPosts(posts.forumList.currentPage+1)">{{posts.forumList.currentPage + 1}}</a>
</li>
<li class="page-item"><a class="page-link btn"
*ngIf="posts.forumList.currentPage+2<=posts.forumList.totalPage"
(click)="getAllPosts(posts.forumList.currentPage+2)">{{posts.forumList.currentPage + 2}}</a>
</li>
<li class="page-item" [class.disabled]="posts.forumList.currentPage===posts.forumList.totalPage"><a
class="page-link btn"
(click)="getAllPosts(posts.forumList.currentPage+1)">{{'button.next_page'|translate}}</a></li>
</ul>
</div>
@ -94,43 +111,47 @@
<div class="col-9 post border-secondary p-3 position-relative">
<!-- 活动帖子-->
<ng-container *ngIf="this.posts.list[this.currentIndex].type==='active';else elseBlock;">
<ng-container [ngSwitch]="getForum().forumType">
<!-- 活动贴-->
<ng-container *ngSwitchCase="activeType">
<!-- 发件人信息-->
<div class="position-absolute sender">
<!-- 发帖人头像-->
<img [src]="getActive().headImg" alt="headimg" class="headimg mb-3"/>
<img [src]="getForum().info.headImg" alt="headimg" class="headimg mb-3"/>
<!-- 发帖人-->
<div class="forum-label border-info mb-3 text-center">
{{getActive().issuer}}
{{getForum().username}}
</div>
<!--信用分-->
<div class="forum-label border-info mb-3 text-center">
{{getActive().userCreditScore}}
{{getForum().info.creditScore}}
</div>
</div>
<!-- 帖子框架-->
<div>
<!-- 标题-->
<h1 class="text-info col-12 text-center mb-3 forum-title">{{getActive().title}}</h1>
<h1 class="text-info col-12 text-center mb-3 forum-title">{{getForum().title}}</h1>
<!-- 帖子正文-->
<div class="forum-content border-info overflow-auto col-9 offset-2 mb-3">
{{getActive().content}}
{{getForum().content}}
</div>
<!-- 帖子底部-->
<div class="forum-footer border-info p-3 mb-3">
<h3 class="text-center">{{ 'forum.active_date' | translate:{
startDate: getActive().startTime|date:'yyyy-MM-dd',
endDate: getActive().endTime|date:'yyyy-MM-dd'
startDate: getActive().activeStartTime|date:'yyyy-MM-dd',
endDate: getActive().activeEndTime|date:'yyyy-MM-dd'
} }}</h3>
<h3 class="text-center">{{ 'forum.active_score' | translate:{score: getActive().activeCreditScore} }}</h3>
<h3
class="text-center">{{ 'forum.active_score' | translate:{score: getActive().activeScore} }}</h3>
</div>
</div>
</ng-container>
<!-- 投诉帖子-->
<ng-template #elseBlock>
<ng-container *ngSwitchCase="complanType">
<div class="complaint row p-3">
<div class="col-5 border-info l-label h-100 d-flex justify-content-around">
@ -140,10 +161,10 @@
<div class="text-center">{{'forum.plaintiff'|translate}}</div>
<!-- 头像-->
<div class="d-flex justify-content-center mb-3 m-headimg">
<img [src]="getComplaint().plaintiffHeadImg" alt="headimg" class="headimg">
<img [src]="getForum().info.headImg" alt="headimg" class="headimg">
</div>
<div class="text-center border-info mb-3 l-label">{{getComplaint().plaintiffName}}</div>
<div class="text-center border-info l-label">{{getComplaint().plaintiffCreditScore}}</div>
<div class="text-center border-info mb-3 l-label">{{getForum().username}}</div>
<div class="text-center border-info l-label">{{getForum().info.creditScore}}</div>
</div>
<!-- 被投诉人信息-->
@ -151,10 +172,10 @@
<div class="text-center">{{'forum.defendant'|translate}}</div>
<div class="d-flex justify-content-center mb-3 m-headimg">
<!-- 头像-->
<img [src]="getComplaint().defendantHeadImg" alt="headimg" class="headimg">
<img [src]="getComplaint().info.headImg" alt="headimg" class="headimg">
</div>
<div class="text-center border-info mb-3 l-label">{{getComplaint().defendantName}}</div>
<div class="text-center border-info l-label">{{getComplaint().defendantCreditScore}}</div>
<div class="text-center border-info mb-3 l-label">{{getComplaint().complain}}</div>
<div class="text-center border-info l-label">{{getComplaint().info.creditScore}}</div>
</div>
</div>
@ -163,30 +184,61 @@
<!-- 投诉内容-->
<div class="col-7 border-success l-label h-100">
<!-- 投诉项-->
<h1 class="text-center">{{getComplaint().title}}</h1>
<h1 class="text-center">{{getForum().title}}</h1>
<!-- 投诉内容-->
<div class="forum-content border-info overflow-auto mb-3">
{{getComplaint().content}}
{{getForum().content}}
</div>
<!-- 投诉时间-->
<h1 class="text-center">{{ 'forum.complaint_time' | translate:{time: getComplaint().time|date:'yyyy-MM-dd'} }}</h1>
<h1
class="text-center">{{ 'forum.complaint_time' | translate:{time: getForum().time|date:'yyyy-MM-dd'} }}</h1>
</div>
</div>
</ng-template>
</ng-container>
<!-- 动态帖子-->
<ng-container *ngSwitchCase="topicType">
<!-- 发件人信息-->
<div class="position-absolute sender">
<!-- 发帖人头像-->
<img [src]="getForum().info.headImg" alt="headimg" class="headimg mb-3"/>
<!-- 发帖人-->
<div class="forum-label border-info mb-3 text-center">
{{getForum().username}}
</div>
<!--信用分-->
<div class="forum-label border-info mb-3 text-center">
{{getForum().info.creditScore}}
</div>
</div>
<!-- 帖子框架-->
<div>
<!-- 标题-->
<h1 class="text-info col-12 text-center mb-3 forum-title">{{getForum().title}}</h1>
<!-- 帖子正文-->
<div class="forum-content border-info overflow-auto col-9 offset-2 mb-3">
{{getForum().content}}
</div>
</div>
</ng-container>
</ng-container>
<!--帖子审核按钮-->
<div class="col-12 text-center">
<button class="btn btn-info col-2 mr-3" (click)="checkPost(0)">{{ 'forum.approve' | translate }}</button>
<button class="btn btn-danger col-2" (click)="checkPost(1)">{{ 'forum.reject' | translate }}</button>
<button class="btn btn-info col-2 mr-3" (click)="checkPost(okType)">{{ 'forum.approve' | translate }}</button>
<button class="btn btn-danger col-2" (click)="checkPost(failType)">{{ 'forum.reject' | translate }}</button>
</div>
</div>
</ng-template>
</ng-container>
<ng-template #ggg>
<ng-template #load_posts_err>
<div class="text-center col-12">
<div class="spinner-border load" role="status">
<span class="sr-only">Loading...</span>
</div>
<h1>{{'forum.load_posts'|translate}}</h1>
<h1>{{this.prefix('posts.' + loadPostsStatus)|translate}}</h1>
</div>
</ng-template>

@ -7,6 +7,7 @@ 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';
/**
*
@ -26,11 +27,26 @@ export class ForumComponent implements OnInit, MessageInterface {
/**
*
*/
posts: Forum;
posts: ForumNewResponse;
// 激活帖子索引
currentIndex = 0;
loadNoticesStatus = this.prefix('load_notices');
// 公告提示信息
loadNoticesStatus = 'load_notices';
// 帖子提示信息
loadPostsStatus = 'load_posts';
// 帖子类型
activeType = 'active';
complanType = 'complan';
topicType = 'topic';
// 审核状态
okType = 'ok';
failType = 'fail';
// 当前页数
currentPage = 1;
constructor(
private router: Router,
@ -41,12 +57,16 @@ export class ForumComponent implements OnInit, MessageInterface {
) {
}
getForum(): Forum {
return this.posts.forumList.list[this.currentIndex];
}
getActive(): Active {
return this.posts.list[this.currentIndex] as Active;
return this.getForum().activeDto;
}
getComplaint(): Complaint {
return this.posts.list[this.currentIndex] as Complaint;
return this.getForum().complainDto;
}
/**
@ -54,7 +74,7 @@ export class ForumComponent implements OnInit, MessageInterface {
*/
getAllNotices() {
this.noticeService.getAllNotices().subscribe(res => {
this.loadNoticesStatus = this.prefix(res.message);
this.loadNoticesStatus = res.message;
if (res.result === Result.OK) {
this.notices = res.noticeList;
}
@ -65,21 +85,23 @@ export class ForumComponent implements OnInit, MessageInterface {
*
*/
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.body;
this.posts = res;
}
});
}
// 删除公告
deleteNotice(noticeId) {
this.translate.get(this.prefix('confirm_delete')).subscribe(r => {
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(res.message));
this.messageUtil.alert(this.prefix('notice.' + res.message));
location.href = '/forum';
});
}
@ -90,21 +112,20 @@ export class ForumComponent implements OnInit, MessageInterface {
*
*/
checkPost(status) {
this.forumService.checkPost(this.posts.list[this.currentIndex].id, status).subscribe(res => {
this.forumService.checkPost(this.getForum().id, status).subscribe(res => {
this.messageUtil.alert(this.prefix('posts.' + res.message));
if (res.result === Result.OK) {
this.posts.list.splice(this.currentIndex, 1);
} else {
alert('审核操作失败,请重试');
this.getAllPosts(this.currentPage);
}
});
}
ngOnInit(): void {
this.getAllNotices();
this.getAllPosts(1);
this.getAllPosts(this.currentPage);
}
prefix(key: string): string {
return 'server.forum.notice.' + key;
return 'server.forum.' + key;
}
}

@ -5,6 +5,8 @@ import {HttpInterface} from '../interface/HttpInterface';
import {JSONRequest} from '../interface/JSONRequest';
import {Observable} from 'rxjs';
import {catchError} from 'rxjs/operators';
import {ForumNewResponse} from '../interface/Response';
import {ForumStatus} from '../interface/ForumType';
/**
*
@ -23,8 +25,13 @@ export class ForumService extends JSONRequest {
/**
*
*/
getAllPosts(page): Observable<JSONResponse<any>> {
return this.http.get<JSONResponse<any>>(HttpInterface.getAllPosts + '/' + page, this.httpOptions)
getAllPosts(page): Observable<ForumNewResponse> {
return this.http.get<ForumNewResponse>(HttpInterface.getAllPosts, Object.assign(this.httpOptions, {
params: {
currentPage: page,
status: ForumStatus.uncheck
}
}))
.pipe(
catchError(this.handleError<any>('获取帖子'))
);
@ -33,8 +40,11 @@ export class ForumService extends JSONRequest {
/**
*
*/
checkPost(id, s): Observable<JSONResponse<any>> {
return this.http.patch<JSONResponse<any>>(HttpInterface.checkPost + '/' + id, { status : s}, this.httpOptions)
checkPost($id, $status): Observable<JSONResponse<any>> {
return this.http.post<JSONResponse<any>>(HttpInterface.checkPost, {
id: $id,
status: $status
}, this.httpOptions)
.pipe(
catchError(this.handleError<any>('审核帖子'))
);

@ -38,10 +38,9 @@ export class NoticeComponent extends Commons implements OnInit, MessageInterface
this.noticeService.addNotice(Object.assign(
this.noticeForm.value, {author: this.cookieService.get(environment.managerKey)}
)).subscribe(res => {
this.messageUtil.alert(this.prefix(res.message));
if (res.result === Result.OK) {
location.href = '/forum';
} else {
this.messageUtil.danger(res.message);
}
});
}
@ -60,7 +59,7 @@ export class NoticeComponent extends Commons implements OnInit, MessageInterface
}
prefix(key: string): string {
return 'server.forum.notice.';
return 'server.forum.notice.' + key;
}

@ -1,66 +1,57 @@
// 帖子类型
import {Info} from './Info';
export enum ForumType {
active= 'active',
complaint= 'complaint'
active = 'active',
topic = 'topic',
complan = 'complan'
}
// 活动帖
export interface Active {
// 活动帖
// 帖子类型
type: ForumType;
// 帖子ID
id: number;
// 发帖人
issuer: string;
// 头像
headImg: string;
// 用户信用分
userCreditScore: number;
export enum ForumStatus {
uncheck = 'uncheck',
ok = 'ok',
fail = 'fail'
}
export interface Forum {
// 帖子
id: string;
// 帖子标题
title: string;
// 帖子内容
// 回复数
reply: number;
// 帖子类型
forumType: ForumType;
// 缩略内容
content: string;
// 发帖人
username: string;
// 发帖时间
time: number;
// 活动贴信息
activeDto: Active;
// 投诉贴信息
complainDto: Complaint;
// 发帖人详情信息
info: Info;
}
// 活动帖
export interface Active {
// 活动开始时间
startTime: number;
activeStartTime: number;
// 活动结束时间
endTime: number;
activeEndTime: number;
// 活动奖励分
activeCreditScore: number;
activeScore: number;
}
// 投诉帖
export interface Complaint {
// 帖子类型
type: ForumType;
// 帖子ID
id: number;
// 投诉人头像
plaintiffHeadImg: string;
// 投诉人名称
plaintiffName: string;
// 投诉人信用分
plaintiffCreditScore: number;
// 被投诉人头像
defendantHeadImg: string;
// 被投诉人名称
defendantName: string;
// 被投诉人信用分
defendantCreditScore: number;
// 投诉标题
title: string;
// 投诉内容
content: string;
// 投诉时间
time: number;
}
// 投诉人
complain: string;
export interface Forum {
list: Array<Active|Complaint>;
page: {
count: number;
page: number;
currentPage: number;
};
// 投诉人详情信息
info: Info;
}

@ -23,7 +23,7 @@ const HttpInterface = {
// 获取所有帖子
getAllPosts: '/api/forum/posts',
// 审核帖子
checkPost: '/api/forum/posts',
checkPost: '/api/forum/posts/check',
// 添加公告
addNotice: '/api/forum/notice/add',
// 删除公告

@ -0,0 +1,19 @@
// 用户信息
export interface Info {
// 用户名
username: string;
// 信用分
creditScore: number;
// 头像
headImg: string;
// 最近发帖数
recentPosts: number;
// 最近访客数
recentVisitors: number;
// 手机号
mobie: string;
// 邮箱
email: string;
// 信用分历史记录
scoreHistory: Array<number>;
}

@ -0,0 +1,8 @@
export interface Page<T> {
count: number;
totalPage: number;
currentPage: number;
list: Array<T>;
pageSize: number;
empty: boolean;
}

@ -2,6 +2,8 @@ import {Result} from './Result';
import {Token} from './Token';
import {EmailType} from './EmailType';
import {Notice} from './Notice';
import {Forum} from './ForumType';
import {Page} from './Page';
export interface Response {
// 响应结果
@ -46,3 +48,8 @@ export interface ResetpwdResponse extends Response {
export interface ForumNoticeResponse extends Response {
noticeList: Array<Notice>;
}
// 帖子信息响应
export interface ForumNewResponse extends Response {
forumList: Page<Forum>;
}

@ -31,7 +31,6 @@
"complaint": "time:{{time}}",
"plaintiff": "plaintiff",
"defendant": "defendant",
"load_posts": "Loading posts",
"notice_title": "notice title",
"notice_content": "notice content"
},
@ -92,14 +91,22 @@
},
"forum": {
"notice": {
"load_notices": "Loading advertising information",
"ok": "获取公告信息成功",
"fail": "获取公告信息失败",
"load_notices": "正在加载广告信息",
"add_ok": "添加成功",
"add_fail": "添加失败",
"fail": "获取失败",
"zero": "没有任何公告信息",
"delete": "删除公告信息",
"confirm_delete": "确认删除当前公告信息吗?",
"delete_ok": "删除成功",
"delete_fail": "删除失败"
},
"posts": {
"zero": "没有任何帖子需要审核",
"load_posts": "正在加载待审核帖子信息",
"fail": "获取失败",
"check_ok": "审核成功",
"check_fail": "审核失败"
}
}
}

@ -31,7 +31,6 @@
"complaint_time": "投诉时间:{{time}}",
"plaintiff": "投诉人",
"defendant": "被投诉人",
"load_posts": " 正在加载帖子信息",
"notice_title": "公告标题",
"notice_content": "公告内容"
},
@ -93,13 +92,21 @@
"forum": {
"notice": {
"load_notices": "正在加载广告信息",
"ok": "获取公告信息成功",
"fail": "获取公告信息失败",
"add_ok": "添加成功",
"add_fail": "添加失败",
"fail": "获取失败",
"zero": "没有任何公告信息",
"delete": "删除公告信息",
"confirm_delete": "确认删除当前公告信息吗?",
"delete_ok": "删除成功",
"delete_fail": "删除失败"
},
"posts": {
"zero": "没有任何帖子需要审核",
"load_posts": "正在加载待审核帖子信息",
"fail": "获取失败",
"check_ok": "审核成功",
"check_fail": "审核失败"
}
}
}

Loading…
Cancel
Save