From 7ea7f83227c8481f184fb28bcdb313cb77331e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BE=E5=87=A0=E6=B5=B7?= Date: Fri, 12 Mar 2021 16:48:27 +0800 Subject: [PATCH] style: eslint of member-ordering --- .eslintrc.json | 6 +- src/app/app.component.ts | 2 +- .../admin-header/admin-header.component.ts | 7 +- src/app/components/footer/footer.component.ts | 6 +- src/app/components/header/header.component.ts | 64 +++++++++---------- src/app/services/component-state.service.ts | 17 +++-- src/app/services/error.service.ts | 18 +++--- src/app/services/global-user.service.ts | 7 +- src/app/services/local-storage.service.ts | 3 +- src/app/utils/svgIconUtil.ts | 7 +- .../admin-article/admin-article.component.ts | 2 +- .../admin-comment/admin-comment.component.ts | 4 +- .../admin/admin-link/admin-link.component.ts | 2 +- .../admin/admin-tag/admin-tag.component.ts | 7 +- .../common-table/common-table.component.ts | 22 +++++-- .../editable-tag/editable-tag.component.ts | 4 +- src/app/view/article/article.component.ts | 2 +- .../components/login/login.component.ts | 18 +++--- .../registration/registration.component.ts | 22 +++---- .../login-registration.component.ts | 9 +-- 20 files changed, 122 insertions(+), 107 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index a45f31f..c2f68ca 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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" ], diff --git a/src/app/app.component.ts b/src/app/app.component.ts index bcbe683..c718d82 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -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) { } diff --git a/src/app/components/admin-header/admin-header.component.ts b/src/app/components/admin-header/admin-header.component.ts index 99d6df7..158fea4 100644 --- a/src/app/components/admin-header/admin-header.component.ts +++ b/src/app/components/admin-header/admin-header.component.ts @@ -8,13 +8,14 @@ import {User} from '../../class/User'; styleUrls: ['./admin-header.component.less'] }) export class AdminHeaderComponent implements OnInit { + @Output() infoClicked = new EventEmitter(); + user: User; + noAvatarUrl = 'https://cdn.celess.cn/'; constructor(private userService: GlobalUserService) { } - user: User; - @Output() infoClicked = new EventEmitter(); - noAvatarUrl = 'https://cdn.celess.cn/'; + logout = () => this.userService.logout(); infoClickedEvent = () => this.infoClicked.emit(); diff --git a/src/app/components/footer/footer.component.ts b/src/app/components/footer/footer.component.ts index 3fcbc30..25d4bc5 100644 --- a/src/app/components/footer/footer.component.ts +++ b/src/app/components/footer/footer.component.ts @@ -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() { } diff --git a/src/app/components/header/header.component.ts b/src/app/components/header/header.component.ts index 4caf56e..af75874 100644 --- a/src/app/components/header/header.component.ts +++ b/src/app/components/header/header.component.ts @@ -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); + } + } + }); + } + } diff --git a/src/app/services/component-state.service.ts b/src/app/services/component-state.service.ts index 7e89d2c..11a8a5d 100644 --- a/src/app/services/component-state.service.ts +++ b/src/app/services/component-state.service.ts @@ -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; } diff --git a/src/app/services/error.service.ts b/src/app/services/error.service.ts index 646232c..8616eeb 100644 --- a/src/app/services/error.service.ts +++ b/src/app/services/error.service.ts @@ -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, 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}`); } diff --git a/src/app/services/global-user.service.ts b/src/app/services/global-user.service.ts index 7f723a8..ff4f1f9 100644 --- a/src/app/services/global-user.service.ts +++ b/src/app/services/global-user.service.ts @@ -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>[] = []; private multicastArray: Observer>[] = []; + constructor(private apiService: ApiService, + private localStorageService: LocalStorageService) { + } watchUserInfo(observer: Observer>) { if (this.userObserverArray.indexOf(observer) < 0) {this.userObserverArray.push(observer);} diff --git a/src/app/services/local-storage.service.ts b/src/app/services/local-storage.service.ts index 996fbc1..db22760 100644 --- a/src/app/services/local-storage.service.ts +++ b/src/app/services/local-storage.service.ts @@ -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'); diff --git a/src/app/utils/svgIconUtil.ts b/src/app/utils/svgIconUtil.ts index e7bc91b..3b324c5 100644 --- a/src/app/utils/svgIconUtil.ts +++ b/src/app/utils/svgIconUtil.ts @@ -1,11 +1,12 @@ export class SvgIconUtil { - constructor() { - } - // eslint-disable-next-line max-len static readonly nameIcon = ''; // eslint-disable-next-line max-len static readonly locationIcon = ''; + + constructor() { + } + } diff --git a/src/app/view/admin/admin-article/admin-article.component.ts b/src/app/view/admin/admin-article/admin-article.component.ts index 1638ff3..f7b53af 100644 --- a/src/app/view/admin/admin-article/admin-article.component.ts +++ b/src/app/view/admin/admin-article/admin-article.component.ts @@ -14,9 +14,9 @@ import {Router} from '@angular/router'; }) export class AdminArticleComponent implements OnInit { + @ViewChild('commonTableComponent') private commonTableComponent: CommonTableComponent
; request: RequestObj; headData: Data
[]; - @ViewChild('commonTableComponent') private commonTableComponent: CommonTableComponent
; constructor(private apiService: ApiService, private nzMessage: NzMessageService, private title: Title, private router: Router) { diff --git a/src/app/view/admin/admin-comment/admin-comment.component.ts b/src/app/view/admin/admin-comment/admin-comment.component.ts index f431828..5f4ba5d 100644 --- a/src/app/view/admin/admin-comment/admin-comment.component.ts +++ b/src/app/view/admin/admin-comment/admin-comment.component.ts @@ -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; 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; constructor(private apiService: ApiService, private messageService: NzMessageService, private userService: GlobalUserService, private title: Title) { diff --git a/src/app/view/admin/admin-link/admin-link.component.ts b/src/app/view/admin/admin-link/admin-link.component.ts index 407d1b8..f5f7f09 100644 --- a/src/app/view/admin/admin-link/admin-link.component.ts +++ b/src/app/view/admin/admin-link/admin-link.component.ts @@ -15,11 +15,11 @@ import {Data} from '../components/common-table/data'; }) export class AdminLinkComponent implements OnInit { + @ViewChild('commonTableComponent') commonTableComponent: CommonTableComponent; modalVisible: boolean = false; modalTitle: string = ''; formGroup: FormGroup; request: RequestObj; - @ViewChild('commonTableComponent') commonTableComponent: CommonTableComponent; headData: Data[]; constructor(private apiService: ApiService, private messageService: NzMessageService, private title: Title) { diff --git a/src/app/view/admin/admin-tag/admin-tag.component.ts b/src/app/view/admin/admin-tag/admin-tag.component.ts index a74b055..9b57439 100644 --- a/src/app/view/admin/admin-tag/admin-tag.component.ts +++ b/src/app/view/admin/admin-tag/admin-tag.component.ts @@ -15,6 +15,10 @@ import {EditableTagComponent} from '../components/editable-tag/editable-tag.comp }) export class AdminTagComponent implements OnInit { + @ViewChild('categoryCTComponent', {static: true}) categoryCTComponent: CommonTableComponent; + @ViewChild('tagCTComponent', {static: true}) tagCTComponent: CommonTableComponent; + @ViewChild('editableTagComponent') editableTagComponent: EditableTagComponent; + categoryCTData: { headData: Data[]; commonTable: CommonTableComponent; 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; - @ViewChild('tagCTComponent', {static: true}) tagCTComponent: CommonTableComponent; - @ViewChild('editableTagComponent') editableTagComponent: EditableTagComponent; getData: any; private updateData: any; diff --git a/src/app/view/admin/components/common-table/common-table.component.ts b/src/app/view/admin/components/common-table/common-table.component.ts index e46378d..4845bc6 100644 --- a/src/app/view/admin/components/common-table/common-table.component.ts +++ b/src/app/view/admin/components/common-table/common-table.component.ts @@ -11,7 +11,7 @@ import {CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop'; }) export class CommonTableComponent 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 implements OnInit, OnChanges { param?: { [key: string]: string }; }; }; - @Output() pageInfo = new EventEmitter<{ page: number; pageSize: number }>(); + @Input() request: RequestObj; + @Input() private headData: Data[]; loading: boolean = true; dataList: PageList = new PageList(); settingModalVisible: boolean = false; filedData: Data[]; changed: boolean = false; visibleFieldLength: number = 0; - @Input() private headData: Data[]; constructor(private httpService: HttpService) { @@ -41,16 +41,22 @@ export class CommonTableComponent 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 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 } diff --git a/src/app/view/admin/components/editable-tag/editable-tag.component.ts b/src/app/view/admin/components/editable-tag/editable-tag.component.ts index 7ebbaac..904de7f 100644 --- a/src/app/view/admin/components/editable-tag/editable-tag.component.ts +++ b/src/app/view/admin/components/editable-tag/editable-tag.component.ts @@ -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(); @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 = { diff --git a/src/app/view/article/article.component.ts b/src/app/view/article/article.component.ts index 48e7e22..c5c6e92 100644 --- a/src/app/view/article/article.component.ts +++ b/src/app/view/article/article.component.ts @@ -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, diff --git a/src/app/view/login-registration/components/login/login.component.ts b/src/app/view/login-registration/components/login/login.component.ts index f19256e..a377763 100644 --- a/src/app/view/login-registration/components/login/login.component.ts +++ b/src/app/view/login-registration/components/login/login.component.ts @@ -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(); + @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(); - @Input() showSendEmail: boolean = true; - - private url: string; - ngOnInit() { this.url = this.activatedRoute.snapshot.queryParamMap.get('url'); this.loginReq.email = localStorage.getItem('e'); diff --git a/src/app/view/login-registration/components/registration/registration.component.ts b/src/app/view/login-registration/components/registration/registration.component.ts index 869b603..22a278e 100644 --- a/src/app/view/login-registration/components/registration/registration.component.ts +++ b/src/app/view/login-registration/components/registration/registration.component.ts @@ -15,6 +15,17 @@ import {Title} from '@angular/platform-browser'; }) export class RegistrationComponent implements OnInit { + @Output() regStatus = new EventEmitter(); + @Output() regAccount = new EventEmitter(); + + 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(); - @Output() regAccount = new EventEmitter(); - ngOnInit() { this.imgCodeUrl = environment.host + '/imgCode'; this.submitting = false; diff --git a/src/app/view/login-registration/login-registration.component.ts b/src/app/view/login-registration/login-registration.component.ts index 065bae9..7d39418 100644 --- a/src/app/view/login-registration/login-registration.component.ts +++ b/src/app/view/login-registration/login-registration.component.ts @@ -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 => {