From 4571d52e5d8c232e3cf6602d5c33cdb7e0cfb914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=B5=B7?= Date: Sat, 16 May 2020 15:41:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index/src/app/class/Comment.ts | 3 +- .../admin-comment.component.html | 41 +++++++++- .../admin-comment.component.less | 3 + .../admin-comment/admin-comment.component.ts | 76 +++++++++++++++++-- .../admin-comment/admin-comment.module.ts | 22 +++++- index/src/app/view/admin/auth.guard.ts | 2 +- 6 files changed, 136 insertions(+), 11 deletions(-) diff --git a/index/src/app/class/Comment.ts b/index/src/app/class/Comment.ts index 3637817..449e558 100644 --- a/index/src/app/class/Comment.ts +++ b/index/src/app/class/Comment.ts @@ -4,6 +4,7 @@ export class Comment { authorAvatarImgUrl?: string; content: string; articleID: number; + articleTitle: string; date?: string; responseId: string; pid: number; @@ -29,4 +30,4 @@ export class CommentReq { this.pid = -1; this.id = null; } -} \ No newline at end of file +} diff --git a/index/src/app/view/admin/admin-comment/admin-comment.component.html b/index/src/app/view/admin/admin-comment/admin-comment.component.html index e4e9602..1cdd02d 100644 --- a/index/src/app/view/admin/admin-comment/admin-comment.component.html +++ b/index/src/app/view/admin/admin-comment/admin-comment.component.html @@ -1 +1,40 @@ -

admin-comment works!

+
+ + + + 文章标题 + 评论内容 + 评论日期 + 操作 + + + + {{data.articleTitle}} + + {{data.content}} + + + + + + + {{data.date}} + + 编辑 + + 删除 + + + + + +
+ diff --git a/index/src/app/view/admin/admin-comment/admin-comment.component.less b/index/src/app/view/admin/admin-comment/admin-comment.component.less index e69de29..35aa4ab 100644 --- a/index/src/app/view/admin/admin-comment/admin-comment.component.less +++ b/index/src/app/view/admin/admin-comment/admin-comment.component.less @@ -0,0 +1,3 @@ +td { + max-width: 300px; +} diff --git a/index/src/app/view/admin/admin-comment/admin-comment.component.ts b/index/src/app/view/admin/admin-comment/admin-comment.component.ts index 521c388..c7804f3 100644 --- a/index/src/app/view/admin/admin-comment/admin-comment.component.ts +++ b/index/src/app/view/admin/admin-comment/admin-comment.component.ts @@ -1,15 +1,77 @@ -import { Component, OnInit } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; +import {NzMessageService} from 'ng-zorro-antd'; +import {ApiService} from '../../../api/api.service'; +import {PageList} from '../../../class/HttpReqAndResp'; +import {Comment, CommentReq} from '../../../class/Comment'; @Component({ - selector: 'app-admin-comment', - templateUrl: './admin-comment.component.html', - styleUrls: ['./admin-comment.component.less'] + selector: 'app-admin-comment', + templateUrl: './admin-comment.component.html', + styleUrls: ['./admin-comment.component.less'] }) export class AdminCommentComponent implements OnInit { - constructor() { } + constructor(private apiService: ApiService, private messageService: NzMessageService) { + } - ngOnInit(): void { - } + loading: boolean = true; + pageIndex: number = 1; + pageSize: number = 10; + pageList: PageList = new PageList(); + editInfo = { + id: null, + content: new CommentReq(true), + editFocus: false, + } + ngOnInit(): void { + this.getComment(); + } + + getComment = () => this.apiService.getCommentByTypeForAdmin(true, this.pageIndex, this.pageSize).subscribe({ + next: data => this.pageList = data.result, + complete: () => this.loading = false, + error: err => this.loading = false + }) + + deleteComment(id: number) { + this.loading = true; + this.apiService.deleteComment(id).subscribe({ + next: () => { + this.messageService.success('删除评论成功'); + this.getComment(); + }, + error: err => { + this.loading = false; + this.messageService.success(err.msg); + }, + complete: () => this.loading = false + }) + } + + edit() { + this.editInfo.editFocus = false; + this.loading = true; + this.apiService.updateComment(this.editInfo.content).subscribe({ + next: data => { + this.messageService.success('更新评论成功'); + this.getComment(); + }, + error: err => { + this.loading = false; + this.messageService.success(err.msg); + }, + complete: () => this.loading = false + }) + } + + editFocus(data: Comment) { + this.editInfo.id = data.id; + this.editInfo.content.content = data.content; + this.editInfo.content.id = data.id; + this.editInfo.content.articleID = data.articleID; + this.editInfo.content.pid = data.pid; + this.editInfo.content.responseId = data.responseId; + this.editInfo.editFocus = true; + } } diff --git a/index/src/app/view/admin/admin-comment/admin-comment.module.ts b/index/src/app/view/admin/admin-comment/admin-comment.module.ts index d65a619..b070182 100644 --- a/index/src/app/view/admin/admin-comment/admin-comment.module.ts +++ b/index/src/app/view/admin/admin-comment/admin-comment.module.ts @@ -2,6 +2,16 @@ import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; import {RouterModule} from '@angular/router'; import {AdminCommentComponent} from './admin-comment.component'; +import { + NzButtonModule, + NzCardModule, + NzDividerModule, NzIconModule, NzInputModule, + NzPopconfirmModule, + NzTableModule, + NzToolTipModule, + NzTypographyModule +} from 'ng-zorro-antd'; +import {FormsModule} from '@angular/forms'; @NgModule({ @@ -10,7 +20,17 @@ import {AdminCommentComponent} from './admin-comment.component'; ], imports: [ CommonModule, - RouterModule.forChild([{path: '', component: AdminCommentComponent}]) + RouterModule.forChild([{path: '', component: AdminCommentComponent}]), + NzCardModule, + NzTableModule, + NzDividerModule, + NzPopconfirmModule, + NzTypographyModule, + NzToolTipModule, + NzInputModule, + FormsModule, + NzIconModule, + NzButtonModule ] }) export class AdminCommentModule { diff --git a/index/src/app/view/admin/auth.guard.ts b/index/src/app/view/admin/auth.guard.ts index fb7cd72..e0ec194 100644 --- a/index/src/app/view/admin/auth.guard.ts +++ b/index/src/app/view/admin/auth.guard.ts @@ -10,7 +10,7 @@ import {GlobalUserService} from '../../services/global-user.service'; export class AuthGuard implements CanActivate { constructor(private userService: GlobalUserService, private router: Router) { - this.userService.refreshUserInfo(); + // this.userService.refreshUserInfo(); } userInfo: User;