style: eslint fix

This commit is contained in:
禾几海
2021-03-12 16:11:09 +08:00
parent b65b25c1fa
commit 33d7bbaf43
35 changed files with 262 additions and 254 deletions

View File

@@ -33,7 +33,7 @@ export class ApiService {
path: '/admin/article/del', path: '/admin/article/del',
method: 'DELETE', method: 'DELETE',
queryParam: {articleID: id} queryParam: {articleID: id}
}) });
} }
articles(pageNumber: number = 1, pageSize: number = 5) { articles(pageNumber: number = 1, pageSize: number = 5) {
@@ -140,7 +140,7 @@ export class ApiService {
} }
tagsNac() { tagsNac() {
return this.httpService.Service<{ name: string, size: number }[]>({ return this.httpService.Service<{ name: string; size: number }[]>({
path: '/tags/nac', path: '/tags/nac',
method: 'GET' method: 'GET'
}); });
@@ -232,11 +232,11 @@ export class ApiService {
counts() { counts() {
return this.httpService.Service<{ return this.httpService.Service<{
articleCount: number, articleCount: number;
visitorCount: number, visitorCount: number;
categoryCount: number, categoryCount: number;
tagCount: number, tagCount: number;
commentCount: number commentCount: number;
}>({ }>({
path: '/counts', path: '/counts',
method: 'GET' method: 'GET'
@@ -394,7 +394,7 @@ export class ApiService {
method: 'PUT', method: 'PUT',
data: user, data: user,
contentType: 'application/json' contentType: 'application/json'
}) });
} }
deleteUser(id: number) { deleteUser(id: number) {
@@ -418,7 +418,7 @@ export class ApiService {
return this.httpService.Service<boolean>({ return this.httpService.Service<boolean>({
path: `/emailStatus/${email}`, path: `/emailStatus/${email}`,
method: 'GET' method: 'GET'
}) });
} }
updateUserInfo(descStr: string, disPlayNameStr: string) { updateUserInfo(descStr: string, disPlayNameStr: string) {
@@ -491,14 +491,14 @@ export class ApiService {
} }
webUpdate() { webUpdate() {
return this.httpService.Service<{ id: number, info: string, time: string }[]>({ return this.httpService.Service<{ id: number; info: string; time: string }[]>({
path: '/webUpdate', path: '/webUpdate',
method: 'GET' method: 'GET'
}); });
} }
webUpdatePage(pageSize: number = 10, pageNumber: number = 1) { webUpdatePage(pageSize: number = 10, pageNumber: number = 1) {
return this.httpService.Service<PageList<{ id: number, info: string, time: string }>>({ return this.httpService.Service<PageList<{ id: number; info: string; time: string }>>({
path: '/webUpdate/pages', path: '/webUpdate/pages',
method: 'GET', method: 'GET',
queryParam: { queryParam: {
@@ -515,7 +515,7 @@ export class ApiService {
lastCommit: string; lastCommit: string;
committerAuthor: string; committerAuthor: string;
committerDate: string; committerDate: string;
commitUrl: string commitUrl: string;
}>({ }>({
path: '/lastestUpdate', path: '/lastestUpdate',
method: 'GET' method: 'GET'

View File

@@ -62,7 +62,7 @@ export class HttpService {
} }
if (o.body.code !== 0) { if (o.body.code !== 0) {
observer.error(o.body); observer.error(o.body);
errorService.httpException(o.body, request) errorService.httpException(o.body, request);
} else { } else {
observer.next(o.body); observer.next(o.body);
} }
@@ -71,7 +71,7 @@ export class HttpService {
error: err => { error: err => {
errorService.httpError(err, request); errorService.httpError(err, request);
errorService.checkConnection(); errorService.checkConnection();
this.subscriptionQueue.splice(this.subscriptionQueue.indexOf(subscription), 1) this.subscriptionQueue.splice(this.subscriptionQueue.indexOf(subscription), 1);
}, },
complete: () => this.subscriptionQueue.splice(this.subscriptionQueue.indexOf(subscription), 1) complete: () => this.subscriptionQueue.splice(this.subscriptionQueue.indexOf(subscription), 1)
}); });
@@ -117,6 +117,7 @@ export class HttpService {
/** /**
* 验证并且处理拼接 URl * 验证并且处理拼接 URl
*
* @param req Request * @param req Request
*/ */
private checkUrl(req: RequestObj): string { private checkUrl(req: RequestObj): string {

View File

@@ -14,5 +14,5 @@ export class ApplyLinkReq {
iconPath: string; iconPath: string;
linkUrl: string; linkUrl: string;
name: string; name: string;
url: string url: string;
} }

View File

@@ -8,7 +8,7 @@ export class User {
role?: string; role?: string;
token?: string; token?: string;
pwd?: string; pwd?: string;
recentlyLandedDate?: string recentlyLandedDate?: string;
} }
export class LoginReq { export class LoginReq {

View File

@@ -12,9 +12,9 @@ export class AdminHeaderComponent implements OnInit {
constructor(private userService: GlobalUserService) { constructor(private userService: GlobalUserService) {
} }
user: User user: User;
@Output() infoClicked = new EventEmitter<void>() @Output() infoClicked = new EventEmitter<void>();
noAvatarUrl = 'https://cdn.celess.cn/' noAvatarUrl = 'https://cdn.celess.cn/';
logout = () => this.userService.logout(); logout = () => this.userService.logout();
infoClickedEvent = () => this.infoClicked.emit(); infoClickedEvent = () => this.infoClicked.emit();
@@ -23,7 +23,7 @@ export class AdminHeaderComponent implements OnInit {
next: data => this.user = data.result, next: data => this.user = data.result,
error: err => this.user = null, error: err => this.user = null,
complete: null complete: null
}) });
} }
} }

View File

@@ -50,7 +50,7 @@ export class HeaderComponent implements OnInit {
@Output() registrationEvent = new EventEmitter(); @Output() registrationEvent = new EventEmitter();
size: 'large' | 'default'; size: 'large' | 'default';
currentPath: string; currentPath: string;
noAvatarUrl = 'https://cdn.celess.cn/' noAvatarUrl = 'https://cdn.celess.cn/';
public pageList: { public pageList: {
path: string; path: string;
@@ -137,7 +137,7 @@ export class HeaderComponent implements OnInit {
} }
toAdminPage() { toAdminPage() {
this.router.navigateByUrl('/admin') this.router.navigateByUrl('/admin');
} }
} }

View File

@@ -9,16 +9,16 @@ import {Observable, of, Subscriber} from 'rxjs';
export class ComponentStateService { export class ComponentStateService {
constructor(private router: Router) { constructor(private router: Router) {
this.watchRouterChange() this.watchRouterChange();
} }
visible = { visible = {
header: true, header: true,
footer: true, footer: true,
globalBackToTop: true globalBackToTop: true
} };
currentPath: string currentPath: string;
getCurrentRouterPath = () => this.currentPath; getCurrentRouterPath = () => this.currentPath;
watchRouterChange() { watchRouterChange() {
@@ -31,9 +31,9 @@ export class ComponentStateService {
// lastIndexOf ==> 0/index // lastIndexOf ==> 0/index
const indexOf = path.lastIndexOf('/'); const indexOf = path.lastIndexOf('/');
const prefix = path.substr(0, indexOf === 0 ? path.length : indexOf); const prefix = path.substr(0, indexOf === 0 ? path.length : indexOf);
this.dealWithPathChange(prefix) this.dealWithPathChange(prefix);
this.currentPath = prefix; this.currentPath = prefix;
if (subscriber) subscriber.next(prefix) if (subscriber) {subscriber.next(prefix);}
}); });
return ob; return ob;
} }
@@ -41,18 +41,18 @@ export class ComponentStateService {
private dealWithPathChange(path) { private dealWithPathChange(path) {
// eslint-disable-next-line guard-for-in // eslint-disable-next-line guard-for-in
for (const visibleKey in this.visible) { for (const visibleKey in this.visible) {
this.visible[visibleKey] = true this.visible[visibleKey] = true;
} }
switch (path) { switch (path) {
case '/admin': case '/admin':
this.visible.header = false this.visible.header = false;
this.visible.footer = false this.visible.footer = false;
this.visible.globalBackToTop = false this.visible.globalBackToTop = false;
break break;
case '/user': case '/user':
case '/write': case '/write':
this.visible.footer = false this.visible.footer = false;
this.visible.globalBackToTop = false this.visible.globalBackToTop = false;
break; break;
default: default:

View File

@@ -21,12 +21,12 @@ export class ErrorService {
} }
private static HTTP_ERROR_COUNT: number = 0; private static HTTP_ERROR_COUNT: number = 0;
private readonly MAINTAIN_PAGE_PREFIX = '/maintain' private readonly MAINTAIN_PAGE_PREFIX = '/maintain';
private readonly ADMIN_PAGE_PREFIX = '/admin' private readonly ADMIN_PAGE_PREFIX = '/admin';
public httpError(err: any, request: RequestObj) { public httpError(err: any, request: RequestObj) {
if (!environment.production) { if (!environment.production) {
console.log('error=>', err, request) console.log('error=>', err, request);
} }
ErrorService.HTTP_ERROR_COUNT++; ErrorService.HTTP_ERROR_COUNT++;
// this.httpService.getSubscriptionQueue().map(a => a.unsubscribe()) // this.httpService.getSubscriptionQueue().map(a => a.unsubscribe())
@@ -34,8 +34,8 @@ export class ErrorService {
public httpException(response: Response<any>, request: RequestObj) { public httpException(response: Response<any>, request: RequestObj) {
if (!environment.production) if (!environment.production)
console.log('exception=>', response, request) {console.log('exception=>', response, request);}
if (response.code === -1 && response.msg === '重复请求') return if (response.code === -1 && response.msg === '重复请求') {return;}
if (this.componentStateService.currentPath === this.ADMIN_PAGE_PREFIX) { if (this.componentStateService.currentPath === this.ADMIN_PAGE_PREFIX) {
this.notification.create('error', `请求失败<${response.code}>`, `${response.msg}`); this.notification.create('error', `请求失败<${response.code}>`, `${response.msg}`);
} }
@@ -62,16 +62,16 @@ export class ErrorService {
path: '/headerInfo', path: '/headerInfo',
method: 'GET', method: 'GET',
url: environment.host + '/headerInfo' url: environment.host + '/headerInfo'
} };
this.injector.get(HttpService).get(req).subscribe({ this.injector.get(HttpService).get(req).subscribe({
next: () => null, next: () => null,
error: () => { error: () => {
if (this.componentStateService.currentPath !== this.MAINTAIN_PAGE_PREFIX) { if (this.componentStateService.currentPath !== this.MAINTAIN_PAGE_PREFIX) {
this.router.navigateByUrl(this.MAINTAIN_PAGE_PREFIX) this.router.navigateByUrl(this.MAINTAIN_PAGE_PREFIX);
} }
ErrorService.HTTP_ERROR_COUNT = 0; ErrorService.HTTP_ERROR_COUNT = 0;
} }
}) });
} }
} }
} }

View File

@@ -23,24 +23,24 @@ export class GlobalUserService {
private multicastArray: Observer<Response<User>>[] = []; private multicastArray: Observer<Response<User>>[] = [];
watchUserInfo(observer: Observer<Response<User>>) { watchUserInfo(observer: Observer<Response<User>>) {
if (this.userObserverArray.indexOf(observer) < 0) this.userObserverArray.push(observer); if (this.userObserverArray.indexOf(observer) < 0) {this.userObserverArray.push(observer);}
this.multicastArray = [...this.userObserverArray]; this.multicastArray = [...this.userObserverArray];
let subscription: Subscription = null; let subscription: Subscription = null;
const unsubscribe = () => { const unsubscribe = () => {
this.userObserverArray.splice(this.userObserverArray.indexOf(observer), 1); this.userObserverArray.splice(this.userObserverArray.indexOf(observer), 1);
observer.complete(); observer.complete();
if (subscription) subscription.unsubscribe(); if (subscription) {subscription.unsubscribe();}
}; };
if (this.lastRequestTime && Date.now() - this.lastRequestTime < 3000) { if (this.lastRequestTime && Date.now() - this.lastRequestTime < 3000) {
if (this.userInfo && this.multicastArray.length) { if (this.userInfo && this.multicastArray.length) {
this.broadcast() this.broadcast();
this.lastRequestTime = Date.now(); this.lastRequestTime = Date.now();
} }
return {unsubscribe} return {unsubscribe};
} }
// 获取数据 // 获取数据
subscription = this.getUserInfoFromServer(); subscription = this.getUserInfoFromServer();
return {unsubscribe} return {unsubscribe};
} }
// 刷新用户信息 // 刷新用户信息
@@ -59,7 +59,7 @@ export class GlobalUserService {
// this.localStorageService.setUser(o.result); // this.localStorageService.setUser(o.result);
// this.userObserver.next(o); // this.userObserver.next(o);
this.userInfo = o.result; this.userInfo = o.result;
this.broadcast() this.broadcast();
observer.next(o); observer.next(o);
observer.complete(); observer.complete();
}, },
@@ -82,7 +82,7 @@ export class GlobalUserService {
// 如果不需要返回消息也ok // 如果不需要返回消息也ok
this.apiService.logout().subscribe(data => { this.apiService.logout().subscribe(data => {
this.localStorageService.clear(); this.localStorageService.clear();
this.broadcast() this.broadcast();
if (observer) { if (observer) {
observer.next(data); observer.next(data);
observer.complete(); observer.complete();
@@ -93,7 +93,7 @@ export class GlobalUserService {
observer.error(error); observer.error(error);
observer.complete(); observer.complete();
} }
}) });
} }
getUserInfoFromServer(observer?: Observer<Response<User>>) { getUserInfoFromServer(observer?: Observer<Response<User>>) {
@@ -102,7 +102,7 @@ export class GlobalUserService {
this.lastRequestTime = Date.now(); this.lastRequestTime = Date.now();
this.userInfo = o.result; this.userInfo = o.result;
// this.localStorageService.setUser(o.result); // this.localStorageService.setUser(o.result);
this.broadcast() this.broadcast();
if (observer) { if (observer) {
observer.next(o); observer.next(o);
observer.complete(); observer.complete();
@@ -118,12 +118,12 @@ export class GlobalUserService {
if (err.code === -1) { if (err.code === -1) {
// 请求重复 // 请求重复
return return;
} }
// this.requested = false; // this.requested = false;
// this.localStorageService.removeToken(); // this.localStorageService.removeToken();
this.multicastArray.forEach(ob => ob.next(new Response<User>(this.userInfo))) this.multicastArray.forEach(ob => ob.next(new Response<User>(this.userInfo)));
this.multicastArray.forEach(ob => ob.error(err)) this.multicastArray.forEach(ob => ob.error(err));
this.multicastArray.splice(0, this.multicastArray.length); this.multicastArray.splice(0, this.multicastArray.length);
} }
@@ -131,7 +131,7 @@ export class GlobalUserService {
} }
private broadcast() { private broadcast() {
this.multicastArray.forEach(ob => ob.next(new Response<User>(this.userInfo))) this.multicastArray.forEach(ob => ob.next(new Response<User>(this.userInfo)));
this.multicastArray.splice(0, this.multicastArray.length); this.multicastArray.splice(0, this.multicastArray.length);
} }
} }

View File

@@ -1,6 +1,6 @@
export class Color { export class Color {
bgColor: string; bgColor: string;
fontColor: string fontColor: string;
} }
export const ColorList: Color[] = [ export const ColorList: Color[] = [
@@ -13,23 +13,24 @@ export const ColorList: Color[] = [
{bgColor: '#177cb0', fontColor: '#ffffff'}, // 靛青 {bgColor: '#177cb0', fontColor: '#ffffff'}, // 靛青
]; ];
export const ColorListLength = ColorList.length export const ColorListLength = ColorList.length;
/** /**
* 获取一组随机颜色 * 获取一组随机颜色
*
* @param count 数量 * @param count 数量
*/ */
export function RandomColor(count: number = 1): Color[] { export function RandomColor(count: number = 1): Color[] {
const map = new Map<number, number>(); const map = new Map<number, number>();
ColorList.forEach((color, index) => map.set(index, 0)) ColorList.forEach((color, index) => map.set(index, 0));
const colorArray: Color[] = []; const colorArray: Color[] = [];
const oneRandomColor = () => { const oneRandomColor = () => {
const minValue = Math.min.apply(null, Array.from(map.values())) const minValue = Math.min.apply(null, Array.from(map.values()));
const keys = Array.from(map.keys()).filter(key => map.get(key) === minValue); const keys = Array.from(map.keys()).filter(key => map.get(key) === minValue);
const keyIndex = Math.floor(Math.random() * keys.length); const keyIndex = Math.floor(Math.random() * keys.length);
const index = keys[keyIndex]; const index = keys[keyIndex];
map.set(index, minValue + 1); map.set(index, minValue + 1);
return ColorList[index] return ColorList[index];
}; };
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
colorArray.push(oneRandomColor()); colorArray.push(oneRandomColor());

View File

@@ -3,6 +3,7 @@ import {PageList} from '../class/HttpReqAndResp';
/** /**
* 判断 一个Page<any>[] 中是否存在一条已查询的数据 * 判断 一个Page<any>[] 中是否存在一条已查询的数据
*
* @param pageNum 页码 * @param pageNum 页码
* @param pageSize 单页数量 * @param pageSize 单页数量
* @param pageList 源数据 * @param pageList 源数据
@@ -19,7 +20,7 @@ export function exist<T>(pageNum: number, pageSize: number, pageList: PageList<a
const ob: Observable<PageList<T>> = new Observable(o => { const ob: Observable<PageList<T>> = new Observable(o => {
o.next(pageList[i]); o.next(pageList[i]);
o.complete(); o.complete();
}) });
} }
} }
return null; return null;

View File

@@ -15,8 +15,8 @@ import {Router} from '@angular/router';
export class AdminArticleComponent implements OnInit { export class AdminArticleComponent implements OnInit {
request: RequestObj; request: RequestObj;
headData: Data<Article>[] headData: Data<Article>[];
@ViewChild('commonTableComponent') private commonTableComponent: CommonTableComponent<Article> @ViewChild('commonTableComponent') private commonTableComponent: CommonTableComponent<Article>;
constructor(private apiService: ApiService, private nzMessage: NzMessageService, private title: Title, constructor(private apiService: ApiService, private nzMessage: NzMessageService, private title: Title,
private router: Router) { private router: Router) {
@@ -27,11 +27,11 @@ export class AdminArticleComponent implements OnInit {
page: 1, page: 1,
count: 10 count: 10
} }
} };
} }
ngOnInit(): void { ngOnInit(): void {
this.title.setTitle('小海博客 | 文章管理') this.title.setTitle('小海博客 | 文章管理');
this.headData = [ this.headData = [
{title: '主键', fieldValue: 'id', show: false, primaryKey: true}, {title: '主键', fieldValue: 'id', show: false, primaryKey: true},
{title: '标题', fieldValue: 'title', show: true}, {title: '标题', fieldValue: 'title', show: true},
@@ -54,18 +54,18 @@ export class AdminArticleComponent implements OnInit {
{name: '编辑', color: '#2db7f5', click: (d) => this.router.navigateByUrl(`/write?id=${d.id}`)}, {name: '编辑', color: '#2db7f5', click: (d) => this.router.navigateByUrl(`/write?id=${d.id}`)},
] ]
} }
] ];
} }
deleteArticle(article: Article) { deleteArticle(article: Article) {
this.apiService.deleteArticle(article.id).subscribe({ this.apiService.deleteArticle(article.id).subscribe({
next: data => { next: data => {
this.nzMessage.success('删除成功') this.nzMessage.success('删除成功');
this.commonTableComponent.getData(); this.commonTableComponent.getData();
}, },
error: err => { error: err => {
this.nzMessage.error(err.msg) this.nzMessage.error(err.msg);
} }
}) });
} }
} }

View File

@@ -19,26 +19,26 @@ export class AdminCommentComponent implements OnInit {
editInfo = { editInfo = {
id: null, id: null,
content: new CommentReq(null), content: new CommentReq(null),
} };
headData: Data<Comment>[]; headData: Data<Comment>[];
modalData = { modalData = {
visible: false, visible: false,
comment: null comment: null
} };
@ViewChild('editableTagComponent') editableTagComponent: EditableTagComponent; @ViewChild('editableTagComponent') editableTagComponent: EditableTagComponent;
@ViewChild('commonTableComponent') commonTableComponent: CommonTableComponent<Comment>; @ViewChild('commonTableComponent') commonTableComponent: CommonTableComponent<Comment>;
constructor(private apiService: ApiService, private messageService: NzMessageService, private userService: GlobalUserService, constructor(private apiService: ApiService, private messageService: NzMessageService, private userService: GlobalUserService,
private title: Title) { private title: Title) {
this.title.setTitle('小海博客 | 评论管理') this.title.setTitle('小海博客 | 评论管理');
this.userService.watchUserInfo({ this.userService.watchUserInfo({
next: data => { next: data => {
let pathStr; let pathStr;
if (data.result) { if (data.result) {
if (data.result.role === 'admin') { if (data.result.role === 'admin') {
pathStr = '/admin/comment/pagePath/*' pathStr = '/admin/comment/pagePath/*';
} else { } else {
pathStr = '/user/comment/pagePath/*' pathStr = '/user/comment/pagePath/*';
} }
this.request = { this.request = {
path: pathStr, path: pathStr,
@@ -47,12 +47,12 @@ export class AdminCommentComponent implements OnInit {
page: 1, page: 1,
count: 10 count: 10
} }
} };
} }
}, },
error: () => null, error: () => null,
complete: () => null complete: () => null
}) });
} }
ngOnInit(): void { ngOnInit(): void {
@@ -74,7 +74,7 @@ export class AdminCommentComponent implements OnInit {
{ {
name: '查看', name: '查看',
click: data => { click: data => {
this.modalData.visible = true this.modalData.visible = true;
this.modalData.comment = data; this.modalData.comment = data;
} }
}, },
@@ -88,13 +88,13 @@ export class AdminCommentComponent implements OnInit {
deleteComment(data: Comment) { deleteComment(data: Comment) {
if (data.status === 3) { if (data.status === 3) {
this.messageService.error('该数据已被删除'); this.messageService.error('该数据已被删除');
return return;
} }
this.apiService.deleteComment(data.id).subscribe({ this.apiService.deleteComment(data.id).subscribe({
next: () => this.messageService.success('删除评论成功'), next: () => this.messageService.success('删除评论成功'),
error: err => this.messageService.error(err.msg), error: err => this.messageService.error(err.msg),
complete: () => this.commonTableComponent.getData() complete: () => this.commonTableComponent.getData()
}) });
} }
edit() { edit() {
@@ -106,7 +106,7 @@ export class AdminCommentComponent implements OnInit {
this.messageService.success(err.msg); this.messageService.success(err.msg);
}, },
complete: () => null complete: () => null
}) });
} }
textChange(value: { value: string; originalValue: string; changed: boolean }, data: Comment) { textChange(value: { value: string; originalValue: string; changed: boolean }, data: Comment) {
@@ -115,7 +115,7 @@ export class AdminCommentComponent implements OnInit {
this.editInfo.content.pid = data.pid; this.editInfo.content.pid = data.pid;
this.editInfo.content.id = data.id; this.editInfo.content.id = data.id;
this.editInfo.content.content = value.value; this.editInfo.content.content = value.value;
this.edit() this.edit();
} }
} }
} }

View File

@@ -14,12 +14,12 @@ export class AdminDashboardComponent implements OnInit {
logLoading: boolean = true; logLoading: boolean = true;
logText: string = null; logText: string = null;
counts: { counts: {
articleCount: number, articleCount: number;
visitorCount: number, visitorCount: number;
categoryCount: number, categoryCount: number;
tagCount: number, tagCount: number;
commentCount: number commentCount: number;
} = {articleCount: 0, visitorCount: 0, categoryCount: 0, tagCount: 0, commentCount: 0} } = {articleCount: 0, visitorCount: 0, categoryCount: 0, tagCount: 0, commentCount: 0};
dayVisitCount: number = 0; dayVisitCount: number = 0;
userInfo: User = new User(); userInfo: User = new User();
private isRequested: boolean = false; private isRequested: boolean = false;
@@ -36,21 +36,21 @@ export class AdminDashboardComponent implements OnInit {
getLog() { getLog() {
this.http.get('https://api.celess.cn/blog.log', {responseType: 'text'}).subscribe(data => { this.http.get('https://api.celess.cn/blog.log', {responseType: 'text'}).subscribe(data => {
this.logText = data; this.logText = data;
this.logLoading = false this.logLoading = false;
}); });
} }
getCounts = () => this.apiService.counts().subscribe({ getCounts = () => this.apiService.counts().subscribe({
next: data => this.counts = data.result next: data => this.counts = data.result
}) });
getDayVisitCount = () => this.apiService.dayVisitCount().subscribe({ getDayVisitCount = () => this.apiService.dayVisitCount().subscribe({
next: data => this.dayVisitCount = data.result next: data => this.dayVisitCount = data.result
}) });
getUserInfo = () => this.userService.watchUserInfo({ getUserInfo = () => this.userService.watchUserInfo({
next: data => { next: data => {
this.userInfo = data.result this.userInfo = data.result;
if (data.result && data.result.role === 'admin' && !this.isRequested) { if (data.result && data.result.role === 'admin' && !this.isRequested) {
this.getLog(); this.getLog();
this.getCounts(); this.getCounts();
@@ -60,5 +60,5 @@ export class AdminDashboardComponent implements OnInit {
}, },
error: () => null, error: () => null,
complete: () => null complete: () => null
}) });
} }

View File

@@ -19,7 +19,7 @@ export class AdminLinkComponent implements OnInit {
modalTitle: string = ''; modalTitle: string = '';
formGroup: FormGroup; formGroup: FormGroup;
request: RequestObj; request: RequestObj;
@ViewChild('commonTableComponent') commonTableComponent: CommonTableComponent<Link> @ViewChild('commonTableComponent') commonTableComponent: CommonTableComponent<Link>;
headData: Data<Link>[]; headData: Data<Link>[];
constructor(private apiService: ApiService, private messageService: NzMessageService, private title: Title) { constructor(private apiService: ApiService, private messageService: NzMessageService, private title: Title) {
@@ -27,12 +27,19 @@ export class AdminLinkComponent implements OnInit {
this.formGroup = new FormGroup({ this.formGroup = new FormGroup({
id: new FormControl(null), id: new FormControl(null),
name: new FormControl(null, [Validators.required]), name: new FormControl(null, [Validators.required]),
url: new FormControl(null, [Validators.required, Validators.pattern(/^(https:\/\/|http:\/\/|)([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)]), url: new FormControl(null, [
Validators.required,
Validators.pattern(/^(https:\/\/|http:\/\/|)([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)
]
),
open: new FormControl(null, [Validators.required]), open: new FormControl(null, [Validators.required]),
desc: new FormControl(null, [Validators.maxLength(255)]), desc: new FormControl(null, [Validators.maxLength(255)]),
iconPath: new FormControl(null, [Validators.pattern(/^(https:\/\/|http:\/\/|)([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)]), iconPath: new FormControl(null, [
Validators.pattern(/^(https:\/\/|http:\/\/|)([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)
]
),
oper: new FormControl(null) oper: new FormControl(null)
}) });
} }
ngOnInit(): void { ngOnInit(): void {
@@ -43,7 +50,7 @@ export class AdminLinkComponent implements OnInit {
count: 10, count: 10,
page: 1 page: 1
} }
} };
this.headData = [ this.headData = [
{title: '主键', fieldValue: 'id', show: false, primaryKey: true}, {title: '主键', fieldValue: 'id', show: false, primaryKey: true},
{title: '友链名称', fieldValue: 'name', show: true}, {title: '友链名称', fieldValue: 'name', show: true},
@@ -72,19 +79,19 @@ export class AdminLinkComponent implements OnInit {
this.messageService.error('删除失败'); this.messageService.error('删除失败');
}, },
complete: () => null, complete: () => null,
}) });
} }
showEdit(data: Link) { showEdit(data: Link) {
this.modalVisible = true; this.modalVisible = true;
this.modalTitle = '编辑友链信息'; this.modalTitle = '编辑友链信息';
this.formGroup.patchValue(data); this.formGroup.patchValue(data);
this.formGroup.controls.oper.setValue('edit') this.formGroup.controls.oper.setValue('edit');
} }
modalConfirm() { modalConfirm() {
this.modalVisible = false; this.modalVisible = false;
const linkReq: Link = this.formGroup.value const linkReq: Link = this.formGroup.value;
const oper = this.formGroup.value.oper; const oper = this.formGroup.value.oper;
let observable: Observable<Response<Link>>; let observable: Observable<Response<Link>>;
if (oper === 'edit') { if (oper === 'edit') {
@@ -97,13 +104,13 @@ export class AdminLinkComponent implements OnInit {
next: data => this.messageService.success('操作成功'), next: data => this.messageService.success('操作成功'),
error: err => this.messageService.error('操作失败,' + err.msg), error: err => this.messageService.error('操作失败,' + err.msg),
complete: () => this.commonTableComponent.getData() complete: () => this.commonTableComponent.getData()
}) });
} }
addLink() { addLink() {
this.modalVisible = true; this.modalVisible = true;
this.modalTitle = '新增友链信息'; this.modalTitle = '新增友链信息';
this.formGroup.reset(); this.formGroup.reset();
this.formGroup.controls.oper.setValue('add') this.formGroup.controls.oper.setValue('add');
} }
} }

View File

@@ -15,19 +15,19 @@ import {EditableTagComponent} from '../components/editable-tag/editable-tag.comp
}) })
export class AdminTagComponent implements OnInit { export class AdminTagComponent implements OnInit {
categoryCTData: { headData: Data<Category>[], commonTable: CommonTableComponent<Category>, request: RequestObj } = { categoryCTData: { headData: Data<Category>[]; commonTable: CommonTableComponent<Category>; request: RequestObj } = {
headData: null, headData: null,
commonTable: null, commonTable: null,
request: null request: null
} };
tagCTData: { headData: Data<Category>[], commonTable: CommonTableComponent<Tag>, request: RequestObj } = { tagCTData: { headData: Data<Category>[]; commonTable: CommonTableComponent<Tag>; request: RequestObj } = {
headData: null, headData: null,
commonTable: null, commonTable: null,
request: null request: null
} };
@ViewChild('categoryCTComponent', {static: true}) categoryCTComponent: CommonTableComponent<Category> @ViewChild('categoryCTComponent', {static: true}) categoryCTComponent: CommonTableComponent<Category>;
@ViewChild('tagCTComponent', {static: true}) tagCTComponent: CommonTableComponent<Tag> @ViewChild('tagCTComponent', {static: true}) tagCTComponent: CommonTableComponent<Tag>;
@ViewChild('editableTagComponent') editableTagComponent: EditableTagComponent @ViewChild('editableTagComponent') editableTagComponent: EditableTagComponent;
getData: any; getData: any;
private updateData: any; private updateData: any;
@@ -35,7 +35,7 @@ export class AdminTagComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.title.setTitle('小海博客 | 标签分类管理') this.title.setTitle('小海博客 | 标签分类管理');
this.categoryCTData = { this.categoryCTData = {
commonTable: this.categoryCTComponent, commonTable: this.categoryCTComponent,
headData: [ headData: [
@@ -64,7 +64,7 @@ export class AdminTagComponent implements OnInit {
count: 1000 count: 1000
} }
} }
} };
this.tagCTData = { this.tagCTData = {
commonTable: this.tagCTComponent, commonTable: this.tagCTComponent,
headData: [ headData: [
@@ -87,7 +87,7 @@ export class AdminTagComponent implements OnInit {
count: 10 count: 10
} }
} }
} };
this.getData = this.categoryCTComponent.getData; this.getData = this.categoryCTComponent.getData;
} }
@@ -96,29 +96,29 @@ export class AdminTagComponent implements OnInit {
if (mode === 'tag') { if (mode === 'tag') {
this.apiService.deleteTag(id).subscribe({ this.apiService.deleteTag(id).subscribe({
next: data => { next: data => {
this.nzMessageService.success('删除成功') this.nzMessageService.success('删除成功');
this.tagCTComponent.getData(); this.tagCTComponent.getData();
}, },
complete: () => null, complete: () => null,
error: err => this.nzMessageService.error(err.msg) error: err => this.nzMessageService.error(err.msg)
}) });
} else if (mode === 'category') { } else if (mode === 'category') {
this.apiService.deleteCategory(id).subscribe({ this.apiService.deleteCategory(id).subscribe({
next: data => { next: data => {
this.nzMessageService.success('删除成功') this.nzMessageService.success('删除成功');
this.categoryCTComponent.getData(); this.categoryCTComponent.getData();
}, },
complete: () => null, complete: () => null,
error: err => this.nzMessageService.error(err.msg) error: err => this.nzMessageService.error(err.msg)
}) });
} }
} }
addCategory($event: { value: string; originalValue: string; changed: boolean }) { addCategory($event: { value: string; originalValue: string; changed: boolean }) {
if (!$event.value || !$event.changed) return if (!$event.value || !$event.changed) {return;}
this.apiService.createCategory($event.value).subscribe({ this.apiService.createCategory($event.value).subscribe({
next: data => { next: data => {
this.nzMessageService.success('新增成功') this.nzMessageService.success('新增成功');
this.getData = this.categoryCTComponent.getData(); this.getData = this.categoryCTComponent.getData();
}, },
complete: () => null, complete: () => null,
@@ -133,14 +133,14 @@ export class AdminTagComponent implements OnInit {
this.updateData = this.apiService.updateTag; this.updateData = this.apiService.updateTag;
} else { } else {
this.getData = this.tagCTComponent.getData; this.getData = this.tagCTComponent.getData;
this.updateData = this.apiService.updateCategory this.updateData = this.apiService.updateCategory;
} }
} }
textChange(value: { value: string; originalValue: string; changed: boolean }, textData: Category | Tag) { textChange(value: { value: string; originalValue: string; changed: boolean }, textData: Category | Tag) {
this.updateData(textData.id, value.value).subscribe({ this.updateData(textData.id, value.value).subscribe({
next: data => { next: data => {
this.nzMessageService.success('更新成功') this.nzMessageService.success('更新成功');
this.tagCTComponent.getData(); this.tagCTComponent.getData();
this.categoryCTComponent.getData(); this.categoryCTComponent.getData();
}, },

View File

@@ -27,7 +27,7 @@ export class AdminUpdateComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.title.setTitle('小海博客 | 更新信息管理') this.title.setTitle('小海博客 | 更新信息管理');
this.headData = [ this.headData = [
{fieldValue: 'id', show: false, title: '主键', primaryKey: true}, {fieldValue: 'id', show: false, title: '主键', primaryKey: true},
{fieldValue: 'info', show: true, title: '更新内容'}, {fieldValue: 'info', show: true, title: '更新内容'},
@@ -46,7 +46,7 @@ export class AdminUpdateComponent implements OnInit {
count: 1, count: 1,
page: 10, page: 10,
} }
} };
} }
@@ -54,21 +54,21 @@ export class AdminUpdateComponent implements OnInit {
this.apiService.deleteWebUpdateInfo(id).subscribe({ this.apiService.deleteWebUpdateInfo(id).subscribe({
next: data => this.nzMessage.success('删除成功'), next: data => this.nzMessage.success('删除成功'),
error: err => this.nzMessage.error(err.msg) error: err => this.nzMessage.error(err.msg)
}) });
} }
confirm() { confirm() {
this.modalData.visible = false; this.modalData.visible = false;
let observable: Observable<Response<UpdateInfo>> let observable: Observable<Response<UpdateInfo>>;
if (this.modalData.id) { if (this.modalData.id) {
observable = this.apiService.updateWebUpdateInfo(this.modalData.id, this.modalData.content) observable = this.apiService.updateWebUpdateInfo(this.modalData.id, this.modalData.content);
} else { } else {
observable = this.apiService.createWebUpdateInfo(this.modalData.content) observable = this.apiService.createWebUpdateInfo(this.modalData.content);
} }
observable.subscribe({ observable.subscribe({
next: data => this.nzMessage.success('操作成功'), next: data => this.nzMessage.success('操作成功'),
error: err => this.nzMessage.error(err.msg) error: err => this.nzMessage.error(err.msg)
}) });
} }
showModal(data?: UpdateInfo) { showModal(data?: UpdateInfo) {

View File

@@ -20,7 +20,7 @@ export class AdminUserComponent implements OnInit {
title: null, title: null,
isEdit: false, isEdit: false,
resetPwd: false resetPwd: false
} };
formGroup: FormGroup; formGroup: FormGroup;
headData: Data<User>[]; headData: Data<User>[];
request: RequestObj; request: RequestObj;
@@ -40,11 +40,11 @@ export class AdminUserComponent implements OnInit {
next: data => this.user = data.result, next: data => this.user = data.result,
error: null, error: null,
complete: null complete: null
}) });
} }
ngOnInit(): void { ngOnInit(): void {
this.title.setTitle('小海博客 | 用户管理') this.title.setTitle('小海博客 | 用户管理');
this.request = { this.request = {
path: '/admin/users', path: '/admin/users',
method: 'GET', method: 'GET',
@@ -78,24 +78,24 @@ export class AdminUserComponent implements OnInit {
this.apiService.deleteUser(id).subscribe({ this.apiService.deleteUser(id).subscribe({
next: data => this.messageService.success('删除成功'), next: data => this.messageService.success('删除成功'),
error: err => this.messageService.error(err.msg) error: err => this.messageService.error(err.msg)
}) });
} }
showModal(isEdit: boolean, data: User) { showModal(isEdit: boolean, data: User) {
this.modalData.visible = true; this.modalData.visible = true;
this.modalData.isEdit = isEdit; this.modalData.isEdit = isEdit;
this.modalData.title = isEdit ? '编辑用户' : '查看用户' this.modalData.title = isEdit ? '编辑用户' : '查看用户';
this.formGroup.reset(); this.formGroup.reset();
this.formGroup.patchValue(data); this.formGroup.patchValue(data);
} }
modalConfirm() { modalConfirm() {
this.modalData.visible = false this.modalData.visible = false;
this.apiService.adminUpdateUser(this.formGroup.value).subscribe({ this.apiService.adminUpdateUser(this.formGroup.value).subscribe({
next: data => { next: data => {
this.messageService.success('修改用户信息成功'); this.messageService.success('修改用户信息成功');
this.userService.refreshUserInfo(); this.userService.refreshUserInfo();
} }
}) });
} }
} }

View File

@@ -12,13 +12,13 @@ import {Data} from '../components/common-table/data';
export class AdminVisitorComponent implements OnInit { export class AdminVisitorComponent implements OnInit {
headData: Data<Visitor>[]; headData: Data<Visitor>[];
request: RequestObj request: RequestObj;
constructor(private apiService: ApiService, private title: Title) { constructor(private apiService: ApiService, private title: Title) {
} }
ngOnInit(): void { ngOnInit(): void {
this.title.setTitle('小海博客 | 访客信息管理') this.title.setTitle('小海博客 | 访客信息管理');
this.request = { this.request = {
path: '/admin/visitor/page', path: '/admin/visitor/page',
method: 'GET', method: 'GET',
@@ -27,7 +27,7 @@ export class AdminVisitorComponent implements OnInit {
page: 10, page: 10,
showLocation: true showLocation: true
} }
} };
this.headData = [ this.headData = [
{fieldValue: 'id', title: '主键', show: false, primaryKey: true}, {fieldValue: 'id', title: '主键', show: false, primaryKey: true},
{fieldValue: 'date', title: '访问日期', show: true}, {fieldValue: 'date', title: '访问日期', show: true},
@@ -36,6 +36,6 @@ export class AdminVisitorComponent implements OnInit {
{fieldValue: 'browserName', title: '浏览器', show: true}, {fieldValue: 'browserName', title: '浏览器', show: true},
{fieldValue: 'browserVersion', title: '浏览器版本', show: true}, {fieldValue: 'browserVersion', title: '浏览器版本', show: true},
{fieldValue: 'osname', title: '系统', show: true} {fieldValue: 'osname', title: '系统', show: true}
] ];
} }
} }

View File

@@ -25,8 +25,8 @@ export class AdminComponent implements OnInit {
resetPwdModalVisible: boolean = false; resetPwdModalVisible: boolean = false;
editInfoFormGroup: FormGroup; editInfoFormGroup: FormGroup;
resetPwdFormGroup: FormGroup; resetPwdFormGroup: FormGroup;
noAvatarUrl = 'https://cdn.celess.cn/' noAvatarUrl = 'https://cdn.celess.cn/';
host: string host: string;
constructor(public gUserService: GlobalUserService, private apiService: ApiService, private messageService: NzMessageService, constructor(public gUserService: GlobalUserService, private apiService: ApiService, private messageService: NzMessageService,
private router: Router, private localStorageService: LocalStorageService) { private router: Router, private localStorageService: LocalStorageService) {
@@ -34,8 +34,8 @@ export class AdminComponent implements OnInit {
complete: () => null, complete: () => null,
error: (err) => null, error: (err) => null,
next: data => { next: data => {
this.user = data.result this.user = data.result;
if (data.result) this.initHelloWords() if (data.result) {this.initHelloWords();}
} }
} }
); );
@@ -53,29 +53,25 @@ export class AdminComponent implements OnInit {
Validators.required, Validators.minLength(6), Validators.maxLength(16), Validators.pattern(/^[\w_-]{6,16}$/), Validators.required, Validators.minLength(6), Validators.maxLength(16), Validators.pattern(/^[\w_-]{6,16}$/),
this.checkSamePwd() this.checkSamePwd()
]), ]),
}) });
} }
showInfoDrawer = () => this.infoDrawerVisible = !this.infoDrawerVisible; showInfoDrawer = () => this.infoDrawerVisible = !this.infoDrawerVisible;
logout() { logout() {
this.gUserService.logout(); this.gUserService.logout();
this.router.navigateByUrl('/') this.router.navigateByUrl('/');
} }
ngOnInit(): void { ngOnInit(): void {
this.host = environment.host; this.host = environment.host;
} }
checkSamePwd = () => { checkSamePwd = () => (control: AbstractControl): { [key: string]: any } | null => {
return (control: AbstractControl): { [key: string]: any } | null => {
const newPwd = this.resetPwdFormGroup && this.resetPwdFormGroup.value.newPwd; const newPwd = this.resetPwdFormGroup && this.resetPwdFormGroup.value.newPwd;
return control.value !== newPwd ? {pwdNotSame: true} : null; return control.value !== newPwd ? {pwdNotSame: true} : null;
}; };
} uploadHeader = (file: NzUploadFile): any | Observable<{}> => ({Authorization: this.localStorageService.getToken()});
uploadHeader = (file: NzUploadFile): object | Observable<{}> => {
return {Authorization: this.localStorageService.getToken()}
};
showEditInfoModal() { showEditInfoModal() {
this.editInfoModalVisible = true; this.editInfoModalVisible = true;
@@ -88,7 +84,7 @@ export class AdminComponent implements OnInit {
const displayName = this.editInfoFormGroup.value.displayName; const displayName = this.editInfoFormGroup.value.displayName;
this.apiService.updateUserInfo(desc, displayName).subscribe({ this.apiService.updateUserInfo(desc, displayName).subscribe({
next: data => { next: data => {
this.messageService.success('修改信息成功') this.messageService.success('修改信息成功');
this.gUserService.refreshUserInfo(); this.gUserService.refreshUserInfo();
}, },
error: err => { error: err => {
@@ -111,13 +107,13 @@ export class AdminComponent implements OnInit {
error: err => { error: err => {
this.messageService.error('修改密码失败,' + err.msg); this.messageService.error('修改密码失败,' + err.msg);
} }
}) });
this.resetPwdModalVisible = false; this.resetPwdModalVisible = false;
} }
showResetPwdModal() { showResetPwdModal() {
this.resetPwdModalVisible = true; this.resetPwdModalVisible = true;
this.infoDrawerVisible = false this.infoDrawerVisible = false;
} }
avatarUpload(info: any) { avatarUpload(info: any) {
@@ -130,17 +126,17 @@ export class AdminComponent implements OnInit {
private initHelloWords() { private initHelloWords() {
const hours = new Date().getHours(); const hours = new Date().getHours();
if (hours < 6) { if (hours < 6) {
this.sayHelloContent = `夜深了,注意早点休息哦!${this.user.displayName}` this.sayHelloContent = `夜深了,注意早点休息哦!${this.user.displayName}`;
} else if (hours < 10) { } else if (hours < 10) {
this.sayHelloContent = `早上好呀!${this.user.displayName}` this.sayHelloContent = `早上好呀!${this.user.displayName}`;
} else if (hours < 14) { } else if (hours < 14) {
this.sayHelloContent = `中午好呀!${this.user.displayName}` this.sayHelloContent = `中午好呀!${this.user.displayName}`;
} else if (hours < 19) { } else if (hours < 19) {
this.sayHelloContent = `下午好呀!${this.user.displayName}` this.sayHelloContent = `下午好呀!${this.user.displayName}`;
} else if (hours < 22) { } else if (hours < 22) {
this.sayHelloContent = `晚上好呀!${this.user.displayName}` this.sayHelloContent = `晚上好呀!${this.user.displayName}`;
} else { } else {
this.sayHelloContent = `时间不早了,注意休息哦!${this.user.displayName}` this.sayHelloContent = `时间不早了,注意休息哦!${this.user.displayName}`;
} }
} }
} }

View File

@@ -46,7 +46,7 @@ export class AuthGuard implements CanActivate {
this.userInfo = data.result; this.userInfo = data.result;
this.checkPath(observer); this.checkPath(observer);
} }
}) });
} }
@@ -60,7 +60,7 @@ export class AuthGuard implements CanActivate {
case '/admin/visitor': case '/admin/visitor':
if (this.userInfo && this.userInfo.role !== 'admin') { if (this.userInfo && this.userInfo.role !== 'admin') {
observer.next(false); observer.next(false);
if (this.visitCount === 1) this.router.navigateByUrl('/admin') if (this.visitCount === 1) {this.router.navigateByUrl('/admin');}
observer.complete(); observer.complete();
return; return;
} }

View File

@@ -15,11 +15,11 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
@Input() cardTitle: string | null; @Input() cardTitle: string | null;
@Input() template: { @Input() template: {
[fieldValue: string]: { [fieldValue: string]: {
temp: TemplateRef<any>, temp: TemplateRef<any>;
param?: { [key: string]: string } param?: { [key: string]: string };
}
}; };
@Output() pageInfo = new EventEmitter<{ page: number, pageSize: number }>(); };
@Output() pageInfo = new EventEmitter<{ page: number; pageSize: number }>();
loading: boolean = true; loading: boolean = true;
dataList: PageList<T> = new PageList<T>(); dataList: PageList<T> = new PageList<T>();
settingModalVisible: boolean = false; settingModalVisible: boolean = false;
@@ -37,20 +37,20 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
this.filedData = this.cloneData(localStorage.getItem(this.request.path)); this.filedData = this.cloneData(localStorage.getItem(this.request.path));
this.changed = true; this.changed = true;
} else { } else {
this.filedData = this.cloneData(this.headData) this.filedData = this.cloneData(this.headData);
} }
this.calculateVisibleFieldLength(); this.calculateVisibleFieldLength();
if (!this.template) this.template = {} if (!this.template) {this.template = {};}
this.headData.forEach(dat => { this.headData.forEach(dat => {
if (!dat.action) return; if (!dat.action) {return;}
dat.action.forEach(act => { dat.action.forEach(act => {
if (!act.hover) { if (!act.hover) {
act.hover = () => null; act.hover = () => null;
} }
})
}); });
if (!this.request || !this.request.path) return });
if (!this.request || !this.request.path) {return;}
this.getData(); this.getData();
} }
@@ -65,15 +65,15 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
// page: pageValue, // page: pageValue,
// count: countValue // count: countValue
// } // }
this.pageInfo.emit({page: pageValue, pageSize: countValue}) this.pageInfo.emit({page: pageValue, pageSize: countValue});
return this.httpService.Service<PageList<T>>(this.request).subscribe({ return this.httpService.Service<PageList<T>>(this.request).subscribe({
next: resp => { next: resp => {
this.dataList = resp.result; this.dataList = resp.result;
setTimeout(() => this.loading = false, 10) setTimeout(() => this.loading = false, 10);
}, },
error: err => this.loading = false error: err => this.loading = false
}); });
} };
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
if (changes.request && !changes.request.isFirstChange()) { if (changes.request && !changes.request.isFirstChange()) {
@@ -87,7 +87,7 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
getValue(index: number, fieldValue: string): string { getValue(index: number, fieldValue: string): string {
let value = this.dataList.list[index]; let value = this.dataList.list[index];
try { try {
for (const key of fieldValue.split('.')) value = value[key] for (const key of fieldValue.split('.')) {value = value[key];}
} catch (e) { } catch (e) {
// ignore // ignore
} }
@@ -96,21 +96,21 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
getContext = (fieldValue: string, index: number) => { getContext = (fieldValue: string, index: number) => {
const valueData = this.getValue(index, fieldValue); const valueData = this.getValue(index, fieldValue);
let context: { value: string, originValue?: string, data: T }; let context: { value: string; originValue?: string; data: T };
if (this.template[fieldValue].param) { if (this.template[fieldValue].param) {
context = { context = {
value: this.template[fieldValue].param[valueData], value: this.template[fieldValue].param[valueData],
originValue: valueData, originValue: valueData,
data: this.dataList.list[index] data: this.dataList.list[index]
} };
} else { } else {
context = { context = {
value: valueData, value: valueData,
data: this.dataList.list[index] data: this.dataList.list[index]
} };
} }
return context; return context;
} };
showFieldSetting = () => this.settingModalVisible = true; showFieldSetting = () => this.settingModalVisible = true;
@@ -121,10 +121,10 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
this.calculateVisibleFieldLength(); this.calculateVisibleFieldLength();
this.settingModalVisible = !this.settingModalVisible; this.settingModalVisible = !this.settingModalVisible;
if (!this.changed) { if (!this.changed) {
return return;
} }
this.dataList = JSON.parse(JSON.stringify(this.dataList)); this.dataList = JSON.parse(JSON.stringify(this.dataList));
localStorage.setItem(this.request.path, JSON.stringify(this.filedData)) localStorage.setItem(this.request.path, JSON.stringify(this.filedData));
this.changed = true; this.changed = true;
} }
@@ -138,7 +138,7 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
this.filedData = this.cloneData(this.headData); this.filedData = this.cloneData(this.headData);
this.changed = false; this.changed = false;
this.calculateVisibleFieldLength(); this.calculateVisibleFieldLength();
} };
cloneData = (source: Data<T>[] | string): Data<T>[] => { cloneData = (source: Data<T>[] | string): Data<T>[] => {
let dist: Data<T>[]; let dist: Data<T>[];
@@ -151,11 +151,11 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
if (!action) { if (!action) {
return dist; return dist;
} }
const del = dist.filter(value => value.isActionColumns).pop() const del = dist.filter(value => value.isActionColumns).pop();
dist.splice(dist.indexOf(del), 1); dist.splice(dist.indexOf(del), 1);
dist.push(action); dist.push(action);
return dist; return dist;
} };
/** /**
* 字段编辑项被点击 * 字段编辑项被点击
@@ -169,5 +169,5 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
this.changed = true; this.changed = true;
} }
} }
} };
} }

View File

@@ -14,7 +14,7 @@ import {NzTagModule} from 'ng-zorro-antd/tag';
import {NzToolTipModule} from 'ng-zorro-antd/tooltip'; import {NzToolTipModule} from 'ng-zorro-antd/tooltip';
import {NzTypographyModule} from 'ng-zorro-antd/typography'; import {NzTypographyModule} from 'ng-zorro-antd/typography';
import {FormsModule} from '@angular/forms'; import {FormsModule} from '@angular/forms';
import {DragDropModule} from '@angular/cdk/drag-drop' import {DragDropModule} from '@angular/cdk/drag-drop';
@NgModule({ @NgModule({
declarations: [ declarations: [

View File

@@ -7,19 +7,19 @@ export class Data<T> {
primaryKey?: boolean = false; primaryKey?: boolean = false;
isActionColumns?: boolean = false; isActionColumns?: boolean = false;
template?: { template?: {
template: TemplateRef<any>, template: TemplateRef<any>;
keymap?: { keymap?: {
[value: string]: string [value: string]: string;
} };
}; };
// order?: number; // order?: number;
action ?: { action?: {
name: string, name: string;
color?: string, color?: string;
order?: number, order?: number;
fontSize?: string, fontSize?: string;
needConfirm?: boolean, needConfirm?: boolean;
click: (data: T) => void, click: (data: T) => void;
hover?: (data: T) => void | null; hover?: (data: T) => void | null;
}[] = [] }[] = [];
} }

View File

@@ -29,11 +29,11 @@ import {NzModalRef, NzModalService} from 'ng-zorro-antd/modal';
}) })
export class EditableTagComponent implements OnInit, OnChanges { export class EditableTagComponent implements OnInit, OnChanges {
private static instanceArray: EditableTagComponent[] = [] private static instanceArray: EditableTagComponent[] = [];
inputVisible = false; inputVisible = false;
inputValue = ''; inputValue = '';
@ViewChild('inputElement', {static: false}) inputElement?: ElementRef; @ViewChild('inputElement', {static: false}) inputElement?: ElementRef;
@Output() valueChange = new EventEmitter<{ value: string, originalValue: string, changed: boolean }>(); @Output() valueChange = new EventEmitter<{ value: string; originalValue: string; changed: boolean }>();
@Input() color: string; @Input() color: string;
@Input() showEditIcon: boolean; @Input() showEditIcon: boolean;
@Input() showBorder: boolean; @Input() showBorder: boolean;
@@ -44,8 +44,8 @@ export class EditableTagComponent implements OnInit, OnChanges {
@Input() autoClear: boolean; @Input() autoClear: boolean;
@Input() size: 'small' | 'default' | 'large'; @Input() size: 'small' | 'default' | 'large';
@Output() inEditStatus = new EventEmitter<void>(); @Output() inEditStatus = new EventEmitter<void>();
@Output() modalOK = new EventEmitter<{ value: string, originalValue: string, changed: boolean }>(); @Output() modalOK = new EventEmitter<{ value: string; originalValue: string; changed: boolean }>();
@Output() modalCancel = new EventEmitter<{ value: string, originalValue: string, changed: boolean }>(); @Output() modalCancel = new EventEmitter<{ value: string; originalValue: string; changed: boolean }>();
confirmModal?: NzModalRef; confirmModal?: NzModalRef;
private tmpKey: any; private tmpKey: any;
private doubleClickInfo = { private doubleClickInfo = {
@@ -84,17 +84,17 @@ export class EditableTagComponent implements OnInit, OnChanges {
if (this.doubleClick && doubleClick) { if (this.doubleClick && doubleClick) {
if (!this.doubleClickInfo.date) { if (!this.doubleClickInfo.date) {
this.doubleClickInfo.date = new Date().getTime(); this.doubleClickInfo.date = new Date().getTime();
return return;
} }
if (new Date().getTime() - this.doubleClickInfo.date < 200) { if (new Date().getTime() - this.doubleClickInfo.date < 200) {
this.inEditStatus.emit() this.inEditStatus.emit();
this.inputVisible = true; this.inputVisible = true;
setTimeout(() => this.inputElement?.nativeElement.focus(), 10); setTimeout(() => this.inputElement?.nativeElement.focus(), 10);
} }
this.doubleClickInfo.date = new Date().getTime(); this.doubleClickInfo.date = new Date().getTime();
} else { } else {
this.inputVisible = true; this.inputVisible = true;
this.inEditStatus.emit() this.inEditStatus.emit();
setTimeout(() => this.inputElement?.nativeElement.focus(), 10); setTimeout(() => this.inputElement?.nativeElement.focus(), 10);
} }
} }
@@ -105,7 +105,7 @@ export class EditableTagComponent implements OnInit, OnChanges {
if (tag.key === this.tmpKey) { if (tag.key === this.tmpKey) {
tag.showInput(false); tag.showInput(false);
} }
}) });
} }
@@ -114,8 +114,8 @@ export class EditableTagComponent implements OnInit, OnChanges {
value: this.inputValue, value: this.inputValue,
originalValue: this.text, originalValue: this.text,
changed: this.inputValue !== this.text changed: this.inputValue !== this.text
} };
this.valueChange.emit(value) this.valueChange.emit(value);
this.text = this.inputValue; this.text = this.inputValue;
this.inputValue = ''; this.inputValue = '';
this.inputVisible = false; this.inputVisible = false;
@@ -128,7 +128,7 @@ export class EditableTagComponent implements OnInit, OnChanges {
}); });
} }
if (this.autoClear) { if (this.autoClear) {
this.text = null this.text = null;
} }
} }

View File

@@ -62,7 +62,7 @@ updateDateFormat: "2020-05-27 00:55:05"*/
}, },
] ]
} }
] ];
} }
ngOnInit(): void { ngOnInit(): void {
@@ -73,7 +73,7 @@ updateDateFormat: "2020-05-27 00:55:05"*/
page: 1, page: 1,
count: 10 count: 10
} }
} };
} }
} }

View File

@@ -7,9 +7,9 @@ import {User} from '../../class/User';
import {Comment, CommentReq} from '../../class/Comment'; import {Comment, CommentReq} from '../../class/Comment';
import {PageList} from '../../class/HttpReqAndResp'; import {PageList} from '../../class/HttpReqAndResp';
import {GlobalUserService} from '../../services/global-user.service'; import {GlobalUserService} from '../../services/global-user.service';
import VditorPreview from 'vditor/dist/method.min' import VditorPreview from 'vditor/dist/method.min';
declare var $; declare let $;
@Component({ @Component({
selector: 'view-article', selector: 'view-article',
@@ -49,7 +49,7 @@ export class ArticleComponent implements OnInit {
error: (err) => null, error: (err) => null,
next: data => { next: data => {
this.user = data.result; this.user = data.result;
if (data.result) this.avatarImgUrl = data.result.avatarImgUrl; if (data.result) {this.avatarImgUrl = data.result.avatarImgUrl;}
} }
}); });
this.comment = new CommentReq(`article/${this.articleId}`); this.comment = new CommentReq(`article/${this.articleId}`);

View File

@@ -9,12 +9,12 @@ import {Router} from '@angular/router';
}) })
export class TagTagComponent implements OnInit { export class TagTagComponent implements OnInit {
@Input() tag: { name: string, size: number }; @Input() tag: { name: string; size: number };
@Input() size: 'default' | 'large' = 'default'; @Input() size: 'default' | 'large' = 'default';
@Input() clickable: boolean; // default true @Input() clickable: boolean; // default true
@Input() enableCount: boolean; // default true @Input() enableCount: boolean; // default true
@Output() tagClick = new EventEmitter(); @Output() tagClick = new EventEmitter();
randColor: { bgColor: string, fontColor: string }; randColor: { bgColor: string; fontColor: string };
constructor(private router: Router) { constructor(private router: Router) {
} }

View File

@@ -23,14 +23,14 @@ export class IndexComponent implements OnInit {
imgUrl: string; imgUrl: string;
desc: string; desc: string;
articles: PageList<Article>; articles: PageList<Article>;
tagNameAndNumber: { name: string, size: number }[]; tagNameAndNumber: { name: string; size: number }[];
categoryList: Category[]; categoryList: Category[];
counts: { counts: {
articleCount: number, articleCount: number;
visitorCount: number, visitorCount: number;
categoryCount: number, categoryCount: number;
tagCount: number, tagCount: number;
commentCount: number commentCount: number;
}; };
lastestUpdate: { lastestUpdate: {
lastUpdateTime: string; lastUpdateTime: string;
@@ -38,7 +38,7 @@ export class IndexComponent implements OnInit {
lastCommit: string; lastCommit: string;
committerAuthor: string; committerAuthor: string;
committerDate: string; committerDate: string;
commitUrl: string commitUrl: string;
}; };
constructor(private apiService: ApiService, constructor(private apiService: ApiService,

View File

@@ -55,7 +55,7 @@ export class LinkComponent implements OnInit {
this.applyFormGroup.patchValue({linkUrl: linkUrlData.replace(this.lastUrl, data)}); this.applyFormGroup.patchValue({linkUrl: linkUrlData.replace(this.lastUrl, data)});
this.lastUrl = data; this.lastUrl = data;
}, },
}) });
} }
apply() { apply() {
@@ -69,7 +69,7 @@ export class LinkComponent implements OnInit {
this.message.success('提交成功,请稍等,即将为你处理'); this.message.success('提交成功,请稍等,即将为你处理');
this.loading = false; this.loading = false;
this.showModal = false; this.showModal = false;
this.applyFormGroup.reset() this.applyFormGroup.reset();
}, },
error: err => { error: err => {
if (err.code === 7200) { if (err.code === 7200) {
@@ -82,7 +82,7 @@ export class LinkComponent implements OnInit {
this.apiService.reapplyLink(key).subscribe({ this.apiService.reapplyLink(key).subscribe({
next: data1 => this.message.success('提交成功,请稍等,即将为你处理'), next: data1 => this.message.success('提交成功,请稍等,即将为你处理'),
error: err1 => this.message.error('提交失败,原因:' + err.msg) error: err1 => this.message.error('提交失败,原因:' + err.msg)
}) });
} }
}); });
} else { } else {
@@ -90,7 +90,7 @@ export class LinkComponent implements OnInit {
} }
this.loading = false; this.loading = false;
this.showModal = false; this.showModal = false;
this.applyFormGroup.reset() this.applyFormGroup.reset();
} }
}); });
} }

View File

@@ -68,7 +68,7 @@ export class LoginComponent implements OnInit {
this.router.navigateByUrl(this.url); this.router.navigateByUrl(this.url);
} else { } else {
// window.location.href = '/admin/'; // window.location.href = '/admin/';
this.router.navigateByUrl('/admin') this.router.navigateByUrl('/admin');
} }
} }
} }

View File

@@ -14,10 +14,10 @@ import {Title} from '@angular/platform-browser';
}) })
export class TagComponent implements OnInit { export class TagComponent implements OnInit {
tagList: { name: string, size: number } [] = []; tagList: { name: string; size: number } [] = [];
articleList: PageList<Article>; articleList: PageList<Article>;
name: string; name: string;
private tag: { name: string, size: number }; private tag: { name: string; size: number };
constructor(private apiService: ApiService, constructor(private apiService: ApiService,
private nzMessageService: NzMessageService, private nzMessageService: NzMessageService,
@@ -56,7 +56,7 @@ export class TagComponent implements OnInit {
}); });
} }
changeTag(tag: { name: string, size: number }) { changeTag(tag: { name: string; size: number }) {
if (this.name === tag.name) { if (this.name === tag.name) {
return; return;
} }

View File

@@ -15,9 +15,9 @@ export class UpdateComponent implements OnInit {
lastCommit: string; lastCommit: string;
committerAuthor: string; committerAuthor: string;
committerDate: string; committerDate: string;
commitUrl: string commitUrl: string;
}; };
webUpdate: { id: number, info: string, time: string }[] = []; webUpdate: { id: number; info: string; time: string }[] = [];
constructor(private titleService: Title, constructor(private titleService: Title,
private apiService: ApiService) { private apiService: ApiService) {

View File

@@ -1,7 +1,7 @@
import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core'; import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Category} from '../../../../class/Tag'; import {Category} from '../../../../class/Tag';
import {ColorList} from '../../../../utils/color' import {ColorList} from '../../../../utils/color';
@Component({ @Component({
selector: 'c-publish-form', selector: 'c-publish-form',
@@ -11,16 +11,16 @@ import {ColorList} from '../../../../utils/color'
export class PublishFormComponent implements OnInit { export class PublishFormComponent implements OnInit {
@ViewChild('inputElement', {static: true}) tagInputElement: ElementRef; @ViewChild('inputElement', {static: true}) tagInputElement: ElementRef;
@Input() tagNacList: { name: string, size: number }[]; @Input() tagNacList: { name: string; size: number }[];
@Input() categoryList: Category[]; @Input() categoryList: Category[];
@Input() primaryData: { id: number, type: boolean, tags: string[], category: string, url?: string }; @Input() primaryData: { id: number; type: boolean; tags: string[]; category: string; url?: string };
@Output() submitEvent = new EventEmitter<{ @Output() submitEvent = new EventEmitter<{
id: number, id: number;
type: boolean, type: boolean;
tags: string[], tags: string[];
category: string, category: string;
isUpdate: boolean, isUpdate: boolean;
url?: string url?: string;
}>(); }>();
formGroup: FormGroup; formGroup: FormGroup;
tagTmpList: string[] = []; tagTmpList: string[] = [];
@@ -94,7 +94,7 @@ export class PublishFormComponent implements OnInit {
this.formGroup.get('tagList').setValue(this.tagTmpList.length ? this.tagTmpList : null); this.formGroup.get('tagList').setValue(this.tagTmpList.length ? this.tagTmpList : null);
this.formGroup.get('tagList').updateValueAndValidity(); this.formGroup.get('tagList').updateValueAndValidity();
this.tagInputVisible = false; this.tagInputVisible = false;
this.editTagText = '新增' this.editTagText = '新增';
} }
// 点击tag切换 // 点击tag切换
@@ -119,7 +119,11 @@ export class PublishFormComponent implements OnInit {
articleTypeChanged() { articleTypeChanged() {
this.formGroup.get(`url`).clearValidators(); this.formGroup.get(`url`).clearValidators();
const type = this.formGroup.get(`type`).value; const type = this.formGroup.get(`type`).value;
this.formGroup.get(`url`).setValidators(type ? null : [Validators.required, Validators.pattern('^(https:\/\/|http:\/\/|)([\\w-]+\\.)+[\\w-]+(\\/[\\w-./?%&=]*)?$')]); this.formGroup.get(`url`).setValidators(type ? null : [
Validators.required,
Validators.pattern('^(https:\/\/|http:\/\/|)([\\w-]+\\.)+[\\w-]+(\\/[\\w-./?%&=]*)?$')
]
);
this.formGroup.get(`url`).updateValueAndValidity(); this.formGroup.get(`url`).updateValueAndValidity();
} }
} }

View File

@@ -26,12 +26,12 @@ export class WriteComponent implements OnInit, OnDestroy {
public article: ArticleReq = new ArticleReq(); public article: ArticleReq = new ArticleReq();
userInfo: User; userInfo: User;
categoryList: Tag[]; categoryList: Tag[];
tagNacList: { name: string, size: number }[]; tagNacList: { name: string; size: number }[];
primaryData = null; primaryData = null;
// 发布新文章时,文章相同会被拦回 此处判断一下 // 发布新文章时,文章相同会被拦回 此处判断一下
title: string; title: string;
private lastShowTime: number; private lastShowTime: number;
private userInfoSub: { unsubscribe: () => void } private userInfoSub: { unsubscribe: () => void };
constructor(private router: Router, constructor(private router: Router,
private activatedRoute: ActivatedRoute, private activatedRoute: ActivatedRoute,
@@ -101,7 +101,7 @@ export class WriteComponent implements OnInit, OnDestroy {
this.article.category = e.category; this.article.category = e.category;
this.article.url = e.url; this.article.url = e.url;
this.article.id = e.id; this.article.id = e.id;
this.isUpdate = e.isUpdate this.isUpdate = e.isUpdate;
this.modalVisible = false; this.modalVisible = false;
@@ -169,8 +169,8 @@ export class WriteComponent implements OnInit, OnDestroy {
next: data => { next: data => {
this.article.category = data.result.category; this.article.category = data.result.category;
this.article.mdContent = data.result.mdContent; this.article.mdContent = data.result.mdContent;
const tags = [] const tags = [];
data.result.tags.forEach(t => tags.push(t.name)) data.result.tags.forEach(t => tags.push(t.name));
this.article.tags = tags; this.article.tags = tags;
this.article.type = data.result.original; this.article.type = data.result.original;
this.article.url = data.result.url; this.article.url = data.result.url;
@@ -184,7 +184,7 @@ export class WriteComponent implements OnInit, OnDestroy {
url: this.article.url, url: this.article.url,
id: this.article.id id: this.article.id
}; };
this.vditor.setValue(this.article.mdContent) this.vditor.setValue(this.article.mdContent);
}, },
error: e => { error: e => {
if (e.code === 2010) { if (e.code === 2010) {
@@ -227,7 +227,7 @@ export class WriteComponent implements OnInit, OnDestroy {
upload: { upload: {
url: environment.host + '/fileUpload', url: environment.host + '/fileUpload',
format: (files: File[], responseText: string) => { format: (files: File[], responseText: string) => {
const data: Response<[{ originalFilename: string, host: string, path: string, success: boolean }]> const data: Response<[{ originalFilename: string; host: string; path: string; success: boolean }]>
= JSON.parse(responseText); = JSON.parse(responseText);
const result = { const result = {
msg: data.msg, msg: data.msg,
@@ -236,16 +236,14 @@ export class WriteComponent implements OnInit, OnDestroy {
errFiles: [], errFiles: [],
succMap: {} succMap: {}
} }
} };
data.result.filter(value => value.success) data.result.filter(value => value.success)
.forEach(value => result.data.succMap[value.originalFilename] = value.host + value.path); .forEach(value => result.data.succMap[value.originalFilename] = value.host + value.path);
data.result.filter(value => !value.success) data.result.filter(value => !value.success)
.forEach(value => result.data.errFiles.push(value.originalFilename)); .forEach(value => result.data.errFiles.push(value.originalFilename));
return JSON.stringify(result); return JSON.stringify(result);
}, },
setHeaders: () => { setHeaders: () => ({Authorization: this.localStorageService.getToken()})
return {Authorization: this.localStorageService.getToken()}
}
}, },
after: () => { after: () => {
// 判断是更新文章还是恢复文章 // 判断是更新文章还是恢复文章
@@ -258,6 +256,6 @@ export class WriteComponent implements OnInit, OnDestroy {
this.article = JSON.parse(localStorage.getItem('tmpArticle')); this.article = JSON.parse(localStorage.getItem('tmpArticle'));
} }
} }
} };
} }
} }