Merge pull request #86 from xiaohai2271/feature-tslint2eslint

Convert tslint to eslint
This commit is contained in:
禾几海
2021-03-12 18:00:05 +08:00
committed by GitHub
45 changed files with 544 additions and 521 deletions

84
.eslintrc.json Normal file
View File

@@ -0,0 +1,84 @@
{
"root": true,
"ignorePatterns": [
"projects/**/*"
],
"overrides": [
{
"files": [
"*.ts"
],
"parserOptions": {
"project": [
"tsconfig.json",
"e2e/tsconfig.json"
],
"createDefaultProgram": true
},
"extends": [
"plugin:@angular-eslint/ng-cli-compat",
"plugin:@angular-eslint/ng-cli-compat--formatting-add-on",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"prefer-arrow/prefer-arrow-functions": [
"off"
],
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"Object": {
"message": "Use {} instead",
"fixWith": "{}"
},
"{}": false
}
}
],
"@angular-eslint/component-selector": [
"off",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
],
"@angular-eslint/directive-selector": [
"off",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
],
"@typescript-eslint/explicit-member-accessibility": [
"off",
{
"accessibility": "explicit"
}
],
"@typescript-eslint/no-inferrable-types": [
"off",
{
"ignoreParameters": true
}
],
"arrow-parens": [
"off",
"always"
],
"import/order": "off"
}
},
{
"files": [
"*.html"
],
"extends": [
"plugin:@angular-eslint/template/recommended"
],
"rules": {}
}
]
}

View File

@@ -112,15 +112,11 @@
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"builder": "@angular-eslint/builder:lint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
"lintFilePatterns": [
"src/**/*.ts",
"src/**/*.html"
]
}
},

View File

@@ -47,7 +47,17 @@
"nz-tslint-rules": "^0.901.2",
"protractor": "^7.0.0",
"ts-node": "^9.0.0",
"tslint": "^6.1.3",
"typescript": "~4.1.0"
"typescript": "~4.1.0",
"eslint": "^7.6.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsdoc": "30.7.6",
"eslint-plugin-prefer-arrow": "1.2.2",
"@angular-eslint/builder": "1.2.0",
"@angular-eslint/eslint-plugin": "1.2.0",
"@angular-eslint/eslint-plugin-template": "1.2.0",
"@angular-eslint/schematics": "1.2.0",
"@angular-eslint/template-parser": "1.2.0",
"@typescript-eslint/eslint-plugin": "4.3.0",
"@typescript-eslint/parser": "4.3.0"
}
}

View File

@@ -20,7 +20,7 @@ export class ApiService {
createArticle(article: ArticleReq) {
article.id = null;
return this.httpService.Service<Article>({
return this.httpService.service<Article>({
path: '/admin/article/create',
contentType: 'application/json',
method: 'POST',
@@ -29,15 +29,15 @@ export class ApiService {
}
deleteArticle(id: number) {
return this.httpService.Service<boolean>({
return this.httpService.service<boolean>({
path: '/admin/article/del',
method: 'DELETE',
queryParam: {articleID: id}
})
});
}
articles(pageNumber: number = 1, pageSize: number = 5) {
return this.httpService.Service<PageList<Article>>({
return this.httpService.service<PageList<Article>>({
path: '/articles',
method: 'GET',
queryParam: {
@@ -48,7 +48,7 @@ export class ApiService {
}
adminArticles(pageNumber: number = 1, pageSize: number = 10) {
return this.httpService.Service<PageList<Article>>({
return this.httpService.service<PageList<Article>>({
path: '/admin/articles',
method: 'GET',
queryParam: {
@@ -59,7 +59,7 @@ export class ApiService {
}
updateArticle(article: ArticleReq) {
return this.httpService.Service<Article>({
return this.httpService.service<Article>({
path: '/admin/article/update',
method: 'PUT',
contentType: 'application/json',
@@ -68,7 +68,7 @@ export class ApiService {
}
getArticle(articleId: number, is4Update: boolean = false) {
return this.httpService.Service<Article>({
return this.httpService.service<Article>({
path: `/article/articleID/${articleId}`,
method: 'GET',
queryParam: {update: is4Update},
@@ -76,7 +76,7 @@ export class ApiService {
}
articlesByCategory(category: string, pageNumber: number = 1, pageSize: number = 10) {
return this.httpService.Service<PageList<Article>>({
return this.httpService.service<PageList<Article>>({
path: `/articles/category/${category}`,
method: 'GET',
queryParam: {
@@ -87,7 +87,7 @@ export class ApiService {
}
articlesByTag(tag: string, pageNumber: number = 1, pageSize: number = 10) {
return this.httpService.Service<PageList<Article>>({
return this.httpService.service<PageList<Article>>({
path: `/articles/tag/${tag}`,
method: 'GET',
queryParam: {
@@ -98,14 +98,14 @@ export class ApiService {
}
categories() {
return this.httpService.Service<PageList<Category>>({
return this.httpService.service<PageList<Category>>({
path: '/categories',
method: 'GET'
});
}
createCategory(nameStr: string) {
return this.httpService.Service<Category>({
return this.httpService.service<Category>({
path: '/admin/category/create',
method: 'POST',
queryParam: {name: nameStr}
@@ -113,7 +113,7 @@ export class ApiService {
}
deleteCategory(categoryId: number) {
return this.httpService.Service<boolean>({
return this.httpService.service<boolean>({
path: '/admin/category/del',
method: 'DELETE',
queryParam: {id: categoryId}
@@ -121,7 +121,7 @@ export class ApiService {
}
updateCategory(categoryId: number, nameStr: string) {
return this.httpService.Service<Category>({
return this.httpService.service<Category>({
path: '/admin/category/update',
method: 'PUT',
queryParam: {id: categoryId, name: nameStr}
@@ -129,7 +129,7 @@ export class ApiService {
}
tags(pageNumber: number = 1, pageSize: number = 10) {
return this.httpService.Service<PageList<Tag>>({
return this.httpService.service<PageList<Tag>>({
path: '/tags',
method: 'GET',
queryParam: {
@@ -140,38 +140,38 @@ export class ApiService {
}
tagsNac() {
return this.httpService.Service<{ name: string, size: number }[]>({
return this.httpService.service<{ name: string; size: number }[]>({
path: '/tags/nac',
method: 'GET'
});
}
createTag(nameStr: string) {
return this.httpService.Service<Tag>({
return this.httpService.service<Tag>({
path: '/admin/tag/create',
method: 'POST',
queryParam: {name: nameStr}
});
}
deleteTag(TagId: number) {
return this.httpService.Service<boolean>({
deleteTag(tagId: number) {
return this.httpService.service<boolean>({
path: '/admin/tag/del',
method: 'DELETE',
queryParam: {id: TagId}
queryParam: {id: tagId}
});
}
updateTag(TagId: number, nameStr: string) {
return this.httpService.Service<Tag>({
updateTag(tagId: number, nameStr: string) {
return this.httpService.service<Tag>({
path: '/admin/tag/update',
method: 'PUT',
queryParam: {id: TagId, name: nameStr}
queryParam: {id: tagId, name: nameStr}
});
}
getCommentByTypeForAdmin(pagePath: string, pageNumber: number = 1, pageSize: number = 10) {
return this.httpService.Service<PageList<Comment>>({
return this.httpService.service<PageList<Comment>>({
path: `/admin/comment/pagePath/${pagePath}`,
method: 'GET',
queryParam: {
@@ -182,7 +182,7 @@ export class ApiService {
}
getCommentByTypeForUser(pagePath: string, pageNumber: number = 1, pageSize: number = 10) {
return this.httpService.Service<PageList<Comment>>({
return this.httpService.service<PageList<Comment>>({
path: `/user/comment/pagePath/${pagePath}`,
method: 'GET',
queryParam: {
@@ -193,7 +193,7 @@ export class ApiService {
}
deleteComment(idNumer: number) {
return this.httpService.Service<boolean>({
return this.httpService.service<boolean>({
path: `/user/comment/del`,
method: 'DELETE',
queryParam: {id: idNumer}
@@ -201,7 +201,7 @@ export class ApiService {
}
updateComment(commentReq: CommentReq) {
return this.httpService.Service<Comment>({
return this.httpService.service<Comment>({
path: `/user/comment/update`,
method: 'PUT',
data: commentReq,
@@ -210,7 +210,7 @@ export class ApiService {
}
comments(pagePath: string, pageSize: number = 10, pageNumber: number = 1) {
return this.httpService.Service<PageList<Comment>>({
return this.httpService.service<PageList<Comment>>({
path: `/comment/pagePath/${pagePath}`,
method: 'GET',
queryParam: {
@@ -221,7 +221,7 @@ export class ApiService {
}
createComment(commentReq: CommentReq) {
return this.httpService.Service<Comment>({
return this.httpService.service<Comment>({
path: '/user/comment/create',
method: 'POST',
contentType: 'application/json',
@@ -231,12 +231,12 @@ export class ApiService {
counts() {
return this.httpService.Service<{
articleCount: number,
visitorCount: number,
categoryCount: number,
tagCount: number,
commentCount: number
return this.httpService.service<{
articleCount: number;
visitorCount: number;
categoryCount: number;
tagCount: number;
commentCount: number;
}>({
path: '/counts',
method: 'GET'
@@ -244,7 +244,7 @@ export class ApiService {
}
adminLinks(pageSize: number = 10, pageNumber: number = 1) {
return this.httpService.Service<PageList<Link>>({
return this.httpService.service<PageList<Link>>({
path: '/admin/links',
method: 'GET',
queryParam: {
@@ -255,7 +255,7 @@ export class ApiService {
}
createLink(linkReq: Link) {
return this.httpService.Service<Link>({
return this.httpService.service<Link>({
path: '/admin/links/create',
method: 'POST',
data: linkReq,
@@ -264,14 +264,14 @@ export class ApiService {
}
deleteLink(idNumber: number) {
return this.httpService.Service<boolean>({
return this.httpService.service<boolean>({
path: `/admin/links/del/${idNumber}`,
method: 'DELETE',
});
}
updateLink(linkReq: Link) {
return this.httpService.Service<Link>({
return this.httpService.service<Link>({
path: '/admin/links/update',
method: 'PUT',
data: linkReq,
@@ -280,7 +280,7 @@ export class ApiService {
}
applyLink(link: ApplyLinkReq) {
return this.httpService.Service<string>({
return this.httpService.service<string>({
path: '/apply',
method: 'POST',
data: link,
@@ -289,7 +289,7 @@ export class ApiService {
}
reapplyLink(keyStr: string) {
return this.httpService.Service<string>({
return this.httpService.service<string>({
path: '/reapply',
method: 'POST',
queryParam: {
@@ -299,14 +299,14 @@ export class ApiService {
}
links() {
return this.httpService.Service<Link[]>({
return this.httpService.service<Link[]>({
path: '/links',
method: 'GET',
});
}
verifyImgCode(codeStr: string) {
return this.httpService.Service<string>({
return this.httpService.service<string>({
path: '/verCode',
method: 'POST',
queryParam: {code: codeStr}
@@ -315,7 +315,7 @@ export class ApiService {
login(loginReq: LoginReq) {
return this.httpService.Service<User>({
return this.httpService.service<User>({
path: '/login',
method: 'POST',
contentType: 'application/json',
@@ -324,14 +324,14 @@ export class ApiService {
}
logout() {
return this.httpService.Service<string>({
return this.httpService.service<string>({
path: '/logout',
method: 'GET',
});
}
registration(emailStr: string, pwd: string) {
return this.httpService.Service<boolean>({
return this.httpService.service<boolean>({
path: '/registration',
method: 'POST',
queryParam: {
@@ -342,7 +342,7 @@ export class ApiService {
}
resetPwd(idStr: string, emailStr: string, pwdStr: string) {
return this.httpService.Service<string>({
return this.httpService.service<string>({
path: '/resetPwd',
method: 'POST',
queryParam: {
@@ -354,7 +354,7 @@ export class ApiService {
}
emailVerify(idStr: string, emailStr: string) {
return this.httpService.Service<void>({
return this.httpService.service<void>({
path: '/emailVerify',
method: 'POST',
queryParam: {
@@ -366,7 +366,7 @@ export class ApiService {
sendResetPwdEmail(emailStr: string) {
return this.httpService.Service<string>({
return this.httpService.service<string>({
path: '/sendResetPwdEmail',
method: 'POST',
queryParam: {email: emailStr}
@@ -374,7 +374,7 @@ export class ApiService {
}
sendVerifyEmail(emailStr: string) {
return this.httpService.Service<string>({
return this.httpService.service<string>({
path: '/sendVerifyEmail',
method: 'POST',
queryParam: {email: emailStr}
@@ -382,30 +382,30 @@ export class ApiService {
}
userInfo() {
return this.httpService.Service<User>({
return this.httpService.service<User>({
path: '/user/userInfo',
method: 'GET',
});
}
adminUpdateUser(user: User) {
return this.httpService.Service<User>({
return this.httpService.service<User>({
path: '/admin/user',
method: 'PUT',
data: user,
contentType: 'application/json'
})
});
}
deleteUser(id: number) {
return this.httpService.Service<boolean>({
return this.httpService.service<boolean>({
path: `/admin/user/delete/${id}`,
method: 'DELETE',
});
}
multipleDeleteUser(idArray: number[]) {
return this.httpService.Service<{ id: number; msg: string; status: boolean }[]>({
return this.httpService.service<{ id: number; msg: string; status: boolean }[]>({
path: `/admin/user/delete`,
method: 'DELETE',
data: idArray,
@@ -415,14 +415,14 @@ export class ApiService {
// 获取邮件是否已注册
emailStatus(email: string) {
return this.httpService.Service<boolean>({
return this.httpService.service<boolean>({
path: `/emailStatus/${email}`,
method: 'GET'
})
});
}
updateUserInfo(descStr: string, disPlayNameStr: string) {
return this.httpService.Service<User>({
return this.httpService.service<User>({
path: '/user/userInfo/update',
method: 'PUT',
queryParam: {
@@ -433,7 +433,7 @@ export class ApiService {
}
adminUsers(pageSize: number = 10, pageNumber: number = 1) {
return this.httpService.Service<PageList<User>>({
return this.httpService.service<PageList<User>>({
path: '/admin/users',
method: 'GET',
queryParam: {
@@ -444,14 +444,14 @@ export class ApiService {
}
visit() {
return this.httpService.Service<Visitor>({
return this.httpService.service<Visitor>({
path: '/visit',
method: 'POST'
});
}
adminVisitors(location: boolean = false, pageSize: number = 10, pageNumber: number = 1) {
return this.httpService.Service<PageList<Visitor>>({
return this.httpService.service<PageList<Visitor>>({
path: '/admin/visitor/page',
method: 'GET',
queryParam: {
@@ -463,42 +463,42 @@ export class ApiService {
}
dayVisitCount() {
return this.httpService.Service<number>({
return this.httpService.service<number>({
path: '/dayVisitCount',
method: 'GET',
});
}
getLocalIp() {
return this.httpService.Service<string>({
return this.httpService.service<string>({
path: '/ip',
method: 'GET',
});
}
getIpLocation(ip: string) {
return this.httpService.Service<string>({
return this.httpService.service<string>({
path: `/ip/${ip}`,
method: 'GET',
});
}
visitorCount() {
return this.httpService.Service<number>({
return this.httpService.service<number>({
path: `/visitor/count`,
method: 'GET',
});
}
webUpdate() {
return this.httpService.Service<{ id: number, info: string, time: string }[]>({
return this.httpService.service<{ id: number; info: string; time: string }[]>({
path: '/webUpdate',
method: 'GET'
});
}
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',
method: 'GET',
queryParam: {
@@ -509,13 +509,13 @@ export class ApiService {
}
lastestUpdate() {
return this.httpService.Service<{
return this.httpService.service<{
lastUpdateTime: string;
lastUpdateInfo: string;
lastCommit: string;
committerAuthor: string;
committerDate: string;
commitUrl: string
commitUrl: string;
}>({
path: '/lastestUpdate',
method: 'GET'
@@ -523,7 +523,7 @@ export class ApiService {
}
createWebUpdateInfo(infoStr: string) {
return this.httpService.Service<UpdateInfo>({
return this.httpService.service<UpdateInfo>({
path: '/admin/webUpdate/create',
method: 'POST',
queryParam: {info: infoStr}
@@ -531,14 +531,14 @@ export class ApiService {
}
deleteWebUpdateInfo(idNumber: number) {
return this.httpService.Service<boolean>({
return this.httpService.service<boolean>({
path: `/admin/webUpdate/del/${idNumber}`,
method: 'DELETE',
});
}
updateWebUpdateInfo(idNumber: number, infoStr: string) {
return this.httpService.Service<UpdateInfo>({
return this.httpService.service<UpdateInfo>({
path: '/admin/webUpdate/update',
method: 'PUT',
queryParam: {id: idNumber, info: infoStr}
@@ -546,14 +546,14 @@ export class ApiService {
}
bingPic() {
return this.httpService.Service<string>({
return this.httpService.service<string>({
path: '/bingPic',
method: 'GET'
});
}
setPwd(pwdStr: string, newPwdStr: string, confirmPwdStr: string,) {
return this.httpService.Service<string>({
return this.httpService.service<string>({
path: '/user/setPwd',
method: 'POST',
queryParam: {

View File

@@ -20,12 +20,13 @@ export class HttpService {
public getSubscriptionQueue = () => this.subscriptionQueue;
Service<T>(request: RequestObj) {
service<T>(request: RequestObj) {
const errorService = this.injector.get(ErrorService);
request.url = null;
// 设置默认值
request.contentType = request.contentType == null ? 'application/x-www-form-urlencoded' : request.contentType;
request.header = {
// eslint-disable-next-line @typescript-eslint/naming-convention
'Content-Type': request.contentType
};
const token = this.localStorageService.getToken();
@@ -62,7 +63,7 @@ export class HttpService {
}
if (o.body.code !== 0) {
observer.error(o.body);
errorService.httpException(o.body, request)
errorService.httpException(o.body, request);
} else {
observer.next(o.body);
}
@@ -71,7 +72,7 @@ export class HttpService {
error: err => {
errorService.httpError(err, request);
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)
});
@@ -117,6 +118,7 @@ export class HttpService {
/**
* 验证并且处理拼接 URl
*
* @param req Request
*/
private checkUrl(req: RequestObj): string {

View File

@@ -9,9 +9,9 @@ import {ComponentStateService} from './services/component-state.service';
styleUrls: ['./app.component.less']
})
export class AppComponent {
@ViewChild('headerComponent') header: HeaderComponent;
loginModal: boolean = false;
regModal: boolean = false;
@ViewChild('headerComponent') header: HeaderComponent;
constructor(public componentStateService: ComponentStateService) {
}

View File

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

View File

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

View File

@@ -8,13 +8,14 @@ import {User} from '../../class/User';
styleUrls: ['./admin-header.component.less']
})
export class AdminHeaderComponent implements OnInit {
@Output() infoClicked = new EventEmitter<void>();
user: User;
noAvatarUrl = 'https://cdn.celess.cn/';
constructor(private userService: GlobalUserService) {
}
user: User
@Output() infoClicked = new EventEmitter<void>()
noAvatarUrl = 'https://cdn.celess.cn/'
logout = () => this.userService.logout();
infoClickedEvent = () => this.infoClicked.emit();
@@ -23,7 +24,7 @@ export class AdminHeaderComponent implements OnInit {
next: data => this.user = data.result,
error: err => this.user = null,
complete: null
})
});
}
}

View File

@@ -8,12 +8,12 @@ import {ComponentStateService} from '../../services/component-state.service';
})
export class FooterComponent implements OnInit {
constructor(public componentStateService: ComponentStateService) {
}
readonly gName: string = '何梦幻';
readonly bName: string = '郑海';
constructor(public componentStateService: ComponentStateService) {
}
ngOnInit() {
}

View File

@@ -1,7 +1,6 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {Router} from '@angular/router';
import {windowWidthChange} from '../../utils/util';
import {ApiService} from '../../api/api.service';
import {User} from '../../class/User';
import {ComponentStateService} from '../../services/component-state.service';
import {GlobalUserService} from '../../services/global-user.service';
@@ -12,6 +11,25 @@ import {GlobalUserService} from '../../services/global-user.service';
styleUrls: ['./header.component.less']
})
export class HeaderComponent implements OnInit {
@Output() loginEvent = new EventEmitter();
@Output() registrationEvent = new EventEmitter();
@Input() userInfo: User;
size: 'large' | 'default';
currentPath: string;
noAvatarUrl = 'https://cdn.celess.cn/';
public pageList: {
path: string;
name: string;
icon: string;
iconType: 'outline' | 'fill' | 'twotone';
show: boolean;
}[];
public showList = true;
// css 样式中设置移动端最大宽度为910px 见src/app/global-variables.less
private readonly mobileMaxWidth = 940;
constructor(private router: Router,
public componentStateService: ComponentStateService,
@@ -46,26 +64,6 @@ export class HeaderComponent implements OnInit {
});
}
@Output() loginEvent = new EventEmitter();
@Output() registrationEvent = new EventEmitter();
size: 'large' | 'default';
currentPath: string;
noAvatarUrl = 'https://cdn.celess.cn/'
public pageList: {
path: string;
name: string;
icon: string;
iconType: 'outline' | 'fill' | 'twotone';
show: boolean;
}[];
public showList = true;
// css 样式中设置移动端最大宽度为910px 见src/app/global-variables.less
private readonly mobileMaxWidth = 940;
@Input() userInfo: User;
ngOnInit() {
}
@@ -75,17 +73,6 @@ export class HeaderComponent implements OnInit {
this.changeLoginButtonV();
}
private changeLoginButtonV() {
this.pageList.forEach(e => {
if (e.name === '登录' || e.name === '注册') {
if (this.userInfo) {
e.show = false;
} else {
e.show = (this.showList && window.innerWidth < this.mobileMaxWidth);
}
}
});
}
dealLink(path: string) {
this.showList = window.innerWidth > this.mobileMaxWidth;
@@ -137,7 +124,20 @@ export class HeaderComponent implements OnInit {
}
toAdminPage() {
this.router.navigateByUrl('/admin')
this.router.navigateByUrl('/admin');
}
private changeLoginButtonV() {
this.pageList.forEach(e => {
if (e.name === '登录' || e.name === '注册') {
if (this.userInfo) {
e.show = false;
} else {
e.show = (this.showList && window.innerWidth < this.mobileMaxWidth);
}
}
});
}
}

View File

@@ -1,24 +1,25 @@
import {Injectable} from '@angular/core';
import {filter} from 'rxjs/operators';
import {NavigationEnd, Router, RouterEvent} from '@angular/router';
import {Observable, of, Subscriber} from 'rxjs';
import {Observable, Subscriber} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ComponentStateService {
constructor(private router: Router) {
this.watchRouterChange()
}
visible = {
header: true,
footer: true,
globalBackToTop: true
};
currentPath: string;
constructor(private router: Router) {
this.watchRouterChange();
}
currentPath: string
getCurrentRouterPath = () => this.currentPath;
watchRouterChange() {
@@ -31,28 +32,30 @@ export class ComponentStateService {
// lastIndexOf ==> 0/index
const indexOf = path.lastIndexOf('/');
const prefix = path.substr(0, indexOf === 0 ? path.length : indexOf);
this.dealWithPathChange(prefix)
this.dealWithPathChange(prefix);
this.currentPath = prefix;
if (subscriber) subscriber.next(prefix)
if (subscriber) {
subscriber.next(prefix);
}
});
return ob;
}
private dealWithPathChange(path) {
// tslint:disable-next-line:forin
// eslint-disable-next-line guard-for-in
for (const visibleKey in this.visible) {
this.visible[visibleKey] = true
this.visible[visibleKey] = true;
}
switch (path) {
case '/admin':
this.visible.header = false
this.visible.footer = false
this.visible.globalBackToTop = false
break
this.visible.header = false;
this.visible.footer = false;
this.visible.globalBackToTop = false;
break;
case '/user':
case '/write':
this.visible.footer = false
this.visible.globalBackToTop = false
this.visible.footer = false;
this.visible.globalBackToTop = false;
break;
default:

View File

@@ -3,7 +3,7 @@ import {RequestObj, Response} from '../class/HttpReqAndResp';
import {environment} from '../../environments/environment';
import {Router} from '@angular/router';
import {ComponentStateService} from './component-state.service';
import { NzNotificationService } from 'ng-zorro-antd/notification';
import {NzNotificationService} from 'ng-zorro-antd/notification';
import {HttpService} from '../api/http/http.service';
import {LocalStorageService} from './local-storage.service';
@@ -11,6 +11,9 @@ import {LocalStorageService} from './local-storage.service';
providedIn: 'root'
})
export class ErrorService {
private static httpErrorCount: number = 0;
private readonly maintainPagePrefix = '/maintain';
private readonly adminPagePrefix = '/admin';
constructor(/*private httpService: HttpService,*/
private router: Router,
@@ -20,23 +23,22 @@ export class ErrorService {
private localStorageService: LocalStorageService) {
}
private static HTTP_ERROR_COUNT: number = 0;
private readonly MAINTAIN_PAGE_PREFIX = '/maintain'
private readonly ADMIN_PAGE_PREFIX = '/admin'
public httpError(err: any, request: RequestObj) {
if (!environment.production) {
console.log('error=>', err, request)
console.log('error=>', err, request);
}
ErrorService.HTTP_ERROR_COUNT++;
ErrorService.httpErrorCount++;
// this.httpService.getSubscriptionQueue().map(a => a.unsubscribe())
}
public httpException(response: Response<any>, request: RequestObj) {
if (!environment.production)
console.log('exception=>', response, request)
if (response.code === -1 && response.msg === '重复请求') return
if (this.componentStateService.currentPath === this.ADMIN_PAGE_PREFIX) {
if (!environment.production) {
console.log('exception=>', response, request);
}
if (response.code === -1 && response.msg === '重复请求') {
return;
}
if (this.componentStateService.currentPath === this.adminPagePrefix) {
this.notification.create('error', `请求失败<${response.code}>`, `${response.msg}`);
}
/***
@@ -57,21 +59,21 @@ export class ErrorService {
public checkConnection() {
// The HTTP_ERROR_COUNT is start with 1 in this function
if (ErrorService.HTTP_ERROR_COUNT === 1) {
if (ErrorService.httpErrorCount === 1) {
const req: RequestObj = {
path: '/headerInfo',
method: 'GET',
url: environment.host + '/headerInfo'
}
};
this.injector.get(HttpService).get(req).subscribe({
next: () => null,
error: () => {
if (this.componentStateService.currentPath !== this.MAINTAIN_PAGE_PREFIX) {
this.router.navigateByUrl(this.MAINTAIN_PAGE_PREFIX)
if (this.componentStateService.currentPath !== this.maintainPagePrefix) {
this.router.navigateByUrl(this.maintainPagePrefix);
}
ErrorService.HTTP_ERROR_COUNT = 0;
ErrorService.httpErrorCount = 0;
}
})
});
}
}
}

View File

@@ -10,10 +10,6 @@ import {LocalStorageService} from './local-storage.service';
})
export class GlobalUserService {
constructor(private apiService: ApiService,
private localStorageService: LocalStorageService) {
}
private lastRequestTime: number;
private userInfo: User = null;
@@ -21,26 +17,29 @@ export class GlobalUserService {
private userObserverArray: Observer<Response<User>>[] = [];
private multicastArray: Observer<Response<User>>[] = [];
constructor(private apiService: ApiService,
private localStorageService: LocalStorageService) {
}
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];
let subscription: Subscription = null;
const unsubscribe = () => {
this.userObserverArray.splice(this.userObserverArray.indexOf(observer), 1);
observer.complete();
if (subscription) subscription.unsubscribe();
if (subscription) {subscription.unsubscribe();}
};
if (this.lastRequestTime && Date.now() - this.lastRequestTime < 3000) {
if (this.userInfo && this.multicastArray.length) {
this.broadcast()
this.broadcast();
this.lastRequestTime = Date.now();
}
return {unsubscribe}
return {unsubscribe};
}
// 获取数据
subscription = this.getUserInfoFromServer();
return {unsubscribe}
return {unsubscribe};
}
// 刷新用户信息
@@ -59,7 +58,7 @@ export class GlobalUserService {
// this.localStorageService.setUser(o.result);
// this.userObserver.next(o);
this.userInfo = o.result;
this.broadcast()
this.broadcast();
observer.next(o);
observer.complete();
},
@@ -82,7 +81,7 @@ export class GlobalUserService {
// 如果不需要返回消息也ok
this.apiService.logout().subscribe(data => {
this.localStorageService.clear();
this.broadcast()
this.broadcast();
if (observer) {
observer.next(data);
observer.complete();
@@ -93,7 +92,7 @@ export class GlobalUserService {
observer.error(error);
observer.complete();
}
})
});
}
getUserInfoFromServer(observer?: Observer<Response<User>>) {
@@ -102,7 +101,7 @@ export class GlobalUserService {
this.lastRequestTime = Date.now();
this.userInfo = o.result;
// this.localStorageService.setUser(o.result);
this.broadcast()
this.broadcast();
if (observer) {
observer.next(o);
observer.complete();
@@ -118,12 +117,12 @@ export class GlobalUserService {
if (err.code === -1) {
// 请求重复
return
return;
}
// this.requested = false;
// this.localStorageService.removeToken();
this.multicastArray.forEach(ob => ob.next(new Response<User>(this.userInfo)))
this.multicastArray.forEach(ob => ob.error(err))
this.multicastArray.forEach(ob => ob.next(new Response<User>(this.userInfo)));
this.multicastArray.forEach(ob => ob.error(err));
this.multicastArray.splice(0, this.multicastArray.length);
}
@@ -131,7 +130,7 @@ export class GlobalUserService {
}
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);
}
}

View File

@@ -1,16 +1,15 @@
import {Injectable} from '@angular/core';
import {User} from '../class/User';
@Injectable({
providedIn: 'root'
})
export class LocalStorageService {
readonly place = 30 * 1000;
constructor() {
}
// 30s
readonly place = 30 * 1000;
getToken(): string {
return localStorage.getItem('token');

View File

@@ -1,9 +1,9 @@
export class Color {
bgColor: string;
fontColor: string
fontColor: string;
}
export const ColorList: Color[] = [
export const COLOR_LIST: Color[] = [
{bgColor: '#7bcfa6', fontColor: '#000000'}, // 石青
{bgColor: '#bce672', fontColor: '#000000'}, // 松花色
{bgColor: '#ff8936', fontColor: '#000000'}, // 橘黄
@@ -13,23 +13,24 @@ export const ColorList: Color[] = [
{bgColor: '#177cb0', fontColor: '#ffffff'}, // 靛青
];
export const ColorListLength = ColorList.length
export const COLOR_LIST_LENGTH = COLOR_LIST.length;
/**
* 获取一组随机颜色
*
* @param count 数量
*/
export function RandomColor(count: number = 1): Color[] {
export function randomColor(count: number = 1): Color[] {
const map = new Map<number, number>();
ColorList.forEach((color, index) => map.set(index, 0))
COLOR_LIST.forEach((color, index) => map.set(index, 0));
const colorArray: Color[] = [];
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 keyIndex = Math.floor(Math.random() * keys.length);
const index = keys[keyIndex];
map.set(index, minValue + 1);
return ColorList[index]
return COLOR_LIST[index];
};
for (let i = 0; i < count; i++) {
colorArray.push(oneRandomColor());

View File

@@ -3,6 +3,7 @@ import {PageList} from '../class/HttpReqAndResp';
/**
* 判断 一个Page<any>[] 中是否存在一条已查询的数据
*
* @param pageNum 页码
* @param pageSize 单页数量
* @param pageList 源数据
@@ -12,14 +13,14 @@ export function exist<T>(pageNum: number, pageSize: number, pageList: PageList<a
if (pageList === undefined || pageList == null || pageList.length === 0) {
return null;
}
// tslint:disable-next-line:prefer-for-of
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < pageList.length; i++) {
// tslint:disable-next-line:triple-equals
// eslint-disable-next-line eqeqeq
if (pageList[i].pageNum == pageNum && pageList[i].pageSize == pageSize) {
const ob: Observable<PageList<T>> = new Observable(o => {
o.next(pageList[i]);
o.complete();
})
});
}
}
return null;

View File

@@ -1,11 +1,12 @@
export class SvgIconUtil {
// eslint-disable-next-line max-len
static readonly nameIcon = '<svg t="1581933298087" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3223" width="200" height="200"><path d="M983.04 163.84H40.96c-24.576 0-40.96 16.384-40.96 40.96v614.4c0 20.48 16.384 40.96 40.96 40.96h942.08c20.48 0 40.96-20.48 40.96-40.96V204.8c0-24.576-20.48-40.96-40.96-40.96zM253.952 749.568c0-102.4 61.44-192.512 147.456-233.472-28.672-24.576-45.056-61.44-45.056-102.4 0-77.824 65.536-143.36 143.36-143.36s143.36 65.536 143.36 143.36c0 40.96-12.288 73.728-36.864 98.304 94.208 36.864 163.84 131.072 163.84 237.568H253.952z" p-id="3224" fill="#1296db"></path></svg>';
// eslint-disable-next-line max-len
static readonly locationIcon = '<svg t="1581933583276" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3981" width="200" height="200"><path d="M511.932268 0c-213.943865 0-387.880498 170.933833-387.880499 381.06211 0 164.815346 238.869364 485.098975 341.66447 620.247558a58.249807 58.249807 0 0 0 46.216029 22.690332c18.129688 0 35.491743-8.443964 46.328916-22.690332 102.704796-135.126006 341.709624-455.432213 341.709624-620.247558C899.970808 170.933833 725.89871 0 511.932268 0z m0 519.574733c-91.393496 0-165.786176-72.902569-165.786176-162.670489 0-89.722765 74.39268-162.738221 165.786176-162.73822 91.438651 0 165.718443 73.015456 165.718443 162.73822 0 89.76792-74.279793 162.670488-165.718443 162.670489z" fill="#1296db" p-id="3982"></path></svg>';
constructor() {
}
// tslint:disable-next-line:max-line-length
static readonly nameIcon = '<svg t="1581933298087" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3223" width="200" height="200"><path d="M983.04 163.84H40.96c-24.576 0-40.96 16.384-40.96 40.96v614.4c0 20.48 16.384 40.96 40.96 40.96h942.08c20.48 0 40.96-20.48 40.96-40.96V204.8c0-24.576-20.48-40.96-40.96-40.96zM253.952 749.568c0-102.4 61.44-192.512 147.456-233.472-28.672-24.576-45.056-61.44-45.056-102.4 0-77.824 65.536-143.36 143.36-143.36s143.36 65.536 143.36 143.36c0 40.96-12.288 73.728-36.864 98.304 94.208 36.864 163.84 131.072 163.84 237.568H253.952z" p-id="3224" fill="#1296db"></path></svg>';
// tslint:disable-next-line:max-line-length
static readonly locationIcon = '<svg t="1581933583276" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3981" width="200" height="200"><path d="M511.932268 0c-213.943865 0-387.880498 170.933833-387.880499 381.06211 0 164.815346 238.869364 485.098975 341.66447 620.247558a58.249807 58.249807 0 0 0 46.216029 22.690332c18.129688 0 35.491743-8.443964 46.328916-22.690332 102.704796-135.126006 341.709624-455.432213 341.709624-620.247558C899.970808 170.933833 725.89871 0 511.932268 0z m0 519.574733c-91.393496 0-165.786176-72.902569-165.786176-162.670489 0-89.722765 74.39268-162.738221 165.786176-162.73822 91.438651 0 165.718443 73.015456 165.718443 162.73822 0 89.76792-74.279793 162.670488-165.718443 162.670489z" fill="#1296db" p-id="3982"></path></svg>';
}

View File

@@ -14,9 +14,9 @@ import {Router} from '@angular/router';
})
export class AdminArticleComponent implements OnInit {
@ViewChild('commonTableComponent') private commonTableComponent: CommonTableComponent<Article>;
request: RequestObj;
headData: Data<Article>[]
@ViewChild('commonTableComponent') private commonTableComponent: CommonTableComponent<Article>
headData: Data<Article>[];
constructor(private apiService: ApiService, private nzMessage: NzMessageService, private title: Title,
private router: Router) {
@@ -27,11 +27,11 @@ export class AdminArticleComponent implements OnInit {
page: 1,
count: 10
}
}
};
}
ngOnInit(): void {
this.title.setTitle('小海博客 | 文章管理')
this.title.setTitle('小海博客 | 文章管理');
this.headData = [
{title: '主键', fieldValue: 'id', show: false, primaryKey: 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}`)},
]
}
]
];
}
deleteArticle(article: Article) {
this.apiService.deleteArticle(article.id).subscribe({
next: data => {
this.nzMessage.success('删除成功')
this.nzMessage.success('删除成功');
this.commonTableComponent.getData();
},
error: err => {
this.nzMessage.error(err.msg)
this.nzMessage.error(err.msg);
}
})
});
}
}

View File

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

View File

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

View File

@@ -15,11 +15,11 @@ import {Data} from '../components/common-table/data';
})
export class AdminLinkComponent implements OnInit {
@ViewChild('commonTableComponent') commonTableComponent: CommonTableComponent<Link>;
modalVisible: boolean = false;
modalTitle: string = '';
formGroup: FormGroup;
request: RequestObj;
@ViewChild('commonTableComponent') commonTableComponent: CommonTableComponent<Link>
headData: Data<Link>[];
constructor(private apiService: ApiService, private messageService: NzMessageService, private title: Title) {
@@ -27,12 +27,19 @@ export class AdminLinkComponent implements OnInit {
this.formGroup = new FormGroup({
id: new FormControl(null),
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]),
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)
})
});
}
ngOnInit(): void {
@@ -43,7 +50,7 @@ export class AdminLinkComponent implements OnInit {
count: 10,
page: 1
}
}
};
this.headData = [
{title: '主键', fieldValue: 'id', show: false, primaryKey: true},
{title: '友链名称', fieldValue: 'name', show: true},
@@ -72,19 +79,19 @@ export class AdminLinkComponent implements OnInit {
this.messageService.error('删除失败');
},
complete: () => null,
})
});
}
showEdit(data: Link) {
this.modalVisible = true;
this.modalTitle = '编辑友链信息';
this.formGroup.patchValue(data);
this.formGroup.controls.oper.setValue('edit')
this.formGroup.controls.oper.setValue('edit');
}
modalConfirm() {
this.modalVisible = false;
const linkReq: Link = this.formGroup.value
const linkReq: Link = this.formGroup.value;
const oper = this.formGroup.value.oper;
let observable: Observable<Response<Link>>;
if (oper === 'edit') {
@@ -97,13 +104,13 @@ export class AdminLinkComponent implements OnInit {
next: data => this.messageService.success('操作成功'),
error: err => this.messageService.error('操作失败,' + err.msg),
complete: () => this.commonTableComponent.getData()
})
});
}
addLink() {
this.modalVisible = true;
this.modalTitle = '新增友链信息';
this.formGroup.reset();
this.formGroup.controls.oper.setValue('add')
this.formGroup.controls.oper.setValue('add');
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -11,22 +11,22 @@ import {CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop';
})
export class CommonTableComponent<T> implements OnInit, OnChanges {
@Input() request: RequestObj;
@Output() pageInfo = new EventEmitter<{ page: number; pageSize: number }>();
@Input() cardTitle: string | null;
@Input() template: {
[fieldValue: string]: {
temp: TemplateRef<any>,
param?: { [key: string]: string }
}
temp: TemplateRef<any>;
param?: { [key: string]: string };
};
@Output() pageInfo = new EventEmitter<{ page: number, pageSize: number }>();
};
@Input() request: RequestObj;
@Input() private headData: Data<T>[];
loading: boolean = true;
dataList: PageList<T> = new PageList<T>();
settingModalVisible: boolean = false;
filedData: Data<T>[];
changed: boolean = false;
visibleFieldLength: number = 0;
@Input() private headData: Data<T>[];
constructor(private httpService: HttpService) {
@@ -37,20 +37,26 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
this.filedData = this.cloneData(localStorage.getItem(this.request.path));
this.changed = true;
} else {
this.filedData = this.cloneData(this.headData)
this.filedData = this.cloneData(this.headData);
}
this.calculateVisibleFieldLength();
if (!this.template) this.template = {}
if (!this.template) {
this.template = {};
}
this.headData.forEach(dat => {
if (!dat.action) return;
if (!dat.action) {
return;
}
dat.action.forEach(act => {
if (!act.hover) {
act.hover = () => null;
}
})
});
if (!this.request || !this.request.path) return
});
if (!this.request || !this.request.path) {
return;
}
this.getData();
}
@@ -65,15 +71,15 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
// page: pageValue,
// count: countValue
// }
this.pageInfo.emit({page: pageValue, pageSize: countValue})
return this.httpService.Service<PageList<T>>(this.request).subscribe({
this.pageInfo.emit({page: pageValue, pageSize: countValue});
return this.httpService.service<PageList<T>>(this.request).subscribe({
next: resp => {
this.dataList = resp.result;
setTimeout(() => this.loading = false, 10)
setTimeout(() => this.loading = false, 10);
},
error: err => this.loading = false
});
}
};
ngOnChanges(changes: SimpleChanges): void {
if (changes.request && !changes.request.isFirstChange()) {
@@ -87,7 +93,9 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
getValue(index: number, fieldValue: string): string {
let value = this.dataList.list[index];
try {
for (const key of fieldValue.split('.')) value = value[key]
for (const key of fieldValue.split('.')) {
value = value[key];
}
} catch (e) {
// ignore
}
@@ -96,21 +104,21 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
getContext = (fieldValue: string, index: number) => {
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) {
context = {
value: this.template[fieldValue].param[valueData],
originValue: valueData,
data: this.dataList.list[index]
}
};
} else {
context = {
value: valueData,
data: this.dataList.list[index]
}
};
}
return context;
}
};
showFieldSetting = () => this.settingModalVisible = true;
@@ -121,10 +129,10 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
this.calculateVisibleFieldLength();
this.settingModalVisible = !this.settingModalVisible;
if (!this.changed) {
return
return;
}
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;
}
@@ -138,7 +146,7 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
this.filedData = this.cloneData(this.headData);
this.changed = false;
this.calculateVisibleFieldLength();
}
};
cloneData = (source: Data<T>[] | string): Data<T>[] => {
let dist: Data<T>[];
@@ -151,11 +159,11 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
if (!action) {
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.push(action);
return dist;
}
};
/**
* 字段编辑项被点击
@@ -169,5 +177,5 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
this.changed = true;
}
}
}
};
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -7,9 +7,9 @@ import {User} from '../../class/User';
import {Comment, CommentReq} from '../../class/Comment';
import {PageList} from '../../class/HttpReqAndResp';
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({
selector: 'view-article',
@@ -18,6 +18,7 @@ declare var $;
})
export class ArticleComponent implements OnInit {
@ViewChild('divElement') divElement: ElementRef;
articleId: number;
article: Article;
copyRightUrl: string;
@@ -30,7 +31,6 @@ export class ArticleComponent implements OnInit {
avatarImgUrl: string;
pid: number;
content: string;
@ViewChild('divElement') divElement: ElementRef;
constructor(private activatedRoute: ActivatedRoute,
private apiService: ApiService,
@@ -49,7 +49,7 @@ export class ArticleComponent implements OnInit {
error: (err) => null,
next: data => {
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}`);

View File

@@ -1,5 +1,5 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {ColorList} from '../../../../utils/color';
import {COLOR_LIST} from '../../../../utils/color';
import {Router} from '@angular/router';
@Component({
@@ -9,19 +9,19 @@ import {Router} from '@angular/router';
})
export class TagTagComponent implements OnInit {
@Input() tag: { name: string, size: number };
@Input() tag: { name: string; size: number };
@Input() size: 'default' | 'large' = 'default';
@Input() clickable: boolean; // default true
@Input() enableCount: boolean; // default true
@Output() tagClick = new EventEmitter();
randColor: { bgColor: string, fontColor: string };
randColor: { bgColor: string; fontColor: string };
constructor(private router: Router) {
}
ngOnInit() {
const randomNumber = Math.floor(ColorList.length * Math.random());
this.randColor = ColorList[randomNumber];
const randomNumber = Math.floor(COLOR_LIST.length * Math.random());
this.randColor = COLOR_LIST[randomNumber];
if (this.clickable == null) {
this.clickable = true;
}

View File

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

View File

@@ -5,7 +5,7 @@ import {Title} from '@angular/platform-browser';
import {ApiService} from '../../api/api.service';
import {ApplyLinkReq, Link} from '../../class/Link';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Color, RandomColor} from '../../utils/color';
import {Color, randomColor} from '../../utils/color';
@Component({
selector: 'view-link',
@@ -37,7 +37,7 @@ export class LinkComponent implements OnInit {
this.apiService.links().subscribe({
next: data => this.linkList = data.result,
error: err => this.message.error(err.msg),
complete: () => this.colors = RandomColor(this.linkList.length)
complete: () => this.colors = randomColor(this.linkList.length)
});
this.applyFormGroup = this.fb.group({
urlLinkProtocol: ['http://'],
@@ -55,7 +55,7 @@ export class LinkComponent implements OnInit {
this.applyFormGroup.patchValue({linkUrl: linkUrlData.replace(this.lastUrl, data)});
this.lastUrl = data;
},
})
});
}
apply() {
@@ -69,7 +69,7 @@ export class LinkComponent implements OnInit {
this.message.success('提交成功,请稍等,即将为你处理');
this.loading = false;
this.showModal = false;
this.applyFormGroup.reset()
this.applyFormGroup.reset();
},
error: err => {
if (err.code === 7200) {
@@ -82,7 +82,7 @@ export class LinkComponent implements OnInit {
this.apiService.reapplyLink(key).subscribe({
next: data1 => this.message.success('提交成功,请稍等,即将为你处理'),
error: err1 => this.message.error('提交失败,原因:' + err.msg)
})
});
}
});
} else {
@@ -90,7 +90,7 @@ export class LinkComponent implements OnInit {
}
this.loading = false;
this.showModal = false;
this.applyFormGroup.reset()
this.applyFormGroup.reset();
}
});
}

View File

@@ -1,5 +1,5 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import {NzMessageService} from 'ng-zorro-antd/message';
import {LoginReq} from '../../../../class/User';
import {ActivatedRoute, Router} from '@angular/router';
import {LoginRegistrationService} from '../../service/login-registration.service';
@@ -13,6 +13,14 @@ import {GlobalUserService} from '../../../../services/global-user.service';
})
export class LoginComponent implements OnInit {
@Output() loginStatus = new EventEmitter<boolean>();
@Input() showSendEmail: boolean = true;
submitting: boolean = false;
loginReq: LoginReq = new LoginReq(null, true, null);
private url: string;
constructor(private nzMessageService: NzMessageService,
private userService: GlobalUserService,
private activatedRoute: ActivatedRoute,
@@ -22,14 +30,6 @@ export class LoginComponent implements OnInit {
this.title.setTitle('小海博客 | 登录 ');
}
submitting: boolean = false;
loginReq: LoginReq = new LoginReq(null, true, null);
@Output() loginStatus = new EventEmitter<boolean>();
@Input() showSendEmail: boolean = true;
private url: string;
ngOnInit() {
this.url = this.activatedRoute.snapshot.queryParamMap.get('url');
this.loginReq.email = localStorage.getItem('e');
@@ -68,7 +68,7 @@ export class LoginComponent implements OnInit {
this.router.navigateByUrl(this.url);
} else {
// window.location.href = '/admin/';
this.router.navigateByUrl('/admin')
this.router.navigateByUrl('/admin');
}
}
}

View File

@@ -15,6 +15,17 @@ import {Title} from '@angular/platform-browser';
})
export class RegistrationComponent implements OnInit {
@Output() regStatus = new EventEmitter<boolean>();
@Output() regAccount = new EventEmitter<LoginReq>();
imgCodeUrl: string;
imgCode: string;
email: string;
pwd: string;
submitting: boolean;
constructor(private apiService: ApiService,
private nzMessageService: NzMessageService,
private router: Router,
@@ -22,17 +33,6 @@ export class RegistrationComponent implements OnInit {
this.title.setTitle('小海博客 | 注册');
}
imgCodeUrl: string;
imgCode: string;
email: string;
pwd: string;
submitting: boolean;
@Output() regStatus = new EventEmitter<boolean>();
@Output() regAccount = new EventEmitter<LoginReq>();
ngOnInit() {
this.imgCodeUrl = environment.host + '/imgCode';
this.submitting = false;

View File

@@ -1,7 +1,7 @@
import {Component, OnInit} from '@angular/core';
import {ApiService} from '../../api/api.service';
import {LoginRegistrationService} from './service/login-registration.service';
import { NzMessageService } from 'ng-zorro-antd/message';
import {NzMessageService} from 'ng-zorro-antd/message';
@Component({
selector: 'view-login-registration',
@@ -10,14 +10,15 @@ import { NzMessageService } from 'ng-zorro-antd/message';
})
export class LoginRegistrationComponent implements OnInit {
picUrl: string = '';
email: string;
submitting: boolean = false;
constructor(private apiService: ApiService,
public loginRegistrationService: LoginRegistrationService,
private nzMessageService: NzMessageService) {
}
picUrl: string = '';
email: string;
submitting: boolean = false;
ngOnInit() {
this.apiService.bingPic().subscribe(data => {

View File

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

View File

@@ -15,9 +15,9 @@ export class UpdateComponent implements OnInit {
lastCommit: string;
committerAuthor: 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,
private apiService: ApiService) {

View File

@@ -1,7 +1,7 @@
import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Category} from '../../../../class/Tag';
import {ColorList} from '../../../../utils/color'
import {COLOR_LIST} from '../../../../utils/color';
@Component({
selector: 'c-publish-form',
@@ -11,16 +11,16 @@ import {ColorList} from '../../../../utils/color'
export class PublishFormComponent implements OnInit {
@ViewChild('inputElement', {static: true}) tagInputElement: ElementRef;
@Input() tagNacList: { name: string, size: number }[];
@Input() tagNacList: { name: string; size: number }[];
@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<{
id: number,
type: boolean,
tags: string[],
category: string,
isUpdate: boolean,
url?: string
id: number;
type: boolean;
tags: string[];
category: string;
isUpdate: boolean;
url?: string;
}>();
formGroup: FormGroup;
tagTmpList: string[] = [];
@@ -32,7 +32,7 @@ export class PublishFormComponent implements OnInit {
constructor(private fb: FormBuilder) {
}
randomColor = () => this.color = ColorList.map(c => c.bgColor).sort(() => Math.floor(Math.random() * 2));
randomColor = () => this.color = COLOR_LIST.map(c => c.bgColor).sort(() => Math.floor(Math.random() * 2));
ngOnInit(): void {
this.formGroup = this.fb.group({
@@ -94,7 +94,7 @@ export class PublishFormComponent implements OnInit {
this.formGroup.get('tagList').setValue(this.tagTmpList.length ? this.tagTmpList : null);
this.formGroup.get('tagList').updateValueAndValidity();
this.tagInputVisible = false;
this.editTagText = '新增'
this.editTagText = '新增';
}
// 点击tag切换
@@ -119,7 +119,11 @@ export class PublishFormComponent implements OnInit {
articleTypeChanged() {
this.formGroup.get(`url`).clearValidators();
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();
}
}

View File

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

View File

@@ -1,93 +0,0 @@
{
"extends": "tslint:recommended",
"rules": {
"nz-secondary-entry-imports": true,
"array-type": false,
"arrow-parens": false,
"deprecation": {
"severity": "warning"
},
"component-class-suffix": true,
"contextual-lifecycle": true,
"directive-class-suffix": true,
"directive-selector": [
false,
"attribute",
"app",
"camelCase"
],
"component-selector": [
false,
"element",
"app",
"kebab-case"
],
"import-blacklist": [
true,
"rxjs/Rx"
],
"interface-name": false,
"max-classes-per-file": false,
"max-line-length": [
true,
140
],
"member-access": false,
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-consecutive-blank-lines": false,
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-empty": false,
"no-inferrable-types": [
false,
"ignore-params"
],
"no-non-null-assertion": true,
"no-redundant-jsdoc": true,
"no-switch-case-fall-through": true,
"no-var-requires": false,
"object-literal-key-quotes": [
true,
"as-needed"
],
"object-literal-sort-keys": false,
"ordered-imports": false,
"quotemark": [
true,
"single"
],
"trailing-comma": false,
"no-conflicting-lifecycle": true,
"no-host-metadata-property": true,
"no-input-rename": true,
"no-inputs-metadata-property": true,
"no-output-native": true,
"no-output-on-prefix": true,
"no-output-rename": true,
"no-outputs-metadata-property": true,
"template-banana-in-box": true,
"template-no-negated-async": true,
"use-lifecycle-interface": true,
"use-pipe-transform-interface": true
},
"rulesDirectory": [
"codelyzer",
"node_modules/nz-tslint-rules"
]
}