diff --git a/src/app/account/login/login.component.ts b/src/app/account/login/login.component.ts index 4f8b18c..7f4891c 100644 --- a/src/app/account/login/login.component.ts +++ b/src/app/account/login/login.component.ts @@ -35,7 +35,6 @@ export class LoginComponent extends Commons implements OnInit, MessageInterface } ngOnInit(): void { - } // 登陆方法 diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 8643143..2651197 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -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'); + } } }); diff --git a/src/app/forum/forum.component.html b/src/app/forum/forum.component.html index c910588..1d9e6a4 100644 --- a/src/app/forum/forum.component.html +++ b/src/app/forum/forum.component.html @@ -1,7 +1,7 @@

{{'server.forum.notice.zero'|translate}}

+ class="text-center col-12 m-3">{{prefix('notice.zero')|translate}} @@ -70,123 +70,175 @@

{{ 'forum.check' | translate }}

- -
+ +

{{prefix('posts.zero')|translate}}

+ + + - - + +
-
+ - -
+ - - + + + +
+ + headimg + +
+ {{getForum().username}} +
+ +
+ {{getForum().info.creditScore}} +
+
- -
- - headimg - -
- {{getActive().issuer}} -
- -
- {{getActive().userCreditScore}} -
-
+ +
+ +

{{getForum().title}}

+ +
+ {{getForum().content}} +
+ + +
+
+ + + +
+ +
+ + +
+
{{'forum.plaintiff'|translate}}
+ +
+ headimg +
+
{{getForum().username}}
+
{{getForum().info.creditScore}}
+
- -
- -

{{getActive().title}}

- -
- {{getActive().content}} -
- - -
+ +
+
{{'forum.defendant'|translate}}
+
+ + headimg +
+
{{getComplaint().complain}}
+
{{getComplaint().info.creditScore}}
+
- - - -
+
-
- -
-
{{'forum.plaintiff'|translate}}
- -
- headimg + +
+ +

{{getForum().title}}

+ +
+ {{getForum().content}} +
+ +

{{ 'forum.complaint_time' | translate:{time: getForum().time|date:'yyyy-MM-dd'} }}

+
+
+ + + + +
+ + headimg + +
+ {{getForum().username}} +
+ +
+ {{getForum().info.creditScore}} +
-
{{getComplaint().plaintiffName}}
-
{{getComplaint().plaintiffCreditScore}}
-
- -
-
{{'forum.defendant'|translate}}
-
- - headimg + +
+ +

{{getForum().title}}

+ +
+ {{getForum().content}} +
-
{{getComplaint().defendantName}}
-
{{getComplaint().defendantCreditScore}}
-
+ + + +
+ +
- - -
- -

{{getComplaint().title}}

- -
- {{getComplaint().content}} -
- -

{{ 'forum.complaint_time' | translate:{time: getComplaint().time|date:'yyyy-MM-dd'} }}

-
- - -
- - -
-
+
- +
Loading...
-

{{'forum.load_posts'|translate}}

+

{{this.prefix('posts.' + loadPostsStatus)|translate}}

diff --git a/src/app/forum/forum.component.ts b/src/app/forum/forum.component.ts index 4e2b111..7c339e5 100644 --- a/src/app/forum/forum.component.ts +++ b/src/app/forum/forum.component.ts @@ -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; } } diff --git a/src/app/forum/forum.service.ts b/src/app/forum/forum.service.ts index c12ccde..57ae0ea 100644 --- a/src/app/forum/forum.service.ts +++ b/src/app/forum/forum.service.ts @@ -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> { - return this.http.get>(HttpInterface.getAllPosts + '/' + page, this.httpOptions) + getAllPosts(page): Observable { + return this.http.get(HttpInterface.getAllPosts, Object.assign(this.httpOptions, { + params: { + currentPage: page, + status: ForumStatus.uncheck + } + })) .pipe( catchError(this.handleError('获取帖子')) ); @@ -33,8 +40,11 @@ export class ForumService extends JSONRequest { /** * 审核帖子 */ - checkPost(id, s): Observable> { - return this.http.patch>(HttpInterface.checkPost + '/' + id, { status : s}, this.httpOptions) + checkPost($id, $status): Observable> { + return this.http.post>(HttpInterface.checkPost, { + id: $id, + status: $status + }, this.httpOptions) .pipe( catchError(this.handleError('审核帖子')) ); diff --git a/src/app/forum/notice/notice.component.ts b/src/app/forum/notice/notice.component.ts index cf69623..e851a40 100644 --- a/src/app/forum/notice/notice.component.ts +++ b/src/app/forum/notice/notice.component.ts @@ -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; } diff --git a/src/app/interface/ForumType.ts b/src/app/interface/ForumType.ts index 0568ff1..8987b6e 100644 --- a/src/app/interface/ForumType.ts +++ b/src/app/interface/ForumType.ts @@ -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; - page: { - count: number; - page: number; - currentPage: number; - }; + // 投诉人详情信息 + info: Info; } - diff --git a/src/app/interface/HttpInterface.ts b/src/app/interface/HttpInterface.ts index f2f4225..8f1455d 100644 --- a/src/app/interface/HttpInterface.ts +++ b/src/app/interface/HttpInterface.ts @@ -23,7 +23,7 @@ const HttpInterface = { // 获取所有帖子 getAllPosts: '/api/forum/posts', // 审核帖子 - checkPost: '/api/forum/posts', + checkPost: '/api/forum/posts/check', // 添加公告 addNotice: '/api/forum/notice/add', // 删除公告 diff --git a/src/app/interface/Info.ts b/src/app/interface/Info.ts new file mode 100644 index 0000000..10f7517 --- /dev/null +++ b/src/app/interface/Info.ts @@ -0,0 +1,19 @@ +// 用户信息 +export interface Info { + // 用户名 + username: string; + // 信用分 + creditScore: number; + // 头像 + headImg: string; + // 最近发帖数 + recentPosts: number; + // 最近访客数 + recentVisitors: number; + // 手机号 + mobie: string; + // 邮箱 + email: string; + // 信用分历史记录 + scoreHistory: Array; +} diff --git a/src/app/interface/Page.ts b/src/app/interface/Page.ts new file mode 100644 index 0000000..ce821c0 --- /dev/null +++ b/src/app/interface/Page.ts @@ -0,0 +1,8 @@ +export interface Page { + count: number; + totalPage: number; + currentPage: number; + list: Array; + pageSize: number; + empty: boolean; +} diff --git a/src/app/interface/Response.ts b/src/app/interface/Response.ts index 21534f8..064ea89 100644 --- a/src/app/interface/Response.ts +++ b/src/app/interface/Response.ts @@ -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; } + +// 帖子信息响应 +export interface ForumNewResponse extends Response { + forumList: Page; +} diff --git a/src/assets/i18n/en-US.json b/src/assets/i18n/en-US.json index eda77f9..1d36d5f 100644 --- a/src/assets/i18n/en-US.json +++ b/src/assets/i18n/en-US.json @@ -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": "审核失败" } } } diff --git a/src/assets/i18n/zh-CN.json b/src/assets/i18n/zh-CN.json index 4d8403f..b72ee51 100644 --- a/src/assets/i18n/zh-CN.json +++ b/src/assets/i18n/zh-CN.json @@ -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": "审核失败" } } }