From c13a7844a6d47f52b88f84747e6cf6058c83feca 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:00:56 +0800 Subject: [PATCH 1/9] chore: convert tslint to eslint --- .eslintrc.json | 69 +++++++++++++++ angular.json | 12 +-- package.json | 13 ++- src/app/services/component-state.service.ts | 2 +- src/app/utils/dataUtil.ts | 4 +- src/app/utils/svgIconUtil.ts | 4 +- tslint.json | 93 --------------------- 7 files changed, 90 insertions(+), 107 deletions(-) create mode 100644 .eslintrc.json delete mode 100644 tslint.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..b5c6517 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,69 @@ +{ + "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": { + "@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": {} + } + ] +} diff --git a/angular.json b/angular.json index ec063a3..667492d 100644 --- a/angular.json +++ b/angular.json @@ -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" ] } }, diff --git a/package.json b/package.json index ca5b812..32cd5fe 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,17 @@ "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" } } diff --git a/src/app/services/component-state.service.ts b/src/app/services/component-state.service.ts index 74e270e..57878eb 100644 --- a/src/app/services/component-state.service.ts +++ b/src/app/services/component-state.service.ts @@ -39,7 +39,7 @@ export class ComponentStateService { } 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 } diff --git a/src/app/utils/dataUtil.ts b/src/app/utils/dataUtil.ts index 185f0ea..98b5657 100644 --- a/src/app/utils/dataUtil.ts +++ b/src/app/utils/dataUtil.ts @@ -12,9 +12,9 @@ export function exist(pageNum: number, pageSize: number, pageList: PageList> = new Observable(o => { o.next(pageList[i]); diff --git a/src/app/utils/svgIconUtil.ts b/src/app/utils/svgIconUtil.ts index 3d17823..e7bc91b 100644 --- a/src/app/utils/svgIconUtil.ts +++ b/src/app/utils/svgIconUtil.ts @@ -3,9 +3,9 @@ export class SvgIconUtil { constructor() { } - // tslint:disable-next-line:max-line-length + // eslint-disable-next-line max-len static readonly nameIcon = ''; - // tslint:disable-next-line:max-line-length + // eslint-disable-next-line max-len static readonly locationIcon = ''; } diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 6858576..0000000 --- a/tslint.json +++ /dev/null @@ -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" - ] -} -- 2.49.1 From b65b25c1fa03c420bb52ec1a32d622aa29d23227 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:10:07 +0800 Subject: [PATCH 2/9] chore: ignore some code rules --- .eslintrc.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.eslintrc.json b/.eslintrc.json index b5c6517..a45f31f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,6 +21,18 @@ "plugin:@angular-eslint/template/process-inline-templates" ], "rules": { + "@typescript-eslint/naming-convention": [ + "off" + ], + "prefer-arrow/prefer-arrow-functions": [ + "off" + ], + "@typescript-eslint/member-ordering": [ + "off" + ], + "@typescript-eslint/ban-types": [ + "off" + ], "@angular-eslint/component-selector": [ "off", { -- 2.49.1 From 33d7bbaf43f4dd9f4e38711a16093e5937c14051 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:11:09 +0800 Subject: [PATCH 3/9] style: eslint fix --- src/app/api/api.service.ts | 24 +++++----- src/app/api/http/http.service.ts | 5 +- src/app/class/Link.ts | 2 +- src/app/class/User.ts | 2 +- .../admin-header/admin-header.component.ts | 8 ++-- src/app/components/header/header.component.ts | 4 +- src/app/services/component-state.service.ts | 24 +++++----- src/app/services/error.service.ts | 16 +++---- src/app/services/global-user.service.ts | 26 +++++------ src/app/utils/color.ts | 11 +++-- src/app/utils/dataUtil.ts | 3 +- .../admin-article/admin-article.component.ts | 16 +++---- .../admin-comment/admin-comment.component.ts | 24 +++++----- .../admin-dashboard.component.ts | 22 ++++----- .../admin/admin-link/admin-link.component.ts | 27 +++++++---- .../admin/admin-tag/admin-tag.component.ts | 36 +++++++-------- .../admin-update/admin-update.component.ts | 14 +++--- .../admin/admin-user/admin-user.component.ts | 14 +++--- .../admin-visitor/admin-visitor.component.ts | 8 ++-- src/app/view/admin/admin.component.ts | 38 +++++++-------- src/app/view/admin/auth.guard.ts | 4 +- .../common-table/common-table.component.ts | 46 +++++++++---------- .../common-table/common-table.module.ts | 2 +- .../admin/components/common-table/data.ts | 22 ++++----- .../editable-tag/editable-tag.component.ts | 22 ++++----- .../test-common-table.component.ts | 4 +- src/app/view/article/article.component.ts | 6 +-- .../components/tag-tag/tag-tag.component.ts | 4 +- src/app/view/index/index.component.ts | 14 +++--- src/app/view/link/link.component.ts | 8 ++-- .../components/login/login.component.ts | 2 +- src/app/view/tag/tag.component.ts | 6 +-- src/app/view/update/update.component.ts | 4 +- .../publish-form/publish-form.component.ts | 26 ++++++----- src/app/view/write/write.component.ts | 22 ++++----- 35 files changed, 262 insertions(+), 254 deletions(-) diff --git a/src/app/api/api.service.ts b/src/app/api/api.service.ts index 61436d3..2641b92 100644 --- a/src/app/api/api.service.ts +++ b/src/app/api/api.service.ts @@ -33,7 +33,7 @@ export class ApiService { path: '/admin/article/del', method: 'DELETE', queryParam: {articleID: id} - }) + }); } articles(pageNumber: number = 1, pageSize: number = 5) { @@ -140,7 +140,7 @@ 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' }); @@ -232,11 +232,11 @@ export class ApiService { counts() { return this.httpService.Service<{ - articleCount: number, - visitorCount: number, - categoryCount: number, - tagCount: number, - commentCount: number + articleCount: number; + visitorCount: number; + categoryCount: number; + tagCount: number; + commentCount: number; }>({ path: '/counts', method: 'GET' @@ -394,7 +394,7 @@ export class ApiService { method: 'PUT', data: user, contentType: 'application/json' - }) + }); } deleteUser(id: number) { @@ -418,7 +418,7 @@ export class ApiService { return this.httpService.Service({ path: `/emailStatus/${email}`, method: 'GET' - }) + }); } updateUserInfo(descStr: string, disPlayNameStr: string) { @@ -491,14 +491,14 @@ export class ApiService { } 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>({ + return this.httpService.Service>({ path: '/webUpdate/pages', method: 'GET', queryParam: { @@ -515,7 +515,7 @@ export class ApiService { lastCommit: string; committerAuthor: string; committerDate: string; - commitUrl: string + commitUrl: string; }>({ path: '/lastestUpdate', method: 'GET' diff --git a/src/app/api/http/http.service.ts b/src/app/api/http/http.service.ts index bc5fdd2..4d94bbc 100644 --- a/src/app/api/http/http.service.ts +++ b/src/app/api/http/http.service.ts @@ -62,7 +62,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 +71,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 +117,7 @@ export class HttpService { /** * 验证并且处理拼接 URl + * * @param req Request */ private checkUrl(req: RequestObj): string { diff --git a/src/app/class/Link.ts b/src/app/class/Link.ts index 7a74650..16ca04c 100644 --- a/src/app/class/Link.ts +++ b/src/app/class/Link.ts @@ -14,5 +14,5 @@ export class ApplyLinkReq { iconPath: string; linkUrl: string; name: string; - url: string + url: string; } diff --git a/src/app/class/User.ts b/src/app/class/User.ts index d15d989..2b41d3b 100644 --- a/src/app/class/User.ts +++ b/src/app/class/User.ts @@ -8,7 +8,7 @@ export class User { role?: string; token?: string; pwd?: string; - recentlyLandedDate?: string + recentlyLandedDate?: string; } export class LoginReq { diff --git a/src/app/components/admin-header/admin-header.component.ts b/src/app/components/admin-header/admin-header.component.ts index cd4d6c8..99d6df7 100644 --- a/src/app/components/admin-header/admin-header.component.ts +++ b/src/app/components/admin-header/admin-header.component.ts @@ -12,9 +12,9 @@ export class AdminHeaderComponent implements OnInit { constructor(private userService: GlobalUserService) { } - user: User - @Output() infoClicked = new EventEmitter() - noAvatarUrl = 'https://cdn.celess.cn/' + user: User; + @Output() infoClicked = new EventEmitter(); + noAvatarUrl = 'https://cdn.celess.cn/'; logout = () => this.userService.logout(); infoClickedEvent = () => this.infoClicked.emit(); @@ -23,7 +23,7 @@ export class AdminHeaderComponent implements OnInit { next: data => this.user = data.result, error: err => this.user = null, complete: null - }) + }); } } diff --git a/src/app/components/header/header.component.ts b/src/app/components/header/header.component.ts index 34de1e8..4caf56e 100644 --- a/src/app/components/header/header.component.ts +++ b/src/app/components/header/header.component.ts @@ -50,7 +50,7 @@ export class HeaderComponent implements OnInit { @Output() registrationEvent = new EventEmitter(); size: 'large' | 'default'; currentPath: string; - noAvatarUrl = 'https://cdn.celess.cn/' + noAvatarUrl = 'https://cdn.celess.cn/'; public pageList: { path: string; @@ -137,7 +137,7 @@ export class HeaderComponent implements OnInit { } toAdminPage() { - this.router.navigateByUrl('/admin') + this.router.navigateByUrl('/admin'); } } diff --git a/src/app/services/component-state.service.ts b/src/app/services/component-state.service.ts index 57878eb..7e89d2c 100644 --- a/src/app/services/component-state.service.ts +++ b/src/app/services/component-state.service.ts @@ -9,16 +9,16 @@ import {Observable, of, Subscriber} from 'rxjs'; export class ComponentStateService { constructor(private router: Router) { - this.watchRouterChange() + this.watchRouterChange(); } visible = { header: true, footer: true, globalBackToTop: true - } + }; - currentPath: string + currentPath: string; getCurrentRouterPath = () => this.currentPath; watchRouterChange() { @@ -31,9 +31,9 @@ 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; } @@ -41,18 +41,18 @@ export class ComponentStateService { private dealWithPathChange(path) { // 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: diff --git a/src/app/services/error.service.ts b/src/app/services/error.service.ts index 878c153..646232c 100644 --- a/src/app/services/error.service.ts +++ b/src/app/services/error.service.ts @@ -21,12 +21,12 @@ export class ErrorService { } private static HTTP_ERROR_COUNT: number = 0; - private readonly MAINTAIN_PAGE_PREFIX = '/maintain' - private readonly ADMIN_PAGE_PREFIX = '/admin' + 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++; // this.httpService.getSubscriptionQueue().map(a => a.unsubscribe()) @@ -34,8 +34,8 @@ export class ErrorService { public httpException(response: Response, request: RequestObj) { if (!environment.production) - console.log('exception=>', response, request) - if (response.code === -1 && response.msg === '重复请求') return + {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}`); } @@ -62,16 +62,16 @@ export class ErrorService { 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) + this.router.navigateByUrl(this.MAINTAIN_PAGE_PREFIX); } ErrorService.HTTP_ERROR_COUNT = 0; } - }) + }); } } } diff --git a/src/app/services/global-user.service.ts b/src/app/services/global-user.service.ts index d7f037a..7f723a8 100644 --- a/src/app/services/global-user.service.ts +++ b/src/app/services/global-user.service.ts @@ -23,24 +23,24 @@ export class GlobalUserService { private multicastArray: Observer>[] = []; watchUserInfo(observer: Observer>) { - 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 +59,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 +82,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 +93,7 @@ export class GlobalUserService { observer.error(error); observer.complete(); } - }) + }); } getUserInfoFromServer(observer?: Observer>) { @@ -102,7 +102,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 +118,12 @@ export class GlobalUserService { if (err.code === -1) { // 请求重复 - return + return; } // this.requested = false; // this.localStorageService.removeToken(); - this.multicastArray.forEach(ob => ob.next(new Response(this.userInfo))) - this.multicastArray.forEach(ob => ob.error(err)) + this.multicastArray.forEach(ob => ob.next(new Response(this.userInfo))); + this.multicastArray.forEach(ob => ob.error(err)); this.multicastArray.splice(0, this.multicastArray.length); } @@ -131,7 +131,7 @@ export class GlobalUserService { } private broadcast() { - this.multicastArray.forEach(ob => ob.next(new Response(this.userInfo))) + this.multicastArray.forEach(ob => ob.next(new Response(this.userInfo))); this.multicastArray.splice(0, this.multicastArray.length); } } diff --git a/src/app/utils/color.ts b/src/app/utils/color.ts index 7f9773c..fdcb973 100644 --- a/src/app/utils/color.ts +++ b/src/app/utils/color.ts @@ -1,6 +1,6 @@ export class Color { bgColor: string; - fontColor: string + fontColor: string; } export const ColorList: Color[] = [ @@ -13,23 +13,24 @@ export const ColorList: Color[] = [ {bgColor: '#177cb0', fontColor: '#ffffff'}, // 靛青 ]; -export const ColorListLength = ColorList.length +export const ColorListLength = ColorList.length; /** * 获取一组随机颜色 + * * @param count 数量 */ export function RandomColor(count: number = 1): Color[] { const map = new Map(); - ColorList.forEach((color, index) => map.set(index, 0)) + ColorList.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 ColorList[index]; }; for (let i = 0; i < count; i++) { colorArray.push(oneRandomColor()); diff --git a/src/app/utils/dataUtil.ts b/src/app/utils/dataUtil.ts index 98b5657..6edbe83 100644 --- a/src/app/utils/dataUtil.ts +++ b/src/app/utils/dataUtil.ts @@ -3,6 +3,7 @@ import {PageList} from '../class/HttpReqAndResp'; /** * 判断 一个Page[] 中是否存在一条已查询的数据 + * * @param pageNum 页码 * @param pageSize 单页数量 * @param pageList 源数据 @@ -19,7 +20,7 @@ export function exist(pageNum: number, pageSize: number, pageList: PageList> = new Observable(o => { o.next(pageList[i]); o.complete(); - }) + }); } } return null; 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 62693c1..1638ff3 100644 --- a/src/app/view/admin/admin-article/admin-article.component.ts +++ b/src/app/view/admin/admin-article/admin-article.component.ts @@ -15,8 +15,8 @@ import {Router} from '@angular/router'; export class AdminArticleComponent implements OnInit { request: RequestObj; - headData: Data
[] - @ViewChild('commonTableComponent') private commonTableComponent: CommonTableComponent
+ headData: Data
[]; + @ViewChild('commonTableComponent') private commonTableComponent: CommonTableComponent
; 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); } - }) + }); } } 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 426b9c3..f431828 100644 --- a/src/app/view/admin/admin-comment/admin-comment.component.ts +++ b/src/app/view/admin/admin-comment/admin-comment.component.ts @@ -19,26 +19,26 @@ export class AdminCommentComponent implements OnInit { editInfo = { id: null, content: new CommentReq(null), - } + }; headData: Data[]; modalData = { 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) { - 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(); } } } diff --git a/src/app/view/admin/admin-dashboard/admin-dashboard.component.ts b/src/app/view/admin/admin-dashboard/admin-dashboard.component.ts index 41eaa25..182e6a1 100644 --- a/src/app/view/admin/admin-dashboard/admin-dashboard.component.ts +++ b/src/app/view/admin/admin-dashboard/admin-dashboard.component.ts @@ -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 - }) + }); } 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 4474e6a..407d1b8 100644 --- a/src/app/view/admin/admin-link/admin-link.component.ts +++ b/src/app/view/admin/admin-link/admin-link.component.ts @@ -19,7 +19,7 @@ export class AdminLinkComponent implements OnInit { modalTitle: string = ''; formGroup: FormGroup; request: RequestObj; - @ViewChild('commonTableComponent') commonTableComponent: CommonTableComponent + @ViewChild('commonTableComponent') commonTableComponent: CommonTableComponent; headData: Data[]; 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>; 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'); } } 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 2c3cced..a74b055 100644 --- a/src/app/view/admin/admin-tag/admin-tag.component.ts +++ b/src/app/view/admin/admin-tag/admin-tag.component.ts @@ -15,19 +15,19 @@ import {EditableTagComponent} from '../components/editable-tag/editable-tag.comp }) export class AdminTagComponent implements OnInit { - categoryCTData: { headData: Data[], commonTable: CommonTableComponent, request: RequestObj } = { + categoryCTData: { headData: Data[]; commonTable: CommonTableComponent; request: RequestObj } = { headData: null, commonTable: null, request: null - } - tagCTData: { headData: Data[], commonTable: CommonTableComponent, request: RequestObj } = { + }; + tagCTData: { headData: Data[]; commonTable: CommonTableComponent; request: RequestObj } = { headData: null, commonTable: null, request: null - } - @ViewChild('categoryCTComponent', {static: true}) categoryCTComponent: CommonTableComponent - @ViewChild('tagCTComponent', {static: true}) tagCTComponent: CommonTableComponent - @ViewChild('editableTagComponent') editableTagComponent: EditableTagComponent + }; + @ViewChild('categoryCTComponent', {static: true}) categoryCTComponent: CommonTableComponent; + @ViewChild('tagCTComponent', {static: true}) tagCTComponent: CommonTableComponent; + @ViewChild('editableTagComponent') editableTagComponent: EditableTagComponent; getData: any; private updateData: any; @@ -35,7 +35,7 @@ export class AdminTagComponent implements OnInit { } ngOnInit(): void { - this.title.setTitle('小海博客 | 标签分类管理') + this.title.setTitle('小海博客 | 标签分类管理'); this.categoryCTData = { commonTable: this.categoryCTComponent, headData: [ @@ -64,7 +64,7 @@ export class AdminTagComponent implements OnInit { count: 1000 } } - } + }; this.tagCTData = { commonTable: this.tagCTComponent, headData: [ @@ -87,7 +87,7 @@ export class AdminTagComponent implements OnInit { count: 10 } } - } + }; this.getData = this.categoryCTComponent.getData; } @@ -96,29 +96,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 +133,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(); }, diff --git a/src/app/view/admin/admin-update/admin-update.component.ts b/src/app/view/admin/admin-update/admin-update.component.ts index 91432da..aedf59f 100644 --- a/src/app/view/admin/admin-update/admin-update.component.ts +++ b/src/app/view/admin/admin-update/admin-update.component.ts @@ -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> + let observable: Observable>; 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) { diff --git a/src/app/view/admin/admin-user/admin-user.component.ts b/src/app/view/admin/admin-user/admin-user.component.ts index 655acd7..427afa0 100644 --- a/src/app/view/admin/admin-user/admin-user.component.ts +++ b/src/app/view/admin/admin-user/admin-user.component.ts @@ -20,7 +20,7 @@ export class AdminUserComponent implements OnInit { title: null, isEdit: false, resetPwd: false - } + }; formGroup: FormGroup; headData: Data[]; 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(); } - }) + }); } } diff --git a/src/app/view/admin/admin-visitor/admin-visitor.component.ts b/src/app/view/admin/admin-visitor/admin-visitor.component.ts index b99587f..0ab3b8f 100644 --- a/src/app/view/admin/admin-visitor/admin-visitor.component.ts +++ b/src/app/view/admin/admin-visitor/admin-visitor.component.ts @@ -12,13 +12,13 @@ import {Data} from '../components/common-table/data'; export class AdminVisitorComponent implements OnInit { headData: Data[]; - 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} - ] + ]; } } diff --git a/src/app/view/admin/admin.component.ts b/src/app/view/admin/admin.component.ts index 9831522..ebd3274 100644 --- a/src/app/view/admin/admin.component.ts +++ b/src/app/view/admin/admin.component.ts @@ -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,25 @@ 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()} - }; + uploadHeader = (file: NzUploadFile): any | Observable<{}> => ({Authorization: this.localStorageService.getToken()}); showEditInfoModal() { this.editInfoModalVisible = true; @@ -88,7 +84,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 +107,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 +126,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}`; } } } diff --git a/src/app/view/admin/auth.guard.ts b/src/app/view/admin/auth.guard.ts index e024553..5a7344d 100644 --- a/src/app/view/admin/auth.guard.ts +++ b/src/app/view/admin/auth.guard.ts @@ -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; } 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 51e4f5d..e46378d 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 @@ -15,11 +15,11 @@ export class CommonTableComponent implements OnInit, OnChanges { @Input() cardTitle: string | null; @Input() template: { [fieldValue: string]: { - temp: TemplateRef, - param?: { [key: string]: string } - } + temp: TemplateRef; + param?: { [key: string]: string }; + }; }; - @Output() pageInfo = new EventEmitter<{ page: number, pageSize: number }>(); + @Output() pageInfo = new EventEmitter<{ page: number; pageSize: number }>(); loading: boolean = true; dataList: PageList = new PageList(); settingModalVisible: boolean = false; @@ -37,20 +37,20 @@ export class CommonTableComponent 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 +65,15 @@ export class CommonTableComponent implements OnInit, OnChanges { // page: pageValue, // count: countValue // } - this.pageInfo.emit({page: pageValue, pageSize: countValue}) + this.pageInfo.emit({page: pageValue, pageSize: countValue}); return this.httpService.Service>(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 +87,7 @@ 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 } @@ -96,21 +96,21 @@ export class CommonTableComponent 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 +121,10 @@ export class CommonTableComponent 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 +138,7 @@ export class CommonTableComponent implements OnInit, OnChanges { this.filedData = this.cloneData(this.headData); this.changed = false; this.calculateVisibleFieldLength(); - } + }; cloneData = (source: Data[] | string): Data[] => { let dist: Data[]; @@ -151,11 +151,11 @@ export class CommonTableComponent 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 +169,5 @@ export class CommonTableComponent implements OnInit, OnChanges { this.changed = true; } } - } + }; } diff --git a/src/app/view/admin/components/common-table/common-table.module.ts b/src/app/view/admin/components/common-table/common-table.module.ts index 52820c3..637033d 100644 --- a/src/app/view/admin/components/common-table/common-table.module.ts +++ b/src/app/view/admin/components/common-table/common-table.module.ts @@ -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: [ diff --git a/src/app/view/admin/components/common-table/data.ts b/src/app/view/admin/components/common-table/data.ts index e78c69a..91e9efa 100644 --- a/src/app/view/admin/components/common-table/data.ts +++ b/src/app/view/admin/components/common-table/data.ts @@ -7,19 +7,19 @@ export class Data { primaryKey?: boolean = false; isActionColumns?: boolean = false; template?: { - template: TemplateRef, + template: TemplateRef; 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; - }[] = [] + }[] = []; } 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 bab560d..7ebbaac 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 @@ -29,11 +29,11 @@ import {NzModalRef, NzModalService} from 'ng-zorro-antd/modal'; }) export class EditableTagComponent implements OnInit, OnChanges { - private static instanceArray: EditableTagComponent[] = [] + private static instanceArray: EditableTagComponent[] = []; inputVisible = false; inputValue = ''; @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 +44,8 @@ export class EditableTagComponent implements OnInit, OnChanges { @Input() autoClear: boolean; @Input() size: 'small' | 'default' | 'large'; @Output() inEditStatus = new EventEmitter(); - @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 }>(); 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; } } diff --git a/src/app/view/admin/test-common-table/test-common-table.component.ts b/src/app/view/admin/test-common-table/test-common-table.component.ts index 2a3ccac..c68af30 100644 --- a/src/app/view/admin/test-common-table/test-common-table.component.ts +++ b/src/app/view/admin/test-common-table/test-common-table.component.ts @@ -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 } - } + }; } } diff --git a/src/app/view/article/article.component.ts b/src/app/view/article/article.component.ts index c95cc01..48e7e22 100644 --- a/src/app/view/article/article.component.ts +++ b/src/app/view/article/article.component.ts @@ -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', @@ -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}`); diff --git a/src/app/view/index/components/tag-tag/tag-tag.component.ts b/src/app/view/index/components/tag-tag/tag-tag.component.ts index ab7e870..fe87d25 100644 --- a/src/app/view/index/components/tag-tag/tag-tag.component.ts +++ b/src/app/view/index/components/tag-tag/tag-tag.component.ts @@ -9,12 +9,12 @@ 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) { } diff --git a/src/app/view/index/index.component.ts b/src/app/view/index/index.component.ts index 307e4df..919e548 100644 --- a/src/app/view/index/index.component.ts +++ b/src/app/view/index/index.component.ts @@ -23,14 +23,14 @@ export class IndexComponent implements OnInit { imgUrl: string; desc: string; articles: PageList
; - 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, diff --git a/src/app/view/link/link.component.ts b/src/app/view/link/link.component.ts index 2e72145..30698e4 100644 --- a/src/app/view/link/link.component.ts +++ b/src/app/view/link/link.component.ts @@ -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(); } }); } 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 04d96a4..f19256e 100644 --- a/src/app/view/login-registration/components/login/login.component.ts +++ b/src/app/view/login-registration/components/login/login.component.ts @@ -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'); } } } diff --git a/src/app/view/tag/tag.component.ts b/src/app/view/tag/tag.component.ts index 10c9ca0..9c71cf3 100644 --- a/src/app/view/tag/tag.component.ts +++ b/src/app/view/tag/tag.component.ts @@ -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
; 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; } diff --git a/src/app/view/update/update.component.ts b/src/app/view/update/update.component.ts index 9c08db9..d6ebc05 100644 --- a/src/app/view/update/update.component.ts +++ b/src/app/view/update/update.component.ts @@ -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) { diff --git a/src/app/view/write/components/publish-form/publish-form.component.ts b/src/app/view/write/components/publish-form/publish-form.component.ts index bf63ada..210f101 100644 --- a/src/app/view/write/components/publish-form/publish-form.component.ts +++ b/src/app/view/write/components/publish-form/publish-form.component.ts @@ -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 {ColorList} 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[] = []; @@ -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(); } } diff --git a/src/app/view/write/write.component.ts b/src/app/view/write/write.component.ts index 59ef179..6380c8a 100644 --- a/src/app/view/write/write.component.ts +++ b/src/app/view/write/write.component.ts @@ -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,14 @@ 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()} - } + setHeaders: () => ({Authorization: this.localStorageService.getToken()}) }, after: () => { // 判断是更新文章还是恢复文章 @@ -258,6 +256,6 @@ export class WriteComponent implements OnInit, OnDestroy { this.article = JSON.parse(localStorage.getItem('tmpArticle')); } } - } + }; } } -- 2.49.1 From 2037c95ffdbf942b2a8a3fab1c671d7ee2933736 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:16:23 +0800 Subject: [PATCH 4/9] chore(deps-dev): remove tslint dependences --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 32cd5fe..310a6a3 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ "nz-tslint-rules": "^0.901.2", "protractor": "^7.0.0", "ts-node": "^9.0.0", - "tslint": "^6.1.3", "typescript": "~4.1.0", "eslint": "^7.6.0", "eslint-plugin-import": "2.22.1", -- 2.49.1 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 5/9] 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 => { -- 2.49.1 From 6bfb42e43dd7c31ecae84802c03c23154cb2cc31 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 17:30:05 +0800 Subject: [PATCH 6/9] style: eslint of naming-convention --- .eslintrc.json | 8 +- src/app/api/api.service.ts | 128 +++++++++++++------------- src/app/api/http/http.service.ts | 3 +- src/app/services/error.service.ts | 18 ++-- src/app/utils/color.ts | 10 +- src/app/view/admin/admin.component.ts | 1 + src/app/view/write/write.component.ts | 1 + 7 files changed, 86 insertions(+), 83 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index c2f68ca..66ed365 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,13 +21,13 @@ "plugin:@angular-eslint/template/process-inline-templates" ], "rules": { - "@typescript-eslint/naming-convention": [ - "off" - ], +// "@typescript-eslint/naming-convention": [ +// "off" +// ], "prefer-arrow/prefer-arrow-functions": [ "off" ], -// "@typescript-eslint/member-ordering": [ +// "@typescript-eslint/member-ordering": [svn // "on" // ], "@typescript-eslint/ban-types": [ diff --git a/src/app/api/api.service.ts b/src/app/api/api.service.ts index 2641b92..4984176 100644 --- a/src/app/api/api.service.ts +++ b/src/app/api/api.service.ts @@ -20,7 +20,7 @@ export class ApiService { createArticle(article: ArticleReq) { article.id = null; - return this.httpService.Service
({ + return this.httpService.service
({ path: '/admin/article/create', contentType: 'application/json', method: 'POST', @@ -29,7 +29,7 @@ export class ApiService { } deleteArticle(id: number) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/article/del', method: 'DELETE', queryParam: {articleID: id} @@ -37,7 +37,7 @@ export class ApiService { } articles(pageNumber: number = 1, pageSize: number = 5) { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/articles', method: 'GET', queryParam: { @@ -48,7 +48,7 @@ export class ApiService { } adminArticles(pageNumber: number = 1, pageSize: number = 10) { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/admin/articles', method: 'GET', queryParam: { @@ -59,7 +59,7 @@ export class ApiService { } updateArticle(article: ArticleReq) { - return this.httpService.Service
({ + return this.httpService.service
({ 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
({ + return this.httpService.service
({ 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>({ + return this.httpService.service>({ 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>({ + return this.httpService.service>({ path: `/articles/tag/${tag}`, method: 'GET', queryParam: { @@ -98,14 +98,14 @@ export class ApiService { } categories() { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/categories', method: 'GET' }); } createCategory(nameStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/category/create', method: 'POST', queryParam: {name: nameStr} @@ -113,7 +113,7 @@ export class ApiService { } deleteCategory(categoryId: number) { - return this.httpService.Service({ + return this.httpService.service({ 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({ + return this.httpService.service({ 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>({ + return this.httpService.service>({ 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({ + return this.httpService.service({ path: '/admin/tag/create', method: 'POST', queryParam: {name: nameStr} }); } - deleteTag(TagId: number) { - return this.httpService.Service({ + deleteTag(tagId: number) { + return this.httpService.service({ path: '/admin/tag/del', method: 'DELETE', - queryParam: {id: TagId} + queryParam: {id: tagId} }); } - updateTag(TagId: number, nameStr: string) { - return this.httpService.Service({ + updateTag(tagId: number, nameStr: string) { + return this.httpService.service({ 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>({ + return this.httpService.service>({ 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>({ + return this.httpService.service>({ path: `/user/comment/pagePath/${pagePath}`, method: 'GET', queryParam: { @@ -193,7 +193,7 @@ export class ApiService { } deleteComment(idNumer: number) { - return this.httpService.Service({ + return this.httpService.service({ path: `/user/comment/del`, method: 'DELETE', queryParam: {id: idNumer} @@ -201,7 +201,7 @@ export class ApiService { } updateComment(commentReq: CommentReq) { - return this.httpService.Service({ + return this.httpService.service({ 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>({ + return this.httpService.service>({ path: `/comment/pagePath/${pagePath}`, method: 'GET', queryParam: { @@ -221,7 +221,7 @@ export class ApiService { } createComment(commentReq: CommentReq) { - return this.httpService.Service({ + return this.httpService.service({ path: '/user/comment/create', method: 'POST', contentType: 'application/json', @@ -231,7 +231,7 @@ export class ApiService { counts() { - return this.httpService.Service<{ + return this.httpService.service<{ articleCount: number; visitorCount: number; categoryCount: number; @@ -244,7 +244,7 @@ export class ApiService { } adminLinks(pageSize: number = 10, pageNumber: number = 1) { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/admin/links', method: 'GET', queryParam: { @@ -255,7 +255,7 @@ export class ApiService { } createLink(linkReq: Link) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/links/create', method: 'POST', data: linkReq, @@ -264,14 +264,14 @@ export class ApiService { } deleteLink(idNumber: number) { - return this.httpService.Service({ + return this.httpService.service({ path: `/admin/links/del/${idNumber}`, method: 'DELETE', }); } updateLink(linkReq: Link) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/links/update', method: 'PUT', data: linkReq, @@ -280,7 +280,7 @@ export class ApiService { } applyLink(link: ApplyLinkReq) { - return this.httpService.Service({ + return this.httpService.service({ path: '/apply', method: 'POST', data: link, @@ -289,7 +289,7 @@ export class ApiService { } reapplyLink(keyStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/reapply', method: 'POST', queryParam: { @@ -299,14 +299,14 @@ export class ApiService { } links() { - return this.httpService.Service({ + return this.httpService.service({ path: '/links', method: 'GET', }); } verifyImgCode(codeStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/verCode', method: 'POST', queryParam: {code: codeStr} @@ -315,7 +315,7 @@ export class ApiService { login(loginReq: LoginReq) { - return this.httpService.Service({ + return this.httpService.service({ path: '/login', method: 'POST', contentType: 'application/json', @@ -324,14 +324,14 @@ export class ApiService { } logout() { - return this.httpService.Service({ + return this.httpService.service({ path: '/logout', method: 'GET', }); } registration(emailStr: string, pwd: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/registration', method: 'POST', queryParam: { @@ -342,7 +342,7 @@ export class ApiService { } resetPwd(idStr: string, emailStr: string, pwdStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/resetPwd', method: 'POST', queryParam: { @@ -354,7 +354,7 @@ export class ApiService { } emailVerify(idStr: string, emailStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/emailVerify', method: 'POST', queryParam: { @@ -366,7 +366,7 @@ export class ApiService { sendResetPwdEmail(emailStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/sendResetPwdEmail', method: 'POST', queryParam: {email: emailStr} @@ -374,7 +374,7 @@ export class ApiService { } sendVerifyEmail(emailStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/sendVerifyEmail', method: 'POST', queryParam: {email: emailStr} @@ -382,14 +382,14 @@ export class ApiService { } userInfo() { - return this.httpService.Service({ + return this.httpService.service({ path: '/user/userInfo', method: 'GET', }); } adminUpdateUser(user: User) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/user', method: 'PUT', data: user, @@ -398,14 +398,14 @@ export class ApiService { } deleteUser(id: number) { - return this.httpService.Service({ + return this.httpService.service({ 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({ + return this.httpService.service({ path: `/emailStatus/${email}`, method: 'GET' }); } updateUserInfo(descStr: string, disPlayNameStr: string) { - return this.httpService.Service({ + return this.httpService.service({ 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>({ + return this.httpService.service>({ path: '/admin/users', method: 'GET', queryParam: { @@ -444,14 +444,14 @@ export class ApiService { } visit() { - return this.httpService.Service({ + return this.httpService.service({ path: '/visit', method: 'POST' }); } adminVisitors(location: boolean = false, pageSize: number = 10, pageNumber: number = 1) { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/admin/visitor/page', method: 'GET', queryParam: { @@ -463,42 +463,42 @@ export class ApiService { } dayVisitCount() { - return this.httpService.Service({ + return this.httpService.service({ path: '/dayVisitCount', method: 'GET', }); } getLocalIp() { - return this.httpService.Service({ + return this.httpService.service({ path: '/ip', method: 'GET', }); } getIpLocation(ip: string) { - return this.httpService.Service({ + return this.httpService.service({ path: `/ip/${ip}`, method: 'GET', }); } visitorCount() { - return this.httpService.Service({ + return this.httpService.service({ 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>({ + return this.httpService.service>({ path: '/webUpdate/pages', method: 'GET', queryParam: { @@ -509,7 +509,7 @@ export class ApiService { } lastestUpdate() { - return this.httpService.Service<{ + return this.httpService.service<{ lastUpdateTime: string; lastUpdateInfo: string; lastCommit: string; @@ -523,7 +523,7 @@ export class ApiService { } createWebUpdateInfo(infoStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/webUpdate/create', method: 'POST', queryParam: {info: infoStr} @@ -531,14 +531,14 @@ export class ApiService { } deleteWebUpdateInfo(idNumber: number) { - return this.httpService.Service({ + return this.httpService.service({ path: `/admin/webUpdate/del/${idNumber}`, method: 'DELETE', }); } updateWebUpdateInfo(idNumber: number, infoStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/webUpdate/update', method: 'PUT', queryParam: {id: idNumber, info: infoStr} @@ -546,14 +546,14 @@ export class ApiService { } bingPic() { - return this.httpService.Service({ + return this.httpService.service({ path: '/bingPic', method: 'GET' }); } setPwd(pwdStr: string, newPwdStr: string, confirmPwdStr: string,) { - return this.httpService.Service({ + return this.httpService.service({ path: '/user/setPwd', method: 'POST', queryParam: { diff --git a/src/app/api/http/http.service.ts b/src/app/api/http/http.service.ts index 4d94bbc..1c1508a 100644 --- a/src/app/api/http/http.service.ts +++ b/src/app/api/http/http.service.ts @@ -20,12 +20,13 @@ export class HttpService { public getSubscriptionQueue = () => this.subscriptionQueue; - Service(request: RequestObj) { + service(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(); diff --git a/src/app/services/error.service.ts b/src/app/services/error.service.ts index 8616eeb..e2ebb79 100644 --- a/src/app/services/error.service.ts +++ b/src/app/services/error.service.ts @@ -11,9 +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'; + private static httpErrorCount: number = 0; + private readonly maintainPagePrefix = '/maintain'; + private readonly adminPagePrefix = '/admin'; constructor(/*private httpService: HttpService,*/ private router: Router, @@ -27,7 +27,7 @@ export class ErrorService { if (!environment.production) { console.log('error=>', err, request); } - ErrorService.HTTP_ERROR_COUNT++; + ErrorService.httpErrorCount++; // this.httpService.getSubscriptionQueue().map(a => a.unsubscribe()) } @@ -38,7 +38,7 @@ export class ErrorService { if (response.code === -1 && response.msg === '重复请求') { return; } - if (this.componentStateService.currentPath === this.ADMIN_PAGE_PREFIX) { + if (this.componentStateService.currentPath === this.adminPagePrefix) { this.notification.create('error', `请求失败<${response.code}>`, `${response.msg}`); } /*** @@ -59,7 +59,7 @@ 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', @@ -68,10 +68,10 @@ export class ErrorService { 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; } }); } diff --git a/src/app/utils/color.ts b/src/app/utils/color.ts index fdcb973..862eb55 100644 --- a/src/app/utils/color.ts +++ b/src/app/utils/color.ts @@ -3,7 +3,7 @@ export class Color { fontColor: string; } -export const ColorList: Color[] = [ +export const COLOR_LIST: Color[] = [ {bgColor: '#7bcfa6', fontColor: '#000000'}, // 石青 {bgColor: '#bce672', fontColor: '#000000'}, // 松花色 {bgColor: '#ff8936', fontColor: '#000000'}, // 橘黄 @@ -13,16 +13,16 @@ 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(); - 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())); @@ -30,7 +30,7 @@ export function RandomColor(count: number = 1): Color[] { 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()); diff --git a/src/app/view/admin/admin.component.ts b/src/app/view/admin/admin.component.ts index ebd3274..f183ab3 100644 --- a/src/app/view/admin/admin.component.ts +++ b/src/app/view/admin/admin.component.ts @@ -71,6 +71,7 @@ export class AdminComponent implements OnInit { const newPwd = this.resetPwdFormGroup && this.resetPwdFormGroup.value.newPwd; return control.value !== newPwd ? {pwdNotSame: true} : null; }; + // eslint-disable-next-line @typescript-eslint/naming-convention uploadHeader = (file: NzUploadFile): any | Observable<{}> => ({Authorization: this.localStorageService.getToken()}); showEditInfoModal() { diff --git a/src/app/view/write/write.component.ts b/src/app/view/write/write.component.ts index 6380c8a..8c02a70 100644 --- a/src/app/view/write/write.component.ts +++ b/src/app/view/write/write.component.ts @@ -243,6 +243,7 @@ export class WriteComponent implements OnInit, OnDestroy { .forEach(value => result.data.errFiles.push(value.originalFilename)); return JSON.stringify(result); }, + // eslint-disable-next-line @typescript-eslint/naming-convention setHeaders: () => ({Authorization: this.localStorageService.getToken()}) }, after: () => { -- 2.49.1 From 7f4e4568e5fedf1b636df382018c8d1b9eb1ac0a 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 17:38:19 +0800 Subject: [PATCH 7/9] style: update eslint of ban-types --- .eslintrc.json | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 66ed365..1a3db7b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,17 +21,26 @@ "plugin:@angular-eslint/template/process-inline-templates" ], "rules": { -// "@typescript-eslint/naming-convention": [ -// "off" -// ], + // "@typescript-eslint/naming-convention": [ + // "off" + // ], "prefer-arrow/prefer-arrow-functions": [ "off" ], -// "@typescript-eslint/member-ordering": [svn -// "on" -// ], + // "@typescript-eslint/member-ordering": [svn + // "on" + // ], "@typescript-eslint/ban-types": [ - "off" + "error", + { + "types": { + "Object": { + "message": "Use {} instead", + "fixWith": "{}" + }, + "{}": false + } + } ], "@angular-eslint/component-selector": [ "off", -- 2.49.1 From 03cf88868e0e03896dc15ea8d8d227f2d7a1905e 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 17:40:09 +0800 Subject: [PATCH 8/9] chore: Clean up eslint configuration files --- .eslintrc.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 1a3db7b..dc91860 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,15 +21,9 @@ "plugin:@angular-eslint/template/process-inline-templates" ], "rules": { - // "@typescript-eslint/naming-convention": [ - // "off" - // ], "prefer-arrow/prefer-arrow-functions": [ "off" ], - // "@typescript-eslint/member-ordering": [svn - // "on" - // ], "@typescript-eslint/ban-types": [ "error", { -- 2.49.1 From 754193d6abd45a028e3d6996a72e8dc253224908 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 17:55:00 +0800 Subject: [PATCH 9/9] chore: fix bug --- .../admin/components/common-table/common-table.component.ts | 2 +- src/app/view/index/components/tag-tag/tag-tag.component.ts | 6 +++--- src/app/view/link/link.component.ts | 4 ++-- .../write/components/publish-form/publish-form.component.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) 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 4845bc6..02837ad 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 @@ -72,7 +72,7 @@ export class CommonTableComponent implements OnInit, OnChanges { // count: countValue // } this.pageInfo.emit({page: pageValue, pageSize: countValue}); - return this.httpService.Service>(this.request).subscribe({ + return this.httpService.service>(this.request).subscribe({ next: resp => { this.dataList = resp.result; setTimeout(() => this.loading = false, 10); diff --git a/src/app/view/index/components/tag-tag/tag-tag.component.ts b/src/app/view/index/components/tag-tag/tag-tag.component.ts index fe87d25..a14cac3 100644 --- a/src/app/view/index/components/tag-tag/tag-tag.component.ts +++ b/src/app/view/index/components/tag-tag/tag-tag.component.ts @@ -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({ @@ -20,8 +20,8 @@ export class TagTagComponent implements OnInit { } 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; } diff --git a/src/app/view/link/link.component.ts b/src/app/view/link/link.component.ts index 30698e4..cccc21d 100644 --- a/src/app/view/link/link.component.ts +++ b/src/app/view/link/link.component.ts @@ -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://'], diff --git a/src/app/view/write/components/publish-form/publish-form.component.ts b/src/app/view/write/components/publish-form/publish-form.component.ts index 210f101..7d52343 100644 --- a/src/app/view/write/components/publish-form/publish-form.component.ts +++ b/src/app/view/write/components/publish-form/publish-form.component.ts @@ -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', @@ -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({ -- 2.49.1