公共组件 #18

Merged
xiaohai2271 merged 45 commits from dev into master 2020-07-11 10:41:50 +08:00
4 changed files with 80 additions and 100 deletions
Showing only changes of commit 3330d0a090 - Show all commits

View File

@@ -1,61 +1,32 @@
<div class="inner-content">
<nz-card nzTitle="文章管理" nzSize="small" [nzExtra]="reload">
<nz-table #table [nzData]="pageList.list"
[nzTotal]="pageList.total"
[(nzPageIndex)]="page"
[nzPageSize]="pageSize"
[nzLoading]="loading"
[nzScroll]="{x:'1100px'}"
(nzPageIndexChange)="getArticle()"
nzFrontPagination="false"
nzTableLayout="fixed">
<thead>
<th>标题</th>
<th>发布日期</th>
<th>更新日期</th>
<th>文章类型</th>
<th>阅读量</th>
<th>👍赞</th>
<th>👎踩</th>
<th>是否可见</th>
<th>操作</th>
</thead>
<tbody>
<tr *ngFor="let data of table.data">
<td nz-typography nzEllipsis="true" [nzTooltipTitle]="data.title" nzTooltipPlacement="right"
nz-tooltip>{{data.title}}</td>
<td>{{data.publishDateFormat}}</td>
<td>{{data.updateDateFormat}}</td>
<td>
<nz-tag nzColor="green" *ngIf="data.original">原创</nz-tag>
<nz-tag nzColor="#ff5500" *ngIf="!data.original">转载</nz-tag>
</td>
<td>
<nz-tag [nzColor]="'purple'">{{data.readingNumber}}</nz-tag>
</td>
<td>
<nz-tag [nzColor]="'blue'">{{data.likeCount}}</nz-tag>
</td>
<td>
<nz-tag [nzColor]="'magenta'">{{data.dislikeCount}}</nz-tag>
</td>
<td><input type="checkbox" [checked]="data.open" disabled></td>
<td>
<a routerLink="/write" [queryParams]="{id:data.id}" class="edit-opr">编辑</a>
<nz-divider nzType="vertical"></nz-divider>
<a [routerLink]="'/article'+data.id" class="show-opr">查看</a>
<nz-divider nzType="vertical"></nz-divider>
<a nz-popconfirm nzPopconfirmTitle="确定要删除这篇文章吗?" nzOkText="删除" nzCancelText="点错了"
(nzOnConfirm)="deleteArticle(data.id)" class="del-opr">删除</a>
</td>
</tr>
</tbody>
<c-common-table cardTitle="文章管理"
#commonTableComponent
[data]="headData"
[request]="request"
[template]="{
original:{temp:original,param:{true:'原创',false:'转载'}},
readingNumber:{temp:readingNumber},
likeCount:{temp:likeCount},
dislikeCount:{temp:dislikeCount},
open:{temp:open}
}">
</c-common-table>
<ng-template #reload>
<a (click)="getArticle()" title="刷新"><i nz-icon nzType="reload" nzTheme="outline"></i></a>
</ng-template>
</nz-table>
</nz-card>
</div>
<ng-template let-value="value" let-originValue="originValue" #original>
<nz-tag [nzColor]="originValue?'green':'#ff5500'">{{value}}</nz-tag>
</ng-template>
<ng-template let-value="value" #readingNumber>
<nz-tag nzColor="purple">{{value}}</nz-tag>
</ng-template>
<ng-template let-value="value" #likeCount>
<nz-tag nzColor="blue">{{value}}</nz-tag>
</ng-template>
<ng-template let-value="value" #dislikeCount>
<nz-tag nzColor="magenta">{{value}}</nz-tag>
</ng-template>
<ng-template #open let-value="value">
<label nz-checkbox nzDisabled [ngModel]="value"></label>
</ng-template>

View File

@@ -1,3 +0,0 @@
td {
max-width: 200px;
}

View File

@@ -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
}
})
}

View File

@@ -2,14 +2,9 @@ import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {RouterModule} from '@angular/router';
import {AdminArticleComponent} from './admin-article.component';
import {
NzCardModule,
NzDividerModule, NzIconModule,
NzPopconfirmModule,
NzTableModule, NzTagModule,
NzToolTipModule,
NzTypographyModule
} from 'ng-zorro-antd';
import {CommonTableModule} from '../components/common-table/common-table.module';
import {FormsModule} from '@angular/forms';
import {NzCheckboxModule, NzTagModule} from 'ng-zorro-antd';
@NgModule({
declarations: [
@@ -18,14 +13,10 @@ import {
imports: [
CommonModule,
RouterModule.forChild([{path: '', component: AdminArticleComponent}]),
NzTableModule,
NzTypographyModule,
NzToolTipModule,
NzCardModule,
NzDividerModule,
NzPopconfirmModule,
CommonTableModule,
FormsModule,
NzTagModule,
NzIconModule,
NzCheckboxModule,
]
})
export class AdminArticleModule {