从"Blog"仓库中分离出来
This commit is contained in:
12
admin/src/app/services/article/article.service.spec.ts
Normal file
12
admin/src/app/services/article/article.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
49
admin/src/app/services/article/article.service.ts
Normal file
49
admin/src/app/services/article/article.service.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {Page} from '../../classes/page';
|
||||
import {Article} from '../../classes/article';
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {exist} from '../../utils/dataUtil';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ArticleService {
|
||||
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
// 存储所有已经请求过的数据<首页数据>
|
||||
pageList: Page<Article>[] = [];
|
||||
|
||||
currentPage: Page<Article>;
|
||||
|
||||
/**
|
||||
* 获取文章
|
||||
* @param pageNum 页码数
|
||||
* @param pageSize 单页数据量
|
||||
*/
|
||||
getArticle(pageNum: number, pageSize: number): object {
|
||||
const articlePage = exist<Article>(pageNum, pageSize, this.pageList);
|
||||
if (articlePage) {
|
||||
articlePage.subscribe(data => {
|
||||
this.currentPage = data;
|
||||
});
|
||||
return articlePage;
|
||||
}
|
||||
const observable = this.http.get('/admin/articles?page=' + pageNum + '&count=' + pageSize);
|
||||
observable.subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.currentPage = data.result;
|
||||
this.pageList.push(data.result);
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
deleteArticle(id) {
|
||||
return this.http.delete('/admin/article/del?articleID=' + id);
|
||||
}
|
||||
|
||||
}
|
||||
12
admin/src/app/services/category/category.service.spec.ts
Normal file
12
admin/src/app/services/category/category.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
56
admin/src/app/services/category/category.service.ts
Normal file
56
admin/src/app/services/category/category.service.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {Category} from '../../classes/category';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CategoryService {
|
||||
|
||||
// FIXME : !!!!!!!!!!!!!!!!!!数据处理全部放到一个模块中!!!!!!!!!!!!!!!!!!
|
||||
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;
|
||||
}
|
||||
|
||||
update(submitBody: { id: number, name: string }) {
|
||||
return this.http.put('/admin/category/update', submitBody, false);
|
||||
}
|
||||
|
||||
create(nameStr: string) {
|
||||
const observable = this.http.post('/admin/category/create', {name: nameStr}, false);
|
||||
observable.subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.categories.push(data.result);
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
delete(id: number) {
|
||||
const observable = this.http.delete(`/admin/category/del?id=${id}`);
|
||||
observable.subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
// tslint:disable-next-line:prefer-for-of
|
||||
for (let i = 0; i < this.categories.length; i++) {
|
||||
if (this.categories[i].id === id) {
|
||||
this.categories.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
}
|
||||
12
admin/src/app/services/comment/comment.service.spec.ts
Normal file
12
admin/src/app/services/comment/comment.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
98
admin/src/app/services/comment/comment.service.ts
Normal file
98
admin/src/app/services/comment/comment.service.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {Page} from '../../classes/page';
|
||||
import {Comment} from '../../classes/comment';
|
||||
import {exist} from '../../utils/dataUtil';
|
||||
import {CommentReq} from "../../classes/commentReq";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CommentService {
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
// 存放
|
||||
leaveMsgPage: Page<Comment>[] = [];
|
||||
|
||||
commentPage: Page<Comment>[] = [];
|
||||
|
||||
currentComment: Page<Comment>;
|
||||
|
||||
currentLeaveMsg: Page<Comment>;
|
||||
|
||||
/**
|
||||
* 获取 评论
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 单页数据数量
|
||||
* @param isAdmin 是否是管理员
|
||||
*/
|
||||
getComments(pageNum: number, pageSize: number, isAdmin: boolean) {
|
||||
const exist1 = exist<Comment>(pageNum, pageSize, this.commentPage);
|
||||
if (exist1) {
|
||||
exist1.subscribe(data => {
|
||||
this.currentComment = data;
|
||||
});
|
||||
return exist1;
|
||||
}
|
||||
const observable = this.http.get(`/${isAdmin ? 'admin' : 'user'}/comment/type/1?count=${pageSize}&page=${pageNum}`);
|
||||
observable.subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.commentPage.unshift(data.result);
|
||||
this.currentComment = data.result;
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 留言
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 单页数据数量
|
||||
* @param isAdmin 是否是管理员
|
||||
*/
|
||||
getLeaveMsg(pageNum: number, pageSize: number, isAdmin: boolean) {
|
||||
const exist1 = exist<Comment>(pageNum, pageSize, this.leaveMsgPage);
|
||||
if (exist1) {
|
||||
exist1.subscribe(data => {
|
||||
this.currentLeaveMsg = data;
|
||||
});
|
||||
return exist1;
|
||||
}
|
||||
const observable = this.http.get(`/${isAdmin ? 'admin' : 'user'}/comment/type/0?count=${pageSize}&page=${pageNum}`);
|
||||
observable.subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.leaveMsgPage.unshift(data.result);
|
||||
this.currentLeaveMsg = data.result;
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复评论/留言
|
||||
* @param responseComment 请求体
|
||||
*/
|
||||
rely(responseComment: CommentReq) {
|
||||
return this.http.post('/user/comment/create', responseComment, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过父评论 获取回复
|
||||
* @param pid 父评论id
|
||||
*/
|
||||
getByPid(pid: number) {
|
||||
return this.http.get('/comment/pid/' + pid + '?count=5&page=1');
|
||||
}
|
||||
|
||||
update(subComment) {
|
||||
return this.http.put('/user/comment/update', subComment);
|
||||
}
|
||||
|
||||
delete(id: number) {
|
||||
return this.http.delete('/user/comment/del?id=' + id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
12
admin/src/app/services/http.service.spec.ts
Normal file
12
admin/src/app/services/http.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
103
admin/src/app/services/http.service.ts
Normal file
103
admin/src/app/services/http.service.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import {environment} from '../../environments/environment';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Data} from '../classes/data';
|
||||
import {reqBody2Str} from '../utils/dataUtil';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class HttpService {
|
||||
|
||||
constructor(public httpClient: 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.httpClient.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,
|
||||
'Content-Type': isJson ? 'application/json' : 'application/x-www-form-urlencoded'
|
||||
}),
|
||||
withCredentials: true
|
||||
};
|
||||
return this.httpClient.post<Data>(this.getPath(path), isJson ? reqBody : reqBody2Str(reqBody), Options);
|
||||
}
|
||||
|
||||
/**
|
||||
* put 请求
|
||||
* @param path 请求路径
|
||||
* @param reqBody 请求体
|
||||
* @param isJson 是否发生json格式数据到服务器
|
||||
*/
|
||||
put(path: string, reqBody: object, isJson: boolean = false): Observable<Data> {
|
||||
const Options = {
|
||||
headers: new HttpHeaders({
|
||||
Accept: '*/*',
|
||||
Authorization: this.token,
|
||||
'Content-Type': isJson ? 'application/json' : 'application/x-www-form-urlencoded'
|
||||
}),
|
||||
withCredentials: true
|
||||
};
|
||||
return this.httpClient.put<Data>(this.getPath(path), isJson ? reqBody : reqBody2Str(reqBody), Options);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete 请求
|
||||
* @param path 请求路径
|
||||
*/
|
||||
delete(path: string): Observable<Data> {
|
||||
return this.httpClient.delete<Data>(this.getPath(path), this.httpOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查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;
|
||||
}
|
||||
|
||||
removeToken() {
|
||||
localStorage.removeItem('token');
|
||||
this.token = null;
|
||||
}
|
||||
}
|
||||
12
admin/src/app/services/link/link.service.spec.ts
Normal file
12
admin/src/app/services/link/link.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
39
admin/src/app/services/link/link.service.ts
Normal file
39
admin/src/app/services/link/link.service.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {Link} from '../../classes/link';
|
||||
import {Page} from '../../classes/page';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class LinkService {
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
// 不采取存储page[] :: 数据量较少
|
||||
public currentPage: Page<Link>;
|
||||
|
||||
getLinks(pageNum: number, pageSize: number) {
|
||||
const observable = this.http.get(`/admin/links?page=${pageNum}&count=${pageSize}`);
|
||||
observable.subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.currentPage = data.result;
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
update(submitBody: Link) {
|
||||
return this.http.put('/admin/links/update', submitBody, true);
|
||||
}
|
||||
|
||||
create(submitBody: Link) {
|
||||
submitBody.id = null;
|
||||
return this.http.post('/admin/links/create', submitBody, true);
|
||||
}
|
||||
|
||||
delete(id) {
|
||||
return this.http.delete(`/admin/links/del/${id}`);
|
||||
}
|
||||
}
|
||||
12
admin/src/app/services/log/log.service.spec.ts
Normal file
12
admin/src/app/services/log/log.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { LogService } from './log.service';
|
||||
|
||||
describe('LogService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: LogService = TestBed.get(LogService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
22
admin/src/app/services/log/log.service.ts
Normal file
22
admin/src/app/services/log/log.service.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class LogService {
|
||||
|
||||
constructor(private http: HttpService) {
|
||||
}
|
||||
|
||||
logText: string;
|
||||
|
||||
getLog() {
|
||||
// @ts-ignore
|
||||
const observable = this.http.httpClient.get<string>('https://api.celess.cn/blog.log', {responseType: 'text'});
|
||||
observable.subscribe(data => {
|
||||
this.logText = data;
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
}
|
||||
12
admin/src/app/services/tag/tag.service.spec.ts
Normal file
12
admin/src/app/services/tag/tag.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
43
admin/src/app/services/tag/tag.service.ts
Normal file
43
admin/src/app/services/tag/tag.service.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {Tag} from '../../classes/tag';
|
||||
import {Page} from '../../classes/page';
|
||||
import {exist} from '../../utils/dataUtil';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TagService {
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
tagPages: Page<Tag>[] = [];
|
||||
currentTagPage: Page<Tag>;
|
||||
|
||||
getTags(pageNum: number, pageSize: number) {
|
||||
const exist1 = exist<Tag>(pageNum, pageSize, this.tagPages);
|
||||
if (exist1) {
|
||||
exist1.subscribe(data => {
|
||||
this.currentTagPage = data;
|
||||
});
|
||||
return exist1;
|
||||
}
|
||||
const observable = this.http.get(`/tags?count=${pageSize}&page=${pageNum}`);
|
||||
observable.subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.currentTagPage = data.result;
|
||||
this.tagPages.unshift(data.result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
update(id: number, name: string) {
|
||||
return this.http.put(`/admin/tag/update?id=${id}&name=${name}`, null);
|
||||
}
|
||||
|
||||
delete(id: number) {
|
||||
return this.http.delete(`/admin/tag/del?id=${id}`);
|
||||
}
|
||||
|
||||
}
|
||||
12
admin/src/app/services/update/web-update.service.spec.ts
Normal file
12
admin/src/app/services/update/web-update.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
48
admin/src/app/services/update/web-update.service.ts
Normal file
48
admin/src/app/services/update/web-update.service.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {UpdateInfo} from '../../classes/updateInfo';
|
||||
import {Page} from '../../classes/page';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class WebUpdateService {
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
public updateInfoList: Page<UpdateInfo>;
|
||||
|
||||
public lastestUpdateTime: string;
|
||||
|
||||
getUpdateInfo(pageNum: number, pageSize: number) {
|
||||
const observable = this.http.get(`/webUpdate/pages?page=${pageNum}&count=${pageSize}`);
|
||||
observable.subscribe((data: any) => {
|
||||
if (data.code === 0) {
|
||||
this.updateInfoList = data.result;
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
getLastestUpdateTime() {
|
||||
this.http.get('/lastestUpdateTime').subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.lastestUpdateTime = data.result;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
update(submitBody: { id: number, info: string }) {
|
||||
return this.http.put('/admin/webUpdate/update', submitBody, false);
|
||||
}
|
||||
|
||||
create(infoStr: string) {
|
||||
return this.http.post('/admin/webUpdate/create', {info: infoStr}, false);
|
||||
}
|
||||
|
||||
delete(id: number) {
|
||||
return this.http.delete(`/admin/webUpdate/del/${id}`);
|
||||
}
|
||||
}
|
||||
12
admin/src/app/services/user/user.service.spec.ts
Normal file
12
admin/src/app/services/user/user.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
97
admin/src/app/services/user/user.service.ts
Normal file
97
admin/src/app/services/user/user.service.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {User} from '../../classes/user';
|
||||
import {Page} from '../../classes/page';
|
||||
import {exist} from '../../utils/dataUtil';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserService {
|
||||
|
||||
userInfo: User;
|
||||
|
||||
avatarHost: string = 'http://cdn.celess.cn';
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
this.getUserInfo();
|
||||
}
|
||||
|
||||
userPage: Page<User>[] = [];
|
||||
currentUserPage: Page<User>;
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
updateInfo(submitBody: { desc: string, displayName: string }) {
|
||||
const observable = this.http.put('/user/userInfo/update', submitBody, false);
|
||||
observable.subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.userInfo.desc = submitBody.desc;
|
||||
this.userInfo.displayName = submitBody.displayName;
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
|
||||
sendEmail() {
|
||||
return this.http.post('/sendVerifyEmail', {email: this.userInfo.email}, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分页数据
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 单页数据量
|
||||
* @param refresh 是否强制刷新
|
||||
*/
|
||||
getPageUser(pageNum: number, pageSize: number, refresh: boolean = false) {
|
||||
const existData = exist<User>(pageNum, pageSize, this.userPage);
|
||||
if (existData && !refresh) {
|
||||
existData.subscribe(data => {
|
||||
this.currentUserPage = data;
|
||||
});
|
||||
}
|
||||
this.http.get(`/admin/users?page=${pageNum}&count=${pageSize}`).subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.currentUserPage = data.result;
|
||||
this.userPage.unshift(data.result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
delete(id: number) {
|
||||
return this.http.delete(`/admin/user/delete/${id}`);
|
||||
}
|
||||
|
||||
update(user: User) {
|
||||
return this.http.put('/admin/user', user, true);
|
||||
}
|
||||
|
||||
getExistOfEmail(email: string) {
|
||||
return this.http.get(`/emailStatus/${email}`);
|
||||
}
|
||||
}
|
||||
12
admin/src/app/services/visitor/visitor.service.spec.ts
Normal file
12
admin/src/app/services/visitor/visitor.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { VisitorService } from './visitor.service';
|
||||
|
||||
describe('VisitorService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: VisitorService = TestBed.get(VisitorService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
76
admin/src/app/services/visitor/visitor.service.ts
Normal file
76
admin/src/app/services/visitor/visitor.service.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpService} from '../http.service';
|
||||
import {Page} from '../../classes/page';
|
||||
import {Visitor} from '../../classes/visitor';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class VisitorService {
|
||||
|
||||
constructor(public http: HttpService) {
|
||||
}
|
||||
|
||||
public pageList: Page<Visitor>[] = [];
|
||||
public currentPage: Page<Visitor>;
|
||||
|
||||
public dayVisit: number;
|
||||
public totalVisitCount: number;
|
||||
|
||||
private ipLocationList: { ip: string, location: string }[] = [];
|
||||
|
||||
getVisitor(pageNum: number, pageSize: number) {
|
||||
const observable = this.http.get(`/admin/visitor/page?count=${pageSize}&page=${pageNum}&showLocation=false`);
|
||||
observable.subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.pageList.unshift(data.result);
|
||||
this.currentPage = data.result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getDayVisitor() {
|
||||
this.http.get('/dayVisitCount').subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.dayVisit = data.result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getTotalVisitorCount() {
|
||||
this.http.get('/visitor/count').subscribe(data => {
|
||||
this.totalVisitCount = data.result;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
getIp(ip: string) {
|
||||
const location = this.exist(ip);
|
||||
if (location) {
|
||||
return location;
|
||||
}
|
||||
const observable = this.http.get(`/ip/${ip}`);
|
||||
observable.subscribe(data => {
|
||||
if (data.code === 0) {
|
||||
this.ipLocationList.unshift(data.result);
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
getLocalIp() {
|
||||
return this.http.get('/ip');
|
||||
}
|
||||
|
||||
private exist(ip): string {
|
||||
if (this.ipLocationList.length === 0) {
|
||||
return null;
|
||||
}
|
||||
// tslint:disable-next-line:prefer-for-of
|
||||
for (let i = 0; i < this.ipLocationList.length; i++) {
|
||||
if (this.ipLocationList[i].ip === ip) {
|
||||
return this.ipLocationList[i].location;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user