From 82598c2bb5947c61dc9418c7ec22811468b54114 Mon Sep 17 00:00:00 2001 From: panqihua <1029559041@qq.com> Date: Fri, 13 Mar 2020 23:20:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BA=E5=9D=9B=E6=A8=A1=E5=9D=97=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=85=AC=E5=91=8A=E6=8E=A5=E5=8F=A3=20=E8=AE=BA?= =?UTF-8?q?=E5=9D=9B=E6=A8=A1=E5=9D=97=E5=A2=9E=E5=8A=A0=E5=B8=96=E5=AD=90?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/account/login/login.component.ts | 29 +++- src/app/account/login/login.service.ts | 64 +------- .../account/register/register.component.html | 2 +- src/app/app.component.ts | 24 ++- src/app/forum/forum.component.html | 149 ++++++++++-------- src/app/forum/forum.component.scss | 10 +- src/app/forum/forum.component.ts | 57 +++++-- src/app/forum/forum.service.spec.ts | 16 ++ src/app/forum/forum.service.ts | 53 +++++++ src/app/interface/ForumType.ts | 66 ++++++++ src/app/interface/HttpInterface.ts | 6 +- src/app/interface/Notice.ts | 10 ++ src/app/interface/Result.ts | 1 + src/assets/i18n/en-US.json | 7 +- src/assets/i18n/zh-CN.json | 6 +- 15 files changed, 345 insertions(+), 155 deletions(-) create mode 100644 src/app/forum/forum.service.spec.ts create mode 100644 src/app/forum/forum.service.ts create mode 100644 src/app/interface/ForumType.ts create mode 100644 src/app/interface/Notice.ts diff --git a/src/app/account/login/login.component.ts b/src/app/account/login/login.component.ts index fe948f6..4c6aba6 100644 --- a/src/app/account/login/login.component.ts +++ b/src/app/account/login/login.component.ts @@ -3,6 +3,10 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {Commons} from '../../commons'; import {Router} from '@angular/router'; import {LoginService} from './login.service'; +import {Result} from '../../interface/Result'; +import {environment} from '../../../environments/environment'; +import {CookieService} from 'ngx-cookie-service'; +import {MessageService} from '../../message/message.service'; @Component({ selector: 'app-login', @@ -20,7 +24,13 @@ export class LoginComponent extends Commons implements OnInit { }); - constructor(private fb: FormBuilder, private router: Router, private loginService: LoginService) { + constructor(private fb: FormBuilder, + private router: Router, + private loginService: LoginService, + private cookieService: CookieService, + private messageService: MessageService + + ) { super(); } @@ -33,11 +43,18 @@ export class LoginComponent extends Commons implements OnInit { console.debug(this.loginForm.value); // 发送登陆请求 - if (this.loginService.checkToken()) { - this.router.navigateByUrl('/forum'); - } else { - this.loginService.request(JSON.stringify(this.loginForm.value)); - } + this.loginService.login(JSON.stringify(this.loginForm.value)).subscribe(r => { + if (r.result === Result.OK) { + this.messageService.info('登陆成功'); + const time = new Date(); + time.setTime(r.body.useTime); + this.cookieService.set(environment.managerKey, r.body.managerName, time); + this.cookieService.set(environment.tokenKey, r.body.token, time); + this.router.navigateByUrl('/forum'); + } else { + this.messageService.danger('登陆失败'); + } + }); } diff --git a/src/app/account/login/login.service.ts b/src/app/account/login/login.service.ts index c047bd8..705bdc2 100644 --- a/src/app/account/login/login.service.ts +++ b/src/app/account/login/login.service.ts @@ -1,15 +1,10 @@ import {Injectable} from '@angular/core'; -import {CookieService} from 'ngx-cookie-service'; -import {Router} from '@angular/router'; -import {MessageService} from '../../message/message.service'; import {JSONRequest} from '../../interface/JSONRequest'; -import {environment} from '../../../environments/environment'; import {HttpClient} from '@angular/common/http'; import {HttpInterface} from '../../interface/HttpInterface'; import {JSONResponse} from '../../interface/JSONResponse'; import {catchError} from 'rxjs/operators'; -import {Result} from '../../interface/Result'; -import {Token} from '../../interface/vo/Token'; +import {Observable} from 'rxjs'; @Injectable({ providedIn: 'root' @@ -17,71 +12,28 @@ import {Token} from '../../interface/vo/Token'; export class LoginService extends JSONRequest { constructor( - private cookieService: CookieService, - private router: Router, - private messageService: MessageService, private http: HttpClient, ) { super(); } - /** - * 检查登陆令牌是否有效 - */ - checkToken(): boolean { - return this.cookieService.check(environment.tokenKey); - } - - /** - * 登陆 - */ - login(body: string) { - if (this.checkToken()) { - this.router.navigateByUrl('/forum'); - } else { - this.request(body); - } - } - /** * 注销登录 */ - logout() { - this.http.post>(HttpInterface.logout, {}, this.httpOptions) + logout(): Observable> { + return this.http.post>(HttpInterface.logout, {}, this.httpOptions) .pipe( catchError(this.handleError('注销')) - ) - .subscribe(r => { - if (r.result === Result.OK) { - this.cookieService.deleteAll(); - this.messageService.info('注销成功'); - this.router.navigateByUrl('/login'); - } else { - alert('注销失败'); - } - }); + ); } /** - * - * @param body 请求表单 + * 登陆 */ - request(body) { - this.http.post>(HttpInterface.login, body, this.httpOptions) + login(body): Observable> { + return this.http.post>(HttpInterface.login, body, this.httpOptions) .pipe( catchError(this.handleError('登陆')) - ) - .subscribe(r => { - if (r.result === Result.OK) { - this.messageService.info('登陆成功'); - const time = new Date(); - time.setTime(r.body.useTime); - this.cookieService.set(environment.managerKey, r.body.managerName, time); - this.cookieService.set(environment.tokenKey, r.body.token, time); - this.router.navigateByUrl('/forum'); - } else { - this.messageService.danger('登陆失败'); - } - }); + ); } } diff --git a/src/app/account/register/register.component.html b/src/app/account/register/register.component.html index 29a021a..16bec4c 100644 --- a/src/app/account/register/register.component.html +++ b/src/app/account/register/register.component.html @@ -89,7 +89,7 @@
- - + +
+ + +
+
+ Loading... +
+

{{'forum.load_posts'|translate}}

+
+
diff --git a/src/app/forum/forum.component.scss b/src/app/forum/forum.component.scss index 33a0584..90252d6 100644 --- a/src/app/forum/forum.component.scss +++ b/src/app/forum/forum.component.scss @@ -5,7 +5,7 @@ //公告正文边框 .notice-content { - height: 200px; + height: 230px; border-style: solid; border-width: 3px; } @@ -17,7 +17,7 @@ //公告底部 .notice-footer { - top: 145px; + top: 175px; bottom: 0; width: 100%; } @@ -101,5 +101,11 @@ margin-top: 50px; } +//加载进度 +.load{ + width: 5rem; + height: 5rem; +} + //投诉帖end diff --git a/src/app/forum/forum.component.ts b/src/app/forum/forum.component.ts index 90d86b4..31db1ba 100644 --- a/src/app/forum/forum.component.ts +++ b/src/app/forum/forum.component.ts @@ -2,6 +2,8 @@ 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'; /** * 论坛组件 @@ -16,14 +18,15 @@ export class ForumComponent implements OnInit { /** * 公告信息 */ - notices: [ - { - managerName: string; - content: string; - title: string, - createTime: number - } - ]; + notices: Array; + + /** + * 帖子信息 + */ + posts: Forum; + + // 激活帖子索引 + currentIndex = 0; constructor( private router: Router, @@ -31,6 +34,14 @@ export class ForumComponent implements OnInit { ) { } + getActive(): Active { + return this.posts.list[this.currentIndex] as Active; + } + + getComplaint(): Complaint { + return this.posts.list[this.currentIndex] as Complaint; + } + /** * 获取公告信息 */ @@ -39,14 +50,40 @@ export class ForumComponent implements OnInit { if (res.result === Result.OK) { console.debug('获取公告信息成功'); this.notices = res.body; - } else { - alert('获取公告信息失败'); } }); } + /** + * 获取所有帖子 + */ + 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); } } diff --git a/src/app/forum/forum.service.spec.ts b/src/app/forum/forum.service.spec.ts new file mode 100644 index 0000000..551e1e1 --- /dev/null +++ b/src/app/forum/forum.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ForumService } from './forum.service'; + +describe('ForumService', () => { + let service: ForumService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ForumService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/forum/forum.service.ts b/src/app/forum/forum.service.ts new file mode 100644 index 0000000..edb11e5 --- /dev/null +++ b/src/app/forum/forum.service.ts @@ -0,0 +1,53 @@ +import { Injectable } from '@angular/core'; +import {HttpClient} from '@angular/common/http'; +import {JSONResponse} from '../interface/JSONResponse'; +import {HttpInterface} from '../interface/HttpInterface'; +import {JSONRequest} from '../interface/JSONRequest'; +import {Observable} from 'rxjs'; +import {catchError} from 'rxjs/operators'; + +/** + * 论坛服务 + */ +@Injectable({ + providedIn: 'root' +}) +export class ForumService extends JSONRequest { + + constructor( + private http: HttpClient + ) { + super(); + } + + + /** + * 获取公告信息 + */ + getAllNotices(): Observable> { + return this.http.get>(HttpInterface.getAllNotices, this.httpOptions) + .pipe( + catchError(this.handleError('获取公告信息')) + ); + } + + /** + * 获取所有帖子 + */ + getAllPosts(page): Observable> { + return this.http.get>(HttpInterface.getAllPosts + '/' + page, this.httpOptions) + .pipe( + catchError(this.handleError('获取帖子')) + ); + } + + /** + * 审核帖子 + */ + checkPost(id, s): Observable> { + return this.http.patch>(HttpInterface.checkPost + '/' + id, { status : s}, this.httpOptions) + .pipe( + catchError(this.handleError('审核帖子')) + ); + } +} diff --git a/src/app/interface/ForumType.ts b/src/app/interface/ForumType.ts new file mode 100644 index 0000000..0568ff1 --- /dev/null +++ b/src/app/interface/ForumType.ts @@ -0,0 +1,66 @@ +// 帖子类型 +export enum ForumType { + active= 'active', + complaint= 'complaint' +} + +// 活动帖 +export interface Active { + // 活动帖 + // 帖子类型 + type: ForumType; + // 帖子ID + id: number; + // 发帖人 + issuer: string; + // 头像 + headImg: string; + // 用户信用分 + userCreditScore: number; + // 帖子标题 + title: string; + // 帖子内容 + content: string; + // 活动开始时间 + startTime: number; + // 活动结束时间 + endTime: number; + // 活动奖励分 + activeCreditScore: 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; +} + +export interface Forum { + list: Array; + page: { + count: number; + page: number; + currentPage: number; + }; +} + diff --git a/src/app/interface/HttpInterface.ts b/src/app/interface/HttpInterface.ts index c84c56e..026c5e0 100644 --- a/src/app/interface/HttpInterface.ts +++ b/src/app/interface/HttpInterface.ts @@ -19,7 +19,11 @@ const HttpInterface = { // 重置密码 resetPwd: '/api/manager/reset/resetPwd', // 获取所有公告 - getAllNotices: '/api/forum/notices' + getAllNotices: '/api/forum/notices', + // 获取所有帖子 + getAllPosts: '/api/forum/posts', + // 审核帖子 + checkPost: '/api/forum/posts' }; for (const key of Object.keys(HttpInterface)) { diff --git a/src/app/interface/Notice.ts b/src/app/interface/Notice.ts new file mode 100644 index 0000000..c154132 --- /dev/null +++ b/src/app/interface/Notice.ts @@ -0,0 +1,10 @@ +export interface Notice { + // 公告人 + managerName: string; + // 公告内容 + content: string; + // 公告标题 + title: string; + // 公告时间 + createTime: number; +} diff --git a/src/app/interface/Result.ts b/src/app/interface/Result.ts index 30f4e6c..dfcac71 100644 --- a/src/app/interface/Result.ts +++ b/src/app/interface/Result.ts @@ -1,3 +1,4 @@ +// 返回结果 export enum Result { OK = 'OK', FAIL = 'FAIL' diff --git a/src/assets/i18n/en-US.json b/src/assets/i18n/en-US.json index d432d13..7aae835 100644 --- a/src/assets/i18n/en-US.json +++ b/src/assets/i18n/en-US.json @@ -28,11 +28,14 @@ "active_score": "Active Score:{{score}}", "approve": "approve", "reject": "reject", - "complaint": "time:{{time}}" + "complaint": "time:{{time}}", + "plaintiff": "plaintiff", + "defendant": "defendant", + "load_notices": "Loading advertising information" }, "tip":{ "input": "please input {{value}}", - "HELLO": "Hello {{value}} welcome to you", + "HELLO": "Hello {{value}} welcome to you", "notnull": "The {{value}} cannot be empty", "password_diff": "The passwords do not match", "mobile_error": "The phone number is illegal", diff --git a/src/assets/i18n/zh-CN.json b/src/assets/i18n/zh-CN.json index 04d32a6..f10e8e8 100644 --- a/src/assets/i18n/zh-CN.json +++ b/src/assets/i18n/zh-CN.json @@ -28,7 +28,11 @@ "active_score": "参与活动奖励信用分:{{score}}", "approve": "审核通过", "reject": "审核不通过", - "complaint_time": "投诉时间:{{time}}" + "complaint_time": "投诉时间:{{time}}", + "plaintiff": "投诉人", + "defendant": "被投诉人", + "load_notices": "正在加载广告信息", + "load_posts": " 正在加载帖子信息" }, "tip":{ "input": "请输入{{value}}",