From bc512d17b0b472c63c7d2f0f86467ec69dbb9bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=B5=B7?= Date: Sat, 16 May 2020 01:59:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=88=86=E7=B1=BB=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index/src/app/api/api.service.ts | 2 +- .../admin-article.component.html | 2 +- .../admin-article/admin-article.component.ts | 2 +- .../app/view/admin/admin-routing.module.ts | 10 +- .../admin/admin-tag/admin-tag.component.html | 89 ++++++++++- .../admin/admin-tag/admin-tag.component.ts | 138 +++++++++++++++++- .../view/admin/admin-tag/admin-tag.module.ts | 19 ++- index/src/app/view/admin/admin.component.html | 10 +- 8 files changed, 250 insertions(+), 22 deletions(-) diff --git a/index/src/app/api/api.service.ts b/index/src/app/api/api.service.ts index a591d08..485fa0c 100644 --- a/index/src/app/api/api.service.ts +++ b/index/src/app/api/api.service.ts @@ -142,7 +142,7 @@ export class ApiService extends HttpService { } tags(pageNumber: number = 1, pageSize: number = 10) { - return super.Service({ + return super.Service>({ path: '/tags', method: 'GET', queryParam: { diff --git a/index/src/app/view/admin/admin-article/admin-article.component.html b/index/src/app/view/admin/admin-article/admin-article.component.html index 035908a..f149e55 100644 --- a/index/src/app/view/admin/admin-article/admin-article.component.html +++ b/index/src/app/view/admin/admin-article/admin-article.component.html @@ -1,7 +1,7 @@
标题 diff --git a/index/src/app/view/admin/admin-article/admin-article.component.ts b/index/src/app/view/admin/admin-article/admin-article.component.ts index 5513091..35d239b 100644 --- a/index/src/app/view/admin/admin-article/admin-article.component.ts +++ b/index/src/app/view/admin/admin-article/admin-article.component.ts @@ -36,9 +36,9 @@ export class AdminArticleComponent implements OnInit { this.apiService.deleteArticle(id).subscribe({ next: data => { this.nzMessage.success('删除成功') + this.loading = false; this.getArticle(); }, - complete: () => this.loading = false, error: err => { this.nzMessage.error(err.msg) this.loading = false diff --git a/index/src/app/view/admin/admin-routing.module.ts b/index/src/app/view/admin/admin-routing.module.ts index 8ad3ba4..b442849 100644 --- a/index/src/app/view/admin/admin-routing.module.ts +++ b/index/src/app/view/admin/admin-routing.module.ts @@ -20,11 +20,11 @@ const routes: Routes = [ loadChildren: () => import('./admin-comment/admin-comment.module').then(mod => mod.AdminCommentModule), canActivate: [AuthGuard] }, - { - path: 'category', - loadChildren: () => import('./admin-category/admin-category.module').then(mod => mod.AdminCategoryModule), - canActivate: [AuthGuard] - }, + // { + // path: 'category', + // loadChildren: () => import('./admin-category/admin-category.module').then(mod => mod.AdminCategoryModule), + // canActivate: [AuthGuard] + // }, { path: 'link', loadChildren: () => import('./admin-link/admin-link.module').then(mod => mod.AdminLinkModule), diff --git a/index/src/app/view/admin/admin-tag/admin-tag.component.html b/index/src/app/view/admin/admin-tag/admin-tag.component.html index 27cd5d7..af06947 100644 --- a/index/src/app/view/admin/admin-tag/admin-tag.component.html +++ b/index/src/app/view/admin/admin-tag/admin-tag.component.html @@ -1 +1,88 @@ -

admin-tag works!

+
+ + + +
+ + + + + +
+ + + 分类名 + 分类文章数量 + 操作 + + + + + {{data.name}} + + + + + + + {{data.articles ? data.articles.length : 0}} + + 编辑 + + 查看 + + 删除 + + + + +
+ + + + 标签名 + 分类文章数量 + 操作 + + + + + {{data.name}} + + + + + + + {{data.articles ? data.articles.length : 0}} + + 编辑 + + 查看 + + 删除 + + + + + +
+
+
+ diff --git a/index/src/app/view/admin/admin-tag/admin-tag.component.ts b/index/src/app/view/admin/admin-tag/admin-tag.component.ts index 8070fcd..d169875 100644 --- a/index/src/app/view/admin/admin-tag/admin-tag.component.ts +++ b/index/src/app/view/admin/admin-tag/admin-tag.component.ts @@ -1,15 +1,139 @@ -import { Component, OnInit } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; +import {NzMessageService} from 'ng-zorro-antd'; +import {Category, Tag} from '../../../class/Tag'; +import {ApiService} from '../../../api/api.service'; +import {PageList} from '../../../class/HttpReqAndResp'; @Component({ - selector: 'app-admin-tag', - templateUrl: './admin-tag.component.html', - styleUrls: ['./admin-tag.component.less'] + selector: 'app-admin-tag', + templateUrl: './admin-tag.component.html', + styleUrls: ['./admin-tag.component.less'] }) export class AdminTagComponent implements OnInit { - constructor() { } + constructor(private apiService: ApiService, private nzMessageService: NzMessageService) { + } - ngOnInit(): void { - } + loading: boolean = true; + categoryList: Category[] = []; + editInfo = { + id: null, + name: null, + editFocus: false, + isAdd: false + } + tagPageList: PageList = new PageList(); + + pageIndex: number = 1; + pageSize: number = 10; + + + ngOnInit(): void { + this.getCategory(); + this.getTag(); + } + + getCategory = () => this.apiService.categories().subscribe({ + next: data => this.categoryList = data.result, + complete: () => this.loading = false, + error: err => this.loading = false + }) + + getTag = () => this.apiService.tags(this.pageIndex, this.pageSize).subscribe({ + next: data => this.tagPageList = data.result, + complete: () => this.loading = false, + error: err => this.loading = false + }) + + delete(id, mode: 'tag' | 'category') { + this.loading = true; + if (mode === 'tag') { + this.apiService.deleteTag(id).subscribe({ + next: data => { + this.nzMessageService.success('删除成功') + this.getTag(); + }, + complete: () => this.loading = false, + error: err => { + this.nzMessageService.error(err.msg) + this.loading = false + } + }) + } else if (mode === 'category') { + this.apiService.deleteCategory(id).subscribe({ + next: data => { + this.nzMessageService.success('删除成功') + this.getCategory(); + }, + complete: () => this.loading = false, + error: err => { + this.nzMessageService.error(err.msg) + this.loading = false + } + }) + } + } + + editFocus(data: Category) { + this.editInfo.isAdd = false; + this.editInfo.id = data.id; + this.editInfo.name = data.name; + this.editInfo.editFocus = true; + } + + edit(mode: 'tag' | 'category') { + this.loading = true; + if (mode === 'tag') { + this.apiService.updateTag(this.editInfo.id, this.editInfo.name).subscribe({ + next: data => { + this.nzMessageService.success('更新成功') + this.getTag(); + }, + complete: () => this.loading = false, + error: err => { + this.nzMessageService.error(err.msg) + this.loading = false + } + }) + } else if (mode === 'category') { + this.apiService.updateCategory(this.editInfo.id, this.editInfo.name).subscribe({ + next: data => { + this.nzMessageService.success('更新成功') + this.getCategory(); + }, + complete: () => this.loading = false, + error: err => { + this.nzMessageService.error(err.msg) + this.loading = false + } + }) + } + this.editInfo.editFocus = false + this.editInfo.name = null + } + + addCategory() { + this.editInfo.isAdd = true + if (!this.editInfo.editFocus && this.editInfo.isAdd) { + this.editInfo.name = null; + this.editInfo.id = null; + this.editInfo.editFocus = true; + return + } + this.apiService.createCategory(this.editInfo.name).subscribe({ + next: data => { + this.nzMessageService.success('新增成功') + this.getCategory(); + }, + complete: () => this.loading = false, + error: err => { + this.nzMessageService.error(err.msg) + this.loading = false + } + }); + this.editInfo.editFocus = false + this.editInfo.isAdd = false + this.editInfo.name = null + } } diff --git a/index/src/app/view/admin/admin-tag/admin-tag.module.ts b/index/src/app/view/admin/admin-tag/admin-tag.module.ts index 8c6a40c..7797fb7 100644 --- a/index/src/app/view/admin/admin-tag/admin-tag.module.ts +++ b/index/src/app/view/admin/admin-tag/admin-tag.module.ts @@ -2,6 +2,14 @@ import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; import {RouterModule} from '@angular/router'; import {AdminTagComponent} from './admin-tag.component'; +import { + NzButtonModule, + NzCardModule, + NzDividerModule, NzIconModule, + NzInputModule, NzPopconfirmModule, + NzTableModule, NzTabsModule, +} from 'ng-zorro-antd'; +import {FormsModule} from '@angular/forms'; @NgModule({ @@ -10,7 +18,16 @@ import {AdminTagComponent} from './admin-tag.component'; ], imports: [ CommonModule, - RouterModule.forChild([{path: '', component: AdminTagComponent}]) + RouterModule.forChild([{path: '', component: AdminTagComponent}]), + NzCardModule, + NzTableModule, + NzDividerModule, + NzInputModule, + FormsModule, + NzTabsModule, + NzPopconfirmModule, + NzButtonModule, + NzIconModule, ] }) export class AdminTagModule { diff --git a/index/src/app/view/admin/admin.component.html b/index/src/app/view/admin/admin.component.html index 0700ffe..4d741ae 100644 --- a/index/src/app/view/admin/admin.component.html +++ b/index/src/app/view/admin/admin.component.html @@ -35,13 +35,13 @@
  • - 标签管理 + 分类标签管理
  • -
  • - - 分类管理 -
  • + + + +