Convert tslint to eslint #86

Merged
xiaohai2271 merged 9 commits from feature-tslint2eslint into master 2021-03-12 18:00:06 +08:00
20 changed files with 122 additions and 107 deletions
Showing only changes of commit 7ea7f83227 - Show all commits

View File

@@ -27,9 +27,9 @@
"prefer-arrow/prefer-arrow-functions": [
"off"
],
"@typescript-eslint/member-ordering": [
"off"
],
// "@typescript-eslint/member-ordering": [
// "on"
// ],
"@typescript-eslint/ban-types": [
"off"
],

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

@@ -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();

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;
@@ -139,5 +126,18 @@ export class HeaderComponent implements OnInit {
toAdminPage() {
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,17 +1,12 @@
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,
@@ -19,6 +14,12 @@ export class ComponentStateService {
};
currentPath: string;
constructor(private router: Router) {
this.watchRouterChange();
}
getCurrentRouterPath = () => this.currentPath;
watchRouterChange() {
@@ -33,7 +34,9 @@ export class ComponentStateService {
const prefix = path.substr(0, indexOf === 0 ? path.length : indexOf);
this.dealWithPathChange(prefix);
this.currentPath = prefix;
if (subscriber) {subscriber.next(prefix);}
if (subscriber) {
subscriber.next(prefix);
}
});
return ob;
}

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 HTTP_ERROR_COUNT: number = 0;
private readonly MAINTAIN_PAGE_PREFIX = '/maintain';
private readonly ADMIN_PAGE_PREFIX = '/admin';
constructor(/*private httpService: HttpService,*/
private router: Router,
@@ -20,10 +23,6 @@ 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);
@@ -33,9 +32,12 @@ export class ErrorService {
}
public httpException(response: Response<any>, request: RequestObj) {
if (!environment.production)
{console.log('exception=>', response, request);}
if (response.code === -1 && response.msg === '重复请求') {return;}
if (!environment.production) {
console.log('exception=>', response, request);
}
if (response.code === -1 && response.msg === '重复请求') {
return;
}
if (this.componentStateService.currentPath === this.ADMIN_PAGE_PREFIX) {
this.notification.create('error', `请求失败<${response.code}>`, `${response.msg}`);
}

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,6 +17,9 @@ 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);}

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,11 +1,12 @@
export class SvgIconUtil {
constructor() {
}
// 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() {
}
}

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>;
constructor(private apiService: ApiService, private nzMessage: NzMessageService, private title: Title,
private router: Router) {

View File

@@ -15,6 +15,8 @@ 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,
@@ -25,8 +27,6 @@ export class AdminCommentComponent implements OnInit {
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) {

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) {

View File

@@ -15,6 +15,10 @@ import {EditableTagComponent} from '../components/editable-tag/editable-tag.comp
})
export class AdminTagComponent implements OnInit {
@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,
@@ -25,9 +29,6 @@ export class AdminTagComponent implements OnInit {
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;

View File

@@ -11,7 +11,7 @@ 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]: {
@@ -19,14 +19,14 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
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) {
@@ -41,16 +41,22 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
}
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();
}
@@ -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
}

View File

@@ -30,8 +30,6 @@ import {NzModalRef, NzModalService} from 'ng-zorro-antd/modal';
export class EditableTagComponent implements OnInit, OnChanges {
private static instanceArray: EditableTagComponent[] = [];
inputVisible = false;
inputValue = '';
@ViewChild('inputElement', {static: false}) inputElement?: ElementRef;
@Output() valueChange = new EventEmitter<{ value: string; originalValue: string; changed: boolean }>();
@Input() color: string;
@@ -46,6 +44,8 @@ export class EditableTagComponent implements OnInit, OnChanges {
@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 }>();
inputVisible = false;
inputValue = '';
confirmModal?: NzModalRef;
private tmpKey: any;
private doubleClickInfo = {

View File

@@ -18,6 +18,7 @@ declare let $;
})
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,

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');

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 => {