合并为一个项目 #14

Merged
xiaohai2271 merged 56 commits from issue11 into master 2020-05-16 22:35:08 +08:00
5 changed files with 154 additions and 9 deletions
Showing only changes of commit adaa54b7ec - Show all commits

View File

@@ -527,6 +527,17 @@ export class ApiService extends HttpService {
});
}
webUpdatePage(pageSize: number = 10, pageNumber: number = 1) {
return super.Service<PageList<{ id: number, info: string, time: string }>>({
path: '/webUpdate/pages',
method: 'GET',
queryParam: {
count: pageSize,
page: pageNumber,
}
});
}
lastestUpdate() {
return super.Service<{
lastUpdateTime: string;

View File

@@ -1 +1,32 @@
<p>admin-update works!</p>
<div class="inner-content">
<nz-card nzTitle="更新内容管理" nzSize="small">
<button nz-button (click)="showModal()" style="margin-bottom: 15px;">新增</button>
<nz-table #table [nzData]="pageList.list" [nzTotal]="pageList.total" [(nzPageIndex)]="pageIndex"
[nzPageSize]="pageSize" [nzLoading]="loading"
(nzPageIndexChange)="getUpdateInfo()" nzFrontPagination="false">
<thead>
<th>更新内容</th>
<th>更新日期</th>
<th>操作</th>
</thead>
<tbody>
<tr *ngFor="let data of table.data">
<td nz-typography nzEllipsis="true" [nzTooltipTitle]="data.info" nzTooltipPlacement="top"
nz-tooltip>{{data.info}}</td>
<td>{{data.time}}</td>
<td>
<a (click)="showModal(data)" class="edit-opr">编辑</a>
<nz-divider nzType="vertical"></nz-divider>
<a nz-popconfirm nzPopconfirmTitle="确定要删除这个更新吗?" nzOkText="删除" nzCancelText="点错了"
(nzOnConfirm)="deleteUpdateInfo(data.id)" class="del-opr">删除</a>
</td>
</tr>
</tbody>
</nz-table>
</nz-card>
</div>
<nz-modal [(nzVisible)]="modalData.visible" [nzClosable]="true" (nzOnCancel)="modalData.visible = false"
(nzOnOk)="confirm()" [nzTitle]="modalData.title">
<textarea nz-input [(ngModel)]="modalData.content" [nzAutosize]="{ minRows: 2, maxRows: 8 }"></textarea>
</nz-modal>

View File

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

View File

@@ -1,4 +1,10 @@
import {Component, OnInit} from '@angular/core';
import {NzMessageService} from 'ng-zorro-antd';
import {Title} from '@angular/platform-browser';
import {Observable} from 'rxjs';
import {ApiService} from '../../../api/api.service';
import {PageList, Response} from '../../../class/HttpReqAndResp';
import {UpdateInfo} from '../../../class/UpdateInfo';
@Component({
selector: 'app-admin-update',
@@ -7,9 +13,83 @@ import { Component, OnInit } from '@angular/core';
})
export class AdminUpdateComponent implements OnInit {
constructor() { }
constructor(private apiService: ApiService, private nzMessage: NzMessageService, private title: Title) {
}
pageIndex: number = 1;
pageSize: number = 10;
pageList: PageList<UpdateInfo> = new PageList();
loading: boolean = true;
modalData = {
visible: false,
content: null,
id: null,
title: null
};
ngOnInit(): void {
this.title.setTitle('小海博客 | 更新信息管理')
this.getUpdateInfo();
}
getUpdateInfo = () => this.apiService.webUpdatePage(this.pageSize, this.pageIndex).subscribe({
next: data => this.pageList = data.result,
complete: () => this.loading = false,
error: err => this.loading = false
})
deleteUpdateInfo(id) {
this.loading = true;
this.apiService.deleteWebUpdateInfo(id).subscribe({
next: data => {
this.nzMessage.success('删除成功')
this.loading = false;
this.getUpdateInfo();
},
error: err => {
this.nzMessage.error(err.msg)
this.loading = false
}
})
}
confirm() {
this.loading = true;
this.modalData.visible = false;
let observable: Observable<Response<UpdateInfo>>
if (this.modalData.id) {
observable = this.apiService.updateWebUpdateInfo(this.modalData.id, this.modalData.content)
} else {
observable = this.apiService.createWebUpdateInfo(this.modalData.content)
}
observable.subscribe({
next: data => {
this.nzMessage.success('操作成功')
this.loading = false;
this.getUpdateInfo();
},
error: err => {
this.nzMessage.error(err.msg)
this.loading = false
}
})
console.log(this.modalData);
}
showModal(data?: UpdateInfo) {
this.modalData.id = null;
this.modalData.title = '新增更新信息';
this.modalData.content = null;
if (data) {
this.modalData.id = data.id;
this.modalData.content = data.info;
this.modalData.title = '编辑更新信息';
}
this.modalData.visible = true;
}
}

View File

@@ -2,6 +2,16 @@ import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {RouterModule} from '@angular/router';
import {AdminUpdateComponent} from './admin-update.component';
import {
NzButtonModule,
NzCardModule,
NzDividerModule, NzInputModule, NzModalModule,
NzPopconfirmModule,
NzTableModule,
NzToolTipModule,
NzTypographyModule
} from 'ng-zorro-antd';
import {FormsModule} from '@angular/forms';
@NgModule({
@@ -10,7 +20,17 @@ import {AdminUpdateComponent} from './admin-update.component';
],
imports: [
CommonModule,
RouterModule.forChild([{path: '', component: AdminUpdateComponent}])
RouterModule.forChild([{path: '', component: AdminUpdateComponent}]),
NzCardModule,
NzTableModule,
NzTypographyModule,
NzToolTipModule,
NzDividerModule,
NzPopconfirmModule,
NzModalModule,
FormsModule,
NzButtonModule,
NzInputModule
]
})
export class AdminUpdateModule {