重构界面ui
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ArticleService } from './article.service';
|
||||
|
||||
describe('ArticleService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: ArticleService = TestBed.get(ArticleService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,97 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {Page} from '../../class/page';
|
||||
import {Article} from '../../class/article';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Data} from '../../class/data';
|
||||
import {ArticleReq} from '../../class/articleReq';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ArticleService {
|
||||
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
// 存储所有已经请求过的数据<首页数据>
|
||||
pageList: Page<Article>[] = [];
|
||||
|
||||
// 最后一次请求后的数据集<首页数据>
|
||||
currentPage: Page<Article>;
|
||||
|
||||
// 通过分类获取的article
|
||||
public currentArticleOfCategory: Page<Article>;
|
||||
// 通过分类获取的article
|
||||
public currentArticleOfTag: Page<Article>;
|
||||
|
||||
|
||||
/**
|
||||
* 获取文章
|
||||
* @param pageNum 页码数
|
||||
* @param pageSize 单页数据量
|
||||
*/
|
||||
getArticle(pageNum: number, pageSize: number): object {
|
||||
const articlePage = this.exist(pageNum, pageSize);
|
||||
if (articlePage) {
|
||||
return articlePage;
|
||||
}
|
||||
const observable = this.http.get('/articles?page=' + pageNum + '&count=' + pageSize);
|
||||
observable.subscribe((data: any) => {
|
||||
if (data.code === 0) {
|
||||
this.currentPage = data.result;
|
||||
this.pageList.push(data.result);
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类获取文章
|
||||
* @param name 分类名
|
||||
*/
|
||||
getArticleByCategory(name: string) {
|
||||
return this.http.get('/articles/category/' + name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标签获取文章
|
||||
* @param name 标签名
|
||||
*/
|
||||
getArticleByTag(name: string) {
|
||||
return this.http.get('/articles/tag/' + name);
|
||||
}
|
||||
|
||||
getArticleById(id: number, update: boolean = false) {
|
||||
return this.http.get('/article/articleID/' + id + '?update=' + update);
|
||||
}
|
||||
|
||||
|
||||
createArticle(article: ArticleReq) {
|
||||
return this.http.post('/admin/article/create', article, true);
|
||||
}
|
||||
|
||||
updateArticle(article: ArticleReq) {
|
||||
return this.http.put('/admin/article/update', article);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断并返回数据
|
||||
* @param pageNum 页码数
|
||||
* @param pageSize 单页数据量
|
||||
*/
|
||||
private exist(pageNum: number, pageSize: number): Page<Article> {
|
||||
if (this.currentPage == null) {
|
||||
return null;
|
||||
}
|
||||
// tslint:disable-next-line:prefer-for-of
|
||||
for (let i = 0; i < this.pageList.length; i++) {
|
||||
// tslint:disable-next-line:triple-equals
|
||||
if (this.pageList[i].pageNum == pageNum && this.pageList[i].pageSize == pageSize) {
|
||||
return this.pageList[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CategoryService } from './category.service';
|
||||
|
||||
describe('CategoryService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: CategoryService = TestBed.get(CategoryService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,27 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {Category} from '../../class/category';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CategoryService {
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
categories: Category[];
|
||||
|
||||
getAllCategory() {
|
||||
const observable = this.http.get('/categories');
|
||||
observable.subscribe((data) => {
|
||||
if (data.code === 0) {
|
||||
this.categories = data.result;
|
||||
}
|
||||
}
|
||||
);
|
||||
return observable;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CommentService } from './comment.service';
|
||||
|
||||
describe('CommentService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: CommentService = TestBed.get(CommentService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,124 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {Page} from '../../class/page';
|
||||
import {LeaveMsg} from '../../class/LeaveMsg';
|
||||
import {CommentReq} from '../../class/commentReq';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CommentService {
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
// 存放
|
||||
leaveMsgPage: Page<LeaveMsg> = new Page();
|
||||
|
||||
commentPage: Page<LeaveMsg> = new Page();
|
||||
|
||||
|
||||
/**
|
||||
* 获取留言
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 单页数据数量
|
||||
*/
|
||||
getLeaveMsg(pageNum: number, pageSize: number) {
|
||||
const observable = this.http.get('/leaveMsg?count=' + pageSize + '&page=' + pageNum);
|
||||
observable.subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.leaveMsgPage = data.result;
|
||||
this.getResponseLeaveMsg();
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文章的评论
|
||||
* @param articleId 文章id
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 单页数量
|
||||
*/
|
||||
getPageComment(articleId: number, pageNum: number, pageSize: number) {
|
||||
const observable = this.http.get('/comments?articleId=' + articleId + '&count=' + pageSize + '&page=' + pageNum);
|
||||
observable.subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.commentPage = data.result;
|
||||
this.getResponseComment();
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取留言的回复
|
||||
*/
|
||||
getResponseLeaveMsg() {
|
||||
if (!this.leaveMsgPage.list) {
|
||||
return;
|
||||
}
|
||||
this.leaveMsgPage.list.forEach(leaveMsg => {
|
||||
if (leaveMsg.responseId != null && leaveMsg.responseId !== '') {
|
||||
this.getByPid(leaveMsg.id).subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
leaveMsg.child = data.result.list;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论的回复
|
||||
*/
|
||||
getResponseComment() {
|
||||
if (!this.commentPage.list) {
|
||||
return;
|
||||
}
|
||||
this.commentPage.list.forEach(comment => {
|
||||
if (comment.responseId != null && comment.responseId !== '') {
|
||||
this.getByPid(comment.id).subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
comment.child = data.result.list;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过父评论 获取回复
|
||||
* @param pid 父评论id
|
||||
*/
|
||||
getByPid(pid: number) {
|
||||
return this.http.get('/comment/pid/' + pid + '?count=5&page=1');
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交评论/留言 并加入缓存数据中
|
||||
* @param submitBody 请求体
|
||||
*/
|
||||
submitComment(submitBody: CommentReq) {
|
||||
this.http.post('/user/comment/create', submitBody, true).subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
if (!submitBody.comment) {
|
||||
this.leaveMsgPage.list.unshift(data.result);
|
||||
} else {
|
||||
this.commentPage.list.unshift(data.result);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 回复评论/留言
|
||||
* @param responseComment 请求体
|
||||
*/
|
||||
rely(responseComment: CommentReq) {
|
||||
return this.http.post('/user/comment/create', responseComment, true);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CountService } from './count.service';
|
||||
|
||||
describe('CountService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: CountService = TestBed.get(CountService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,24 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {Count} from '../../class/count';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CountService {
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
count: Count;
|
||||
|
||||
getCount() {
|
||||
const observable = this.http.get('/counts');
|
||||
observable.subscribe((data: any) => {
|
||||
if (data.code === 0) {
|
||||
this.count = data.result;
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { HttpService } from './http.service';
|
||||
|
||||
describe('HttpService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: HttpService = TestBed.get(HttpService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,110 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import {environment} from '../../environments/environment';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Data} from '../class/data';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class HttpService {
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
this.host = environment.host;
|
||||
const item = localStorage.getItem('token');
|
||||
this.token = item == null ? '' : item;
|
||||
this.httpOptions = {
|
||||
headers: new HttpHeaders({
|
||||
Accept: '*/*',
|
||||
Authorization: this.token
|
||||
}),
|
||||
withCredentials: true
|
||||
};
|
||||
}
|
||||
|
||||
// 请求的主机地址
|
||||
public host: string;
|
||||
private token: string;
|
||||
|
||||
/**
|
||||
* http请求配置
|
||||
*/
|
||||
private httpOptions: object;
|
||||
|
||||
/**
|
||||
* get 请求
|
||||
* @param path 路径
|
||||
*/
|
||||
get(path: string): Observable<Data> {
|
||||
return this.http.get<Data>(this.getPath(path), this.httpOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* post请求
|
||||
* @param path 路径
|
||||
* @param reqBody 请求体
|
||||
* @param isJson 请求数据是否是json格式
|
||||
*/
|
||||
post(path: string, reqBody: object, isJson: boolean): Observable<Data> {
|
||||
const Options = {
|
||||
headers: new HttpHeaders({
|
||||
Accept: '*/*',
|
||||
Authorization: this.token,
|
||||
ContentType: isJson ? 'application/json' : 'application/x-www-form-urlencoded'
|
||||
}),
|
||||
withCredentials: true
|
||||
};
|
||||
let submitBody = '';
|
||||
if (!isJson) {
|
||||
for (const key in reqBody) {
|
||||
// 跳过值为null的参数请求
|
||||
if (reqBody[key] == null || reqBody[key] === 'null') {
|
||||
continue;
|
||||
}
|
||||
submitBody = submitBody + '&' + key + '=' + reqBody[key];
|
||||
}
|
||||
submitBody = submitBody.substring(1);
|
||||
}
|
||||
return this.http.post<Data>(this.getPath(path), isJson ? reqBody : submitBody, Options);
|
||||
}
|
||||
|
||||
/**
|
||||
* put 请求
|
||||
* @param path 请求路径
|
||||
* @param reqBody 请求体
|
||||
*/
|
||||
put(path: string, reqBody: object): Observable<Data> {
|
||||
return this.http.put<Data>(this.getPath(path), reqBody, this.httpOptions);
|
||||
}
|
||||
|
||||
visit() {
|
||||
this.post('/visit', null, true).subscribe(data => {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查path 并拼接
|
||||
* @param path 请求路径
|
||||
* @return 拼接后的url
|
||||
*/
|
||||
private getPath(path: string): string {
|
||||
if (path == null || path.length === 0 || path.substr(0, 1) !== '/') {
|
||||
throw new Error('路径不合法');
|
||||
}
|
||||
return this.host + path;
|
||||
}
|
||||
|
||||
setToken(t: string) {
|
||||
if (t == null) {
|
||||
return;
|
||||
}
|
||||
localStorage.setItem('token', t);
|
||||
this.token = t;
|
||||
}
|
||||
|
||||
removeToken() {
|
||||
localStorage.removeItem('token');
|
||||
this.token = ''
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { LinkService } from './link.service';
|
||||
|
||||
describe('LinkService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: LinkService = TestBed.get(LinkService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,28 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class LinkService {
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
public Links: { id: number, name: string, url: string };
|
||||
|
||||
apply(link: {
|
||||
name: string,
|
||||
url: string
|
||||
}) {
|
||||
return this.http.post('/apply', link, false);
|
||||
}
|
||||
|
||||
getLinks() {
|
||||
this.http.get('/links').subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.Links = data.result;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TagService } from './tag.service';
|
||||
|
||||
describe('TagService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: TagService = TestBed.get(TagService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,26 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {Tag} from '../../class/tag';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TagService {
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
tagCloudList: Tag[];
|
||||
|
||||
getTagCloud() {
|
||||
const observable = this.http.get('/tags/nac');
|
||||
observable.subscribe((data: any) => {
|
||||
if (data.code === 0) {
|
||||
this.tagCloudList = data.result;
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { WebUpdateService } from './web-update.service';
|
||||
|
||||
describe('WebUpdateService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: WebUpdateService = TestBed.get(WebUpdateService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,34 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {UpdateInfo} from '../../class/updateInfo';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class WebUpdateService {
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
public updateInfoList: UpdateInfo[];
|
||||
|
||||
public lastestUpdateTime: string;
|
||||
|
||||
// when you fell unhappy,look at the sky, the sun is shining the birds are singing
|
||||
// And you? should be smiling
|
||||
getUpdateInfo() {
|
||||
this.http.get('/webUpdate').subscribe((data: any) => {
|
||||
if (data.code === 0) {
|
||||
this.updateInfoList = data.result.reverse();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getLastestUpdateTime() {
|
||||
this.http.get('/lastestUpdateTime').subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.lastestUpdateTime = data.result;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { UserService } from './user.service';
|
||||
|
||||
describe('UserService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: UserService = TestBed.get(UserService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,100 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {User} from '../../class/user';
|
||||
import {LoginReq} from '../../class/loginReq';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserService {
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
userInfo: User;
|
||||
|
||||
// 刚注册完账户 实现自动填充账户的临时存储 登录成功即置空
|
||||
tempUser: LoginReq;
|
||||
|
||||
loginModalType: 'login' | 'registration' = 'login';
|
||||
loginModalVisible: boolean = false;
|
||||
|
||||
|
||||
showModal(type: 'login' | 'registration') {
|
||||
this.loginModalType = type;
|
||||
this.loginModalVisible = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
getUserInfo() {
|
||||
const observable = this.http.get('/user/userInfo');
|
||||
observable.subscribe((data: any) => {
|
||||
if (data.code === 0) {
|
||||
this.userInfo = data.result;
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销登录
|
||||
*/
|
||||
logout() {
|
||||
this.http.get('/logout').subscribe((data: any) => {
|
||||
if (data.code === 0) {
|
||||
this.userInfo = null;
|
||||
this.http.removeToken();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param loginReq 请求体
|
||||
*/
|
||||
login(loginReq: {
|
||||
'email': string,
|
||||
'isRememberMe': boolean,
|
||||
'password': string
|
||||
}) {
|
||||
const observable = this.http.post('/login', loginReq, true);
|
||||
observable.subscribe((data: any) => {
|
||||
if (data.code === 0) {
|
||||
this.userInfo = data.result;
|
||||
this.loginModalVisible = false;
|
||||
this.http.setToken(data.result.token);
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
registration(emailStr: string, pwd: string) {
|
||||
const submitBody = {
|
||||
email: emailStr,
|
||||
password: pwd
|
||||
};
|
||||
return this.http.post('/registration', submitBody, false);
|
||||
// 注册成功 -> 登录 在component里面实现了
|
||||
}
|
||||
|
||||
|
||||
emailVerify(reqBody) {
|
||||
return this.http.post('/emailVerify', reqBody, false);
|
||||
}
|
||||
|
||||
resetPWd(reqBody) {
|
||||
return this.http.post('/resetPwd', reqBody, false);
|
||||
}
|
||||
|
||||
sendResetPwdEmail(emailStr: string) {
|
||||
return this.http.post('/sendResetPwdEmail', {email: emailStr}, false);
|
||||
}
|
||||
|
||||
imgCodeVerify(codeStr: string) {
|
||||
return this.http.post('/verCode', {code: codeStr}, false);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user