This commit is contained in:
禾几海
2020-07-03 12:58:07 +08:00
parent efa1f0bee2
commit d800fa479b
3 changed files with 42 additions and 115 deletions

View File

@@ -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<Comment>[];
@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()
}
}
}