From d800fa479bfece2686f28427ff99a4b8b1eff64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BE=E5=87=A0=E6=B5=B7?= Date: Fri, 3 Jul 2020 12:58:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin-comment.component.html | 56 +------------- .../admin-comment/admin-comment.component.ts | 73 +++++++------------ .../test-common-table.component.ts | 28 +++---- 3 files changed, 42 insertions(+), 115 deletions(-) diff --git a/src/app/view/admin/admin-comment/admin-comment.component.html b/src/app/view/admin/admin-comment/admin-comment.component.html index 259aa70..594422c 100644 --- a/src/app/view/admin/admin-comment/admin-comment.component.html +++ b/src/app/view/admin/admin-comment/admin-comment.component.html @@ -1,55 +1,3 @@ - - @@ -59,6 +7,6 @@ {{value}} - - + + diff --git a/src/app/view/admin/admin-comment/admin-comment.component.ts b/src/app/view/admin/admin-comment/admin-comment.component.ts index e7250e8..80d68d9 100644 --- a/src/app/view/admin/admin-comment/admin-comment.component.ts +++ b/src/app/view/admin/admin-comment/admin-comment.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, OnInit, ViewChild} from '@angular/core'; import {NzMessageService} from 'ng-zorro-antd'; import {ApiService} from '../../../api/api.service'; import {RequestObj} from '../../../class/HttpReqAndResp'; @@ -6,6 +6,7 @@ import {Comment, CommentReq} from '../../../class/Comment'; import {GlobalUserService} from '../../../services/global-user.service'; import {Title} from '@angular/platform-browser'; import {Data} from '../components/common-table/data'; +import {EditableTagComponent} from '../components/editable-tag/editable-tag.component'; @Component({ selector: 'app-admin-comment', @@ -16,22 +17,22 @@ export class AdminCommentComponent implements OnInit { constructor(private apiService: ApiService, private messageService: NzMessageService, private userService: GlobalUserService, private title: Title) { this.title.setTitle('小海博客 | 评论管理') - this.request = { - // path: `/admin/comment/pagePath/${pagePath}`, - path: null, - method: 'GET', - queryParam: { - page: 1, - count: 10 - } - } this.userService.watchUserInfo({ next: data => { + let pathStr; if (data.result) { if (data.result.role === 'admin') { - this.request.path = '/admin/comment/pagePath/*' + pathStr = '/admin/comment/pagePath/*' } else { - this.request.path = '/user/comment/pagePath/*' + pathStr = '/user/comment/pagePath/*' + } + this.request = { + path: pathStr, + method: 'GET', + queryParam: { + page: 1, + count: 10 + } } } }, @@ -44,9 +45,9 @@ export class AdminCommentComponent implements OnInit { editInfo = { id: null, content: new CommentReq(null), - editFocus: false, } headData: Data[]; + @ViewChild('editableTagComponent') editableTagComponent: EditableTagComponent; ngOnInit(): void { this.headData = [ @@ -66,38 +67,20 @@ export class AdminCommentComponent implements OnInit { action: [ {name: '查看', click: data => console.log(data)}, {name: '删除', color: 'red', click: data => this.deleteComment(data), needConfirm: true}, - {name: '编辑', color: '#2db7f5', click: data => this.edit(data)}, + {name: '编辑', color: '#2db7f5', click: data => this.editableTagComponent.getFocus(data.id)}, ] } ]; } - - // // TODO:: pagePath - // getCommentForAdmin = () => this.apiService.getCommentByTypeForAdmin('*', this.pageIndex, this.pageSize).subscribe({ - // next: data => this.pageList = data.result, - // complete: () => this.loading = false, - // error: err => this.loading = false - // }) - - // getCommentForUser = () => this.apiService.getCommentByTypeForUser('*', this.pageIndex, this.pageSize).subscribe({ - // next: data => this.pageList = data.result, - // complete: () => this.loading = false, - // error: err => this.loading = false - // }) - deleteComment(data: Comment) { this.apiService.deleteComment(data.id).subscribe({ - next: () => { - this.messageService.success('删除评论成功'); - }, - error: err => { - this.messageService.error(err.msg); - } + next: () => this.messageService.success('删除评论成功'), + error: err => this.messageService.error(err.msg) }) } - edit(comment: Comment) { + edit() { this.apiService.updateComment(this.editInfo.content).subscribe({ next: data => { this.messageService.success('更新评论成功'); @@ -109,17 +92,13 @@ export class AdminCommentComponent implements OnInit { }) } - 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; - } - - textChange(value: { value: string; originalValue: string; changed: boolean }) { - console.log(value) + textChange(value: { value: string; originalValue: string; changed: boolean }, data: Comment) { + if (value.changed) { + this.editInfo.id = data.id; + this.editInfo.content.pid = data.pid; + this.editInfo.content.id = data.id; + this.editInfo.content.content = value.value; + this.edit() + } } } diff --git a/src/app/view/admin/test-common-table/test-common-table.component.ts b/src/app/view/admin/test-common-table/test-common-table.component.ts index 035aae1..dff7dd0 100644 --- a/src/app/view/admin/test-common-table/test-common-table.component.ts +++ b/src/app/view/admin/test-common-table/test-common-table.component.ts @@ -28,21 +28,21 @@ updateDateFormat: "2020-05-27 00:55:05"*/ constructor() { this.data = [ - {fieldName: '主键', fieldValue: 'id', show: false, primaryKey: true}, - {fieldName: '标题', fieldValue: 'title', show: true}, - {fieldName: '发布日期', fieldValue: 'publishDateFormat', show: true}, - {fieldName: '更新日期', fieldValue: 'updateDateFormat', show: true}, - {fieldName: '文章类型', fieldValue: 'original', show: true}, - {fieldName: '阅读量', fieldValue: 'readingNumber', show: true}, - {fieldName: '分类', fieldValue: 'category', show: true}, - {fieldName: '👎数', fieldValue: 'dislikeCount', show: true}, - {fieldName: '👍数', fieldValue: 'likeCount', show: true}, - {fieldName: '状态', fieldValue: 'open', show: true}, - {fieldName: '简介', fieldValue: 'summary', show: false}, - {fieldName: '作者', fieldValue: 'author.displayName', show: true}, - {fieldName: '标签数', fieldValue: 'tags.length', show: true}, + {title: '主键', fieldValue: 'id', show: false, primaryKey: true}, + {title: '标题', fieldValue: 'title', show: true}, + {title: '发布日期', fieldValue: 'publishDateFormat', show: true}, + {title: '更新日期', fieldValue: 'updateDateFormat', show: true}, + {title: '文章类型', fieldValue: 'original', show: true}, + {title: '阅读量', fieldValue: 'readingNumber', show: true}, + {title: '分类', fieldValue: 'category', show: true}, + {title: '👎数', fieldValue: 'dislikeCount', show: true}, + {title: '👍数', fieldValue: 'likeCount', show: true}, + {title: '状态', fieldValue: 'open', show: true}, + {title: '简介', fieldValue: 'summary', show: false}, + {title: '作者', fieldValue: 'author.displayName', show: true}, + {title: '标签数', fieldValue: 'tags.length', show: true}, { - fieldName: '操作', fieldValue: '', show: true, isActionColumns: true, + title: '操作', fieldValue: '', show: true, isActionColumns: true, action: [ { name: '新增',