重构界面ui

This commit is contained in:
小海
2020-04-06 20:48:40 +08:00
parent f2791ee150
commit 3ea8f63abc
601 changed files with 95141 additions and 90135 deletions

View File

@@ -0,0 +1,18 @@
import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {CategoryComponent} from './category.component';
const routes: Routes = [
{path: ':category', component: CategoryComponent},
{path: '**', component: CategoryComponent}
];
@NgModule({
imports: [
RouterModule.forChild(routes)
],
exports: [RouterModule]
})
export class CategoryRoutingModule {
}

View File

@@ -0,0 +1,28 @@
<div id="main">
<div id="category">
<ul *ngIf="categoryList.length">
<c-tag-tag *ngFor="let category of categoryList"
[tag]="{name:category.name,size:category.articles.length}"
(tagClick)="changeCategory(category)">
</c-tag-tag>
</ul>
<h2 *ngIf="!categoryList.length">暂时没有分类</h2>
</div>
<span id="tip">当前分类为 :
<span style="font-weight: bolder;">{{name}}</span>
</span>
<ul id="detail" *ngIf="articleList&&articleList.list.length">
<c-article-detail-card *ngFor="let article of articleList.list"
[data]="article" [showMediaArea]="false" [showTagArea]="false">
</c-article-detail-card>
</ul>
<div *ngIf="!articleList||!articleList.list.length">
<h2 style="text-align: center">该分类暂无文章</h2>
</div>
</div>

View File

@@ -0,0 +1,29 @@
#main {
width: 75%;
margin: 30px auto;
border-radius: 10px;
padding: 10px;
background: #ffffff;
#tip {
margin-left: 40px;
font-size: large;
}
#category {
text-align: center;
}
#detail {
margin-top: 20px;
}
}
@media screen and (max-width: 940px) {
#main {
width: 100%;
}
#detail{
margin: 10px 40px 10px 0;
}
}

View File

@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CategoryComponent } from './category.component';
describe('CategoryComponent', () => {
let component: CategoryComponent;
let fixture: ComponentFixture<CategoryComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CategoryComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CategoryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,71 @@
import {Component, OnInit} from '@angular/core';
import {ApiService} from '../../api/api.service';
import {Category} from '../../class/Category';
import {NzMessageService} from 'ng-zorro-antd';
import {PageList} from '../../class/pageList';
import {Article} from '../../class/Article';
import {ActivatedRoute} from '@angular/router';
import {Location} from '@angular/common';
import {Title} from '@angular/platform-browser';
@Component({
selector: 'view-category',
templateUrl: './category.component.html',
styleUrls: ['./category.component.less']
})
export class CategoryComponent implements OnInit {
constructor(private apiService: ApiService,
private nzMessageService: NzMessageService,
private activatedRoute: ActivatedRoute,
private location: Location,
private title: Title) {
}
categoryList: Category[] = [];
private category: Category;
articleList: PageList<Article>;
name: string;
ngOnInit() {
this.name = this.activatedRoute.snapshot.paramMap.get('category');
this.getCategories(this.name == null);
if (this.name != null) {
this.getArticles(this.name);
}
}
getCategories(needGetArticle: boolean) {
this.apiService.categories().subscribe(data => {
this.categoryList = data.result;
this.category = data.result[0];
if (needGetArticle) {
this.getArticles(this.category.name);
this.name = this.category.name;
this.title.setTitle('小海博客 | 分类 | ' + this.name);
}
}, error => {
this.nzMessageService.error('出现了错误,原因:' + error.msg);
});
}
getArticles(categoryName: string) {
this.apiService.articlesByCategory(categoryName).subscribe(data => {
this.articleList = data.result;
}, error => {
this.nzMessageService.error('出现了错误,原因:' + error.msg);
});
}
changeCategory(category: Category) {
if (this.name === category.name) {
return;
}
this.category = category;
this.name = category.name;
this.location.replaceState('categories/' + this.name);
this.getArticles(this.name);
this.title.setTitle('小海博客 | 分类 | ' + this.name);
}
}

View File

@@ -0,0 +1,20 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {CategoryComponent} from './category.component';
import {CategoryRoutingModule} from './category-routing.module';
import {NzIconModule, NzToolTipModule} from 'ng-zorro-antd';
import {IndexModule} from '../index/index.module';
@NgModule({
declarations: [CategoryComponent],
imports: [
CommonModule,
CategoryRoutingModule,
NzToolTipModule,
NzIconModule,
IndexModule
]
})
export class CategoryModule {
}