From dba21730ca143811792cb40cafc7ff744ee027fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BE=E5=87=A0=E6=B5=B7?= Date: Wed, 27 May 2020 16:41:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4=EF=BC=8C?= =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E5=90=8E=E7=AB=AF=E9=83=A8=E5=88=86=E7=9A=84?= =?UTF-8?q?v2=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/api.service.ts | 41 ++++--------------- src/app/class/Article.ts | 21 ++++++---- src/app/class/Comment.ts | 29 +++++-------- src/app/class/HttpReqAndResp.ts | 15 ------- src/app/class/Link.ts | 2 + src/app/class/Tag.ts | 6 ++- src/app/class/User.ts | 6 +-- .../admin-article.component.html | 26 ++++++++++-- .../admin-article/admin-article.module.ts | 3 +- .../admin-comment.component.html | 37 ++++++++++------- .../admin-comment/admin-comment.component.ts | 14 ++++--- .../admin-dashboard.component.ts | 3 +- .../admin/admin-link/admin-link.module.ts | 5 ++- src/app/view/article/article.component.html | 37 +++++++++++------ src/app/view/article/article.component.ts | 5 +-- src/app/view/category/category.component.ts | 4 +- .../article-detail-card.component.html | 4 +- .../article-detail-card.component.ts | 2 +- src/app/view/index/index.component.ts | 7 ++-- src/app/view/update/update.component.ts | 2 +- .../publish-form/publish-form.component.ts | 14 +++---- src/app/view/write/write.component.ts | 18 ++++---- 22 files changed, 153 insertions(+), 148 deletions(-) diff --git a/src/app/api/api.service.ts b/src/app/api/api.service.ts index 5e07c7e..482250a 100644 --- a/src/app/api/api.service.ts +++ b/src/app/api/api.service.ts @@ -111,7 +111,7 @@ export class ApiService extends HttpService { } categories() { - return super.Service({ + return super.Service>({ path: '/categories', method: 'GET' }); @@ -183,10 +183,9 @@ export class ApiService extends HttpService { }); } - - getCommentByPid(pid: number, pageNumber: number = 1, pageSize: number = 10) { - return super.Service({ - path: `/comment/pid/${pid}`, + getCommentByTypeForAdmin(pagePath: string, pageNumber: number = 1, pageSize: number = 10) { + return super.Service>({ + path: `/admin/comment/pagePath/${pagePath}`, method: 'GET', queryParam: { page: pageNumber, @@ -195,20 +194,9 @@ export class ApiService extends HttpService { }); } - getCommentByTypeForAdmin(isComment: boolean, pageNumber: number = 1, pageSize: number = 10) { + getCommentByTypeForUser(pagePath: string, pageNumber: number = 1, pageSize: number = 10) { return super.Service>({ - path: `/admin/comment/type/${isComment ? 1 : 0}`, - method: 'GET', - queryParam: { - page: pageNumber, - count: pageSize - } - }); - } - - getCommentByTypeForUser(isComment: boolean, pageNumber: number = 1, pageSize: number = 10) { - return super.Service>({ - path: `/user/comment/type/${isComment ? 1 : 0}`, + path: `/user/comment/pagePath/${pagePath}`, method: 'GET', queryParam: { page: pageNumber, @@ -234,21 +222,9 @@ export class ApiService extends HttpService { }); } - comments(articleID: number, pageSize: number = 10, pageNumber: number = 1) { + comments(pagePath: string, pageSize: number = 10, pageNumber: number = 1) { return super.Service>({ - path: '/comments', - method: 'GET', - queryParam: { - articleId: articleID, - count: pageSize, - page: pageNumber - } - }); - } - - leaveMsg(pageSize: number = 10, pageNumber: number = 1) { - return super.Service>({ - path: '/leaveMsg', + path: `/comment/pagePath/${pagePath}`, method: 'GET', queryParam: { count: pageSize, @@ -272,7 +248,6 @@ export class ApiService extends HttpService { articleCount: number, visitorCount: number, categoryCount: number, - leaveMsgCount: number, tagCount: number, commentCount: number }>({ diff --git a/src/app/class/Article.ts b/src/app/class/Article.ts index 3c2a618..5d4ce36 100644 --- a/src/app/class/Article.ts +++ b/src/app/class/Article.ts @@ -1,3 +1,6 @@ +import {Tag} from './Tag'; +import {User} from './User'; + export class Article { id: number; title: string; @@ -5,16 +8,16 @@ export class Article { mdContent?: string; original?: boolean; url?: string; - publishDateFormat?: string; + publishDateFormat: string; updateDateFormat?: string; category?: string; - tags?: string[]; - authorName?: string; - preArticleId?: number; - nextArticleId?: number; - preArticleTitle?: string; - nextArticleTitle?: string; - readingNumber?: number; + tags?: Tag[]; + author: User; + preArticle?: Article; + nextArticle?: Article; + readingNumber: number; + likeCount: number; + dislikeCount: number; open?: string; } @@ -24,7 +27,7 @@ export class ArticleReq { id?: number; mdContent: string; open: boolean; - tags: string; + tags: string[]; title: string; type: boolean; url?: string; diff --git a/src/app/class/Comment.ts b/src/app/class/Comment.ts index 449e558..100f659 100644 --- a/src/app/class/Comment.ts +++ b/src/app/class/Comment.ts @@ -1,33 +1,26 @@ +import {User} from './User'; + export class Comment { id?: number; - authorName?: string; - authorAvatarImgUrl?: string; + fromUser: User; + toUser?: User; content: string; - articleID: number; - articleTitle: string; + pagePath: string; date?: string; - responseId: string; pid: number; - comment: boolean; respComment: Comment[]; + status: number; } export class CommentReq { id?: number; - comment: boolean; content: string; - pid: number; - articleID: number; - responseId: string; + pid: number = -1; + toUserId: number; + pagePath: string; - constructor(comment: boolean) { - this.comment = comment; - this.responseId = ''; - if (!comment) { - this.articleID = -1; - } - this.pid = -1; - this.id = null; + constructor(pagePath: string) { + this.pagePath = pagePath; } } diff --git a/src/app/class/HttpReqAndResp.ts b/src/app/class/HttpReqAndResp.ts index 7ef4596..33ba9f1 100644 --- a/src/app/class/HttpReqAndResp.ts +++ b/src/app/class/HttpReqAndResp.ts @@ -15,7 +15,6 @@ export class Response { code: number; msg: string; result: T; - date: number; constructor(t: T) { this.code = 0; @@ -28,18 +27,4 @@ export class PageList { list: T[]; pageNum: number; pageSize: number; - size: number; - startRow: number; - endRow: number; - pages: number; - prePage: number; - nextPage: number; - isFirstPage: boolean; - isLastPage: boolean; - hasPreviousPage: boolean; - hasNextPage: boolean; - navigatePages: number; - navigatepageNums: number[]; - navigateFirstPage: number; - navigateLastPage: number; } diff --git a/src/app/class/Link.ts b/src/app/class/Link.ts index a44c984..55fc7d3 100644 --- a/src/app/class/Link.ts +++ b/src/app/class/Link.ts @@ -3,4 +3,6 @@ export class Link { name: string; url: string; open?: boolean; + iconPath: string; + desc: string; } diff --git a/src/app/class/Tag.ts b/src/app/class/Tag.ts index 0fc4dd1..6a9429e 100644 --- a/src/app/class/Tag.ts +++ b/src/app/class/Tag.ts @@ -1,12 +1,14 @@ +import {Article} from './Article'; + export class Category { id: number; name: string; - articles?: number[]; + articles?: Article[]; } export class Tag { id: number; name: string; - articles?: number[]; + articles?: Article[]; } diff --git a/src/app/class/User.ts b/src/app/class/User.ts index b9cb99b..d15d989 100644 --- a/src/app/class/User.ts +++ b/src/app/class/User.ts @@ -2,10 +2,10 @@ export class User { id: number; email: string; displayName: string; - emailStatus: boolean; - avatarImgUrl?: string; + emailStatus?: boolean; + avatarImgUrl: string; desc: string; - role: string; + role?: string; token?: string; pwd?: string; recentlyLandedDate?: string diff --git a/src/app/view/admin/admin-article/admin-article.component.html b/src/app/view/admin/admin-article/admin-article.component.html index 01983b6..fa19575 100644 --- a/src/app/view/admin/admin-article/admin-article.component.html +++ b/src/app/view/admin/admin-article/admin-article.component.html @@ -1,14 +1,22 @@
- - + + 标题 发布日期 更新日期 文章类型 阅读量 + 👍赞 + 👎踩 是否可见 操作 @@ -25,6 +33,12 @@ {{data.readingNumber}} + + {{data.likeCount}} + + + {{data.dislikeCount}} + 编辑 @@ -36,6 +50,10 @@ + + + +
diff --git a/src/app/view/admin/admin-article/admin-article.module.ts b/src/app/view/admin/admin-article/admin-article.module.ts index 2e1e461..7331c83 100644 --- a/src/app/view/admin/admin-article/admin-article.module.ts +++ b/src/app/view/admin/admin-article/admin-article.module.ts @@ -4,7 +4,7 @@ import {RouterModule} from '@angular/router'; import {AdminArticleComponent} from './admin-article.component'; import { NzCardModule, - NzDividerModule, + NzDividerModule, NzIconModule, NzPopconfirmModule, NzTableModule, NzTagModule, NzToolTipModule, @@ -25,6 +25,7 @@ import { NzDividerModule, NzPopconfirmModule, NzTagModule, + NzIconModule, ] }) export class AdminArticleModule { diff --git a/src/app/view/admin/admin-comment/admin-comment.component.html b/src/app/view/admin/admin-comment/admin-comment.component.html index 1c6fe8d..ecd3aef 100644 --- a/src/app/view/admin/admin-comment/admin-comment.component.html +++ b/src/app/view/admin/admin-comment/admin-comment.component.html @@ -1,20 +1,25 @@
- - + + - 文章标题 - 评论内容 - 评论者 - 评论日期 - 操作 + 评论页面 + 评论内容 + 评论日期 + 操作 - {{data.articleTitle}} - {{data.pagePath}} + {{data.content}} 取消 - {{data.authorName}} - {{data.date}} - + {{data.date}} + 编辑
+ + + diff --git a/src/app/view/admin/admin-comment/admin-comment.component.ts b/src/app/view/admin/admin-comment/admin-comment.component.ts index 13c7659..ddb8ccb 100644 --- a/src/app/view/admin/admin-comment/admin-comment.component.ts +++ b/src/app/view/admin/admin-comment/admin-comment.component.ts @@ -27,7 +27,9 @@ export class AdminCommentComponent implements OnInit { } else { this.getComment = this.getCommentForUser; } + if (this.requested) return; this.getComment() + this.requested = true }, error: null, complete: null @@ -40,23 +42,25 @@ export class AdminCommentComponent implements OnInit { pageList: PageList = new PageList(); editInfo = { id: null, - content: new CommentReq(true), + content: new CommentReq(null), editFocus: false, } getComment: any;// 存放获取评论的方法 + private requested: boolean = false; ngOnInit(): void { } - getCommentForAdmin = () => this.apiService.getCommentByTypeForAdmin(true, this.pageIndex, this.pageSize).subscribe({ + // 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(true, this.pageIndex, this.pageSize).subscribe({ + getCommentForUser = () => this.apiService.getCommentByTypeForUser('*', this.pageIndex, this.pageSize).subscribe({ next: data => this.pageList = data.result, complete: () => this.loading = false, error: err => this.loading = false @@ -97,9 +101,9 @@ export class AdminCommentComponent implements OnInit { 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.articleID = data.articleID; this.editInfo.content.pid = data.pid; - this.editInfo.content.responseId = data.responseId; + // this.editInfo.content.responseId = data.responseId; this.editInfo.editFocus = true; } } diff --git a/src/app/view/admin/admin-dashboard/admin-dashboard.component.ts b/src/app/view/admin/admin-dashboard/admin-dashboard.component.ts index cf595bf..182dcec 100644 --- a/src/app/view/admin/admin-dashboard/admin-dashboard.component.ts +++ b/src/app/view/admin/admin-dashboard/admin-dashboard.component.ts @@ -23,10 +23,9 @@ export class AdminDashboardComponent implements OnInit { articleCount: number, visitorCount: number, categoryCount: number, - leaveMsgCount: number, tagCount: number, commentCount: number - } = {articleCount: 0, visitorCount: 0, categoryCount: 0, tagCount: 0, commentCount: 0, leaveMsgCount: 0} + } = {articleCount: 0, visitorCount: 0, categoryCount: 0, tagCount: 0, commentCount: 0} dayVisitCount: number = 0; userInfo: User = new User(); diff --git a/src/app/view/admin/admin-link/admin-link.module.ts b/src/app/view/admin/admin-link/admin-link.module.ts index ed478fb..d69b05a 100644 --- a/src/app/view/admin/admin-link/admin-link.module.ts +++ b/src/app/view/admin/admin-link/admin-link.module.ts @@ -6,7 +6,7 @@ import { NzButtonModule, NzCardModule, NzDividerModule, - NzFormModule, NzInputModule, + NzFormModule, NzIconModule, NzInputModule, NzModalModule, NzPopconfirmModule, NzSelectModule, NzTableModule @@ -30,7 +30,8 @@ import {ReactiveFormsModule} from '@angular/forms'; ReactiveFormsModule, NzInputModule, NzSelectModule, - NzButtonModule + NzButtonModule, + NzIconModule ] }) export class AdminLinkModule { diff --git a/src/app/view/article/article.component.html b/src/app/view/article/article.component.html index 2cd0ce9..648b742 100644 --- a/src/app/view/article/article.component.html +++ b/src/app/view/article/article.component.html @@ -6,7 +6,7 @@ @@ -16,17 +16,19 @@ - {{item}} - + {{item.name}} +
- - {{article.nextArticleTitle}} + + + {{(article.nextArticle && article.nextArticle.title) || '无'}} - - {{article.preArticleTitle}} + {{(article.preArticle && article.preArticle.title) || '无'}} +
@@ -58,19 +60,30 @@ - - + + + + +

{{ comment.content }}

- + - - + + + + +

{{ com.content }}

diff --git a/src/app/view/article/article.component.ts b/src/app/view/article/article.component.ts index ae89852..0adb93c 100644 --- a/src/app/view/article/article.component.ts +++ b/src/app/view/article/article.component.ts @@ -51,7 +51,7 @@ export class ArticleComponent implements OnInit { if (data.result) this.avatarImgUrl = data.result.avatarImgUrl; } }); - this.comment = new CommentReq(true); + this.comment = new CommentReq(`article/${this.articleId}`); } parseMd(md: string) { @@ -73,7 +73,7 @@ export class ArticleComponent implements OnInit { this.router.navigateByUrl('/article/' + id); this.apiService.getArticle(id).subscribe({ next: data => { - this.apiService.comments(id).subscribe(commData => { + this.apiService.comments(`article+${id}`).subscribe(commData => { this.commentPage = commData.result; }); document.getElementById('article-content').innerHTML = ''; @@ -89,7 +89,6 @@ export class ArticleComponent implements OnInit { // true ==> 一级评论 false ==>二级评论 submitComment(bool: boolean) { this.submitting = true; - this.comment.articleID = this.articleId; if (!bool) { this.comment.content = this.content; this.comment.pid = this.pid; diff --git a/src/app/view/category/category.component.ts b/src/app/view/category/category.component.ts index aacb981..0001a2e 100644 --- a/src/app/view/category/category.component.ts +++ b/src/app/view/category/category.component.ts @@ -38,8 +38,8 @@ export class CategoryComponent implements OnInit { getCategories(needGetArticle: boolean) { this.apiService.categories().subscribe(data => { - this.categoryList = data.result; - this.category = data.result[0]; + this.categoryList = data.result.list; + this.category = this.categoryList[0]; if (needGetArticle) { this.getArticles(this.category.name); this.name = this.category.name; diff --git a/src/app/view/index/components/article-detail-card/article-detail-card.component.html b/src/app/view/index/components/article-detail-card/article-detail-card.component.html index 7f7b2a2..e36f017 100644 --- a/src/app/view/index/components/article-detail-card/article-detail-card.component.html +++ b/src/app/view/index/components/article-detail-card/article-detail-card.component.html @@ -10,7 +10,7 @@ - {{data.authorName}} + {{data.author.displayName}} @@ -28,7 +28,7 @@ diff --git a/src/app/view/index/components/article-detail-card/article-detail-card.component.ts b/src/app/view/index/components/article-detail-card/article-detail-card.component.ts index 69bb2c7..e883619 100644 --- a/src/app/view/index/components/article-detail-card/article-detail-card.component.ts +++ b/src/app/view/index/components/article-detail-card/article-detail-card.component.ts @@ -22,7 +22,7 @@ export class ArticleDetailCardComponent implements OnInit { } if (this.showMediaArea == null) { // 如果作者名不为空 则显示 - this.showMediaArea = this.data.authorName != null; + this.showMediaArea = this.data.author.displayName != null; } if (this.showTagArea == null) { this.showTagArea = this.data.tags != null; diff --git a/src/app/view/index/index.component.ts b/src/app/view/index/index.component.ts index 4b839f3..0c8b905 100644 --- a/src/app/view/index/index.component.ts +++ b/src/app/view/index/index.component.ts @@ -7,7 +7,7 @@ import {PageList} from '../../class/HttpReqAndResp'; import {ErrDispatch} from '../../class/ErrDispatch'; import {RequestObj} from '../../class/HttpReqAndResp'; import {Router} from '@angular/router'; -import {Tag} from '../../class/Tag'; +import {Category, Tag} from '../../class/Tag'; import {Title} from '@angular/platform-browser'; @Component({ @@ -36,12 +36,11 @@ export class IndexComponent implements OnInit, ErrDispatch { desc: string; articles: PageList
; tagNameAndNumber: { name: string, size: number }[]; - categoryList: Tag[]; + categoryList: Category[]; counts: { articleCount: number, visitorCount: number, categoryCount: number, - leaveMsgCount: number, tagCount: number, commentCount: number }; @@ -75,7 +74,7 @@ export class IndexComponent implements OnInit, ErrDispatch { } }); this.apiService.categories().subscribe({ - next: data => this.categoryList = data.result, + next: data => this.categoryList = data.result.list, error: err => { } }); diff --git a/src/app/view/update/update.component.ts b/src/app/view/update/update.component.ts index 77d8819..1953fc5 100644 --- a/src/app/view/update/update.component.ts +++ b/src/app/view/update/update.component.ts @@ -29,7 +29,7 @@ export class UpdateComponent implements OnInit { this.lastUpdate = data.result; }); this.apiService.webUpdate().subscribe(data => { - this.webUpdate = data.result.reverse(); + this.webUpdate = data.result; }); } diff --git a/src/app/view/write/components/publish-form/publish-form.component.ts b/src/app/view/write/components/publish-form/publish-form.component.ts index 534ac7b..b2c4cbd 100644 --- a/src/app/view/write/components/publish-form/publish-form.component.ts +++ b/src/app/view/write/components/publish-form/publish-form.component.ts @@ -1,6 +1,6 @@ import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; -import {Tag} from '../../../../class/Tag'; +import {Category, Tag} from '../../../../class/Tag'; @Component({ selector: 'c-publish-form', @@ -15,9 +15,9 @@ export class PublishFormComponent implements OnInit { @ViewChild('inputElement', {static: false}) tagInputElement: ElementRef; @Input() tagNacList: { name: string, size: number }[]; - @Input() categoryList: Tag[]; - @Input() primaryData: { id: number, type: boolean, tags: string, category: string, url?: string }; - @Output() submitEvent = new EventEmitter<{ id: number, type: boolean, tags: string, category: string, url?: string }>(); + @Input() categoryList: Category[]; + @Input() primaryData: { id: number, type: boolean, tags: string[], category: string, url?: string }; + @Output() submitEvent = new EventEmitter<{ id: number, type: boolean, tags: string[], category: string, url?: string }>(); formGroup: FormGroup; tagTmpList: string[] = []; @@ -36,8 +36,8 @@ export class PublishFormComponent implements OnInit { if (this.primaryData) { this.formGroup.get('type').setValue(this.primaryData.type); const tags = this.primaryData.tags; - this.formGroup.get('tagList').setValue(tags ? this.primaryData.tags.split(',') : tags); - this.tagTmpList = tags ? this.primaryData.tags.split(',') : [...tags]; + this.formGroup.get('tagList').setValue(tags); + this.tagTmpList = tags; this.formGroup.get('category').setValue(this.primaryData.category); this.formGroup.get('url').setValue(this.primaryData.url); } @@ -47,7 +47,7 @@ export class PublishFormComponent implements OnInit { const formData = { id: this.formGroup.value.isUpdate ? this.primaryData.id : null, type: this.formGroup.value.type, - tags: this.formGroup.value.tagList.toString(), + tags: this.formGroup.value.tagList, category: this.formGroup.value.category, url: this.formGroup.value.type ? null : this.formGroup.value.url }; diff --git a/src/app/view/write/write.component.ts b/src/app/view/write/write.component.ts index 716a3bc..305dba7 100644 --- a/src/app/view/write/write.component.ts +++ b/src/app/view/write/write.component.ts @@ -81,7 +81,7 @@ export class WriteComponent implements OnInit { }); this.apiService.categories().subscribe({ next: data => { - this.categoryList = data.result; + this.categoryList = data.result.list; }, error: err => { this.message.error('获取分类信息失败'); @@ -109,17 +109,19 @@ export class WriteComponent implements OnInit { /** * 文章数据提交 */ - publishArticle(e: { id: number, type: boolean, tags: string, category: string, url?: string }) { + publishArticle(e: { id: number, type: boolean, tags: string[], category: string, url?: string }) { this.article.type = e.type; this.article.tags = e.tags; this.article.category = e.category; this.article.url = e.url; this.article.id = e.id; - if (!this.article.id && this.title === this.article.title) { - this.message.error('文章标题未经更改,请修改后再发布'); - return; - } + this.modalVisible = false; + + // if (!this.article.id && this.title === this.article.title) { + // this.message.error('文章标题未经更改,请修改后再发布'); + // return; + // } // 文章 暂存 localStorage.setItem('tmpArticle', JSON.stringify(this.article)); @@ -182,7 +184,9 @@ export class WriteComponent implements OnInit { next: data => { this.article.category = data.result.category; this.article.mdContent = data.result.mdContent; - this.article.tags = String(data.result.tags); + const tags = [] + data.result.tags.forEach(t => tags.push(t.name)) + this.article.tags = tags; this.article.type = data.result.original; this.article.url = data.result.url; this.article.title = data.result.title;