文章管理改用通用组件
This commit is contained in:
@@ -1,49 +1,70 @@
|
||||
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 {PageList} from '../../../class/HttpReqAndResp';
|
||||
import {RequestObj} from '../../../class/HttpReqAndResp';
|
||||
import {Article} from '../../../class/Article';
|
||||
import {Title} from '@angular/platform-browser';
|
||||
import {Data} from '../components/common-table/data';
|
||||
import {CommonTableComponent} from '../components/common-table/common-table.component';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-admin-article',
|
||||
templateUrl: './admin-article.component.html',
|
||||
styleUrls: ['./admin-article.component.less']
|
||||
templateUrl: './admin-article.component.html'
|
||||
})
|
||||
export class AdminArticleComponent implements OnInit {
|
||||
|
||||
constructor(private apiService: ApiService, private nzMessage: NzMessageService, private title: Title) {
|
||||
constructor(private apiService: ApiService, private nzMessage: NzMessageService, private title: Title,
|
||||
private router: Router) {
|
||||
this.request = {
|
||||
path: '/admin/articles',
|
||||
method: 'GET',
|
||||
queryParam: {
|
||||
page: 1,
|
||||
count: 10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
page: number = 1;
|
||||
pageSize: number = 10;
|
||||
|
||||
pageList: PageList<Article> = new PageList<Article>();
|
||||
|
||||
loading: boolean = true;
|
||||
request: RequestObj;
|
||||
headData: Data<Article>[]
|
||||
@ViewChild('commonTableComponent') private commonTableComponent: CommonTableComponent<Article>
|
||||
|
||||
ngOnInit(): void {
|
||||
this.title.setTitle('小海博客 | 文章管理')
|
||||
this.getArticle();
|
||||
this.headData = [
|
||||
{fieldName: '主键', fieldValue: 'id', show: false, primaryKey: true},
|
||||
{fieldName: '标题', fieldValue: 'title', show: true},
|
||||
{fieldName: '分类', fieldValue: 'category', show: true},
|
||||
{fieldName: '文章类型', fieldValue: 'original', show: true},
|
||||
{fieldName: '阅读量', fieldValue: 'readingNumber', show: true},
|
||||
{fieldName: '👍数', fieldValue: 'likeCount', show: true},
|
||||
{fieldName: '👎数', fieldValue: 'dislikeCount', show: true},
|
||||
{fieldName: '发布日期', fieldValue: 'publishDateFormat', show: true},
|
||||
{fieldName: '更新日期', fieldValue: 'updateDateFormat', show: true},
|
||||
{fieldName: '状态', fieldValue: 'open', show: true},
|
||||
{fieldName: '简介', fieldValue: 'summary', show: false},
|
||||
{fieldName: '作者', fieldValue: 'author.displayName', show: false},
|
||||
{fieldName: '标签数', fieldValue: 'tags.length', show: false},
|
||||
{
|
||||
fieldName: '操作', fieldValue: '', show: true, isActionColumns: true,
|
||||
action: [
|
||||
{name: '查看', click: (d) => this.router.navigateByUrl(`/article/${d.id}`)},
|
||||
{name: '删除', color: '#ff0000', needConfirm: true, click: (d) => this.deleteArticle(d)},
|
||||
{name: '编辑', color: '#2db7f5', click: (d) => this.router.navigateByUrl(`/write?id=${d.id}`)},
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
getArticle = () => this.apiService.adminArticles(this.page, this.pageSize).subscribe({
|
||||
next: data => this.pageList = data.result,
|
||||
complete: () => this.loading = false,
|
||||
error: err => this.loading = false
|
||||
})
|
||||
|
||||
deleteArticle(id) {
|
||||
this.loading = true;
|
||||
this.apiService.deleteArticle(id).subscribe({
|
||||
deleteArticle(article: Article) {
|
||||
this.apiService.deleteArticle(article.id).subscribe({
|
||||
next: data => {
|
||||
this.nzMessage.success('删除成功')
|
||||
this.loading = false;
|
||||
this.getArticle();
|
||||
this.commonTableComponent.getData();
|
||||
},
|
||||
error: err => {
|
||||
this.nzMessage.error(err.msg)
|
||||
this.loading = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user