[webapp] 批量处理eslint格式告警

This commit is contained in:
tomsun28
2021-12-23 15:59:49 +08:00
parent a22548a06d
commit e846de5b20
72 changed files with 1724 additions and 2170 deletions

View File

@@ -1,15 +1,13 @@
import { NgModule, Optional, SkipSelf } from '@angular/core';
import { throwIfAlreadyLoaded } from './module-import-guard';
import { I18NService } from './i18n/i18n.service';
import { throwIfAlreadyLoaded } from './module-import-guard';
@NgModule({
providers: [
I18NService
]
providers: [I18NService]
})
export class CoreModule {
constructor( @Optional() @SkipSelf() parentModule: CoreModule) {
constructor(@Optional() @SkipSelf() parentModule: CoreModule) {
throwIfAlreadyLoaded(parentModule, 'CoreModule');
}
}

View File

@@ -1,24 +1,24 @@
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from "@angular/router";
import {Observable} from "rxjs";
import {Injectable} from "@angular/core";
import {LocalStorageService} from "../../service/local-storage.service";
import {NzNotificationService} from "ng-zorro-antd/notification";
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
import { NzNotificationService } from 'ng-zorro-antd/notification';
import { Observable } from 'rxjs';
import { LocalStorageService } from '../../service/local-storage.service';
@Injectable({
providedIn: 'root'
})
export class DetectAuthGuard implements CanActivate {
constructor(private localStorageSvc: LocalStorageService, private notifySvc: NzNotificationService, private router: Router) {}
constructor(private localStorageSvc : LocalStorageService,
private notifySvc: NzNotificationService,
private router: Router) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
let activate = this.localStorageSvc.hasAuthorizationToken();
if (!activate) {
setTimeout(() => {
this.notifySvc.warning('请先登陆!','')
this.notifySvc.warning('请先登陆!', '');
this.router.navigateByUrl('/passport/login');
});
}

View File

@@ -1,10 +1,10 @@
// 请参考https://ng-alain.com/docs/i18n
import {Platform} from '@angular/cdk/platform';
import {registerLocaleData} from '@angular/common';
import { Platform } from '@angular/cdk/platform';
import { registerLocaleData } from '@angular/common';
import ngEn from '@angular/common/locales/en';
import ngZh from '@angular/common/locales/zh';
import ngZhTw from '@angular/common/locales/zh-Hant';
import {Injectable} from '@angular/core';
import { Injectable } from '@angular/core';
import {
_HttpClient,
AlainI18nBaseService,
@@ -14,13 +14,14 @@ import {
zh_CN as delonZhCn,
zh_TW as delonZhTw
} from '@delon/theme';
import {AlainConfigService} from '@delon/util/config';
import {enUS as dfEn, zhCN as dfZhCn, zhTW as dfZhTw} from 'date-fns/locale';
import {NzSafeAny} from 'ng-zorro-antd/core/types';
import {en_US as zorroEnUS, NzI18nService, zh_CN as zorroZhCN, zh_TW as zorroZhTW} from 'ng-zorro-antd/i18n';
import {Observable, zip} from 'rxjs';
import {map} from "rxjs/operators";
import {Message} from "../../pojo/Message";
import { AlainConfigService } from '@delon/util/config';
import { enUS as dfEn, zhCN as dfZhCn, zhTW as dfZhTw } from 'date-fns/locale';
import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { en_US as zorroEnUS, NzI18nService, zh_CN as zorroZhCN, zh_TW as zorroZhTW } from 'ng-zorro-antd/i18n';
import { Observable, zip } from 'rxjs';
import { map } from 'rxjs/operators';
import { Message } from '../../pojo/Message';
interface LangConfigData {
abbr: string;
@@ -94,16 +95,15 @@ export class I18NService extends AlainI18nBaseService {
}
loadLangData(lang: string): Observable<NzSafeAny> {
return zip(this.http.get(`http://localhost:4200/assets/tmp/i18n/${lang}.json`),this.http.get(`/i18n/${lang}`))
.pipe(
map(([langLocalData, langRemoteData]: [Record<string, string>, Message<any>]) => {
let remote:Record<string, string> = langRemoteData.data;
Object.keys(remote).forEach(key => {
langLocalData[key] = remote[key];
});
return langLocalData;
})
)
return zip(this.http.get(`./assets/i18n/${lang}.json`), this.http.get(`/i18n/${lang}`)).pipe(
map(([langLocalData, langRemoteData]: [Record<string, string>, Message<any>]) => {
let remote: Record<string, string> = langRemoteData.data;
Object.keys(remote).forEach(key => {
langLocalData[key] = remote[key];
});
return langLocalData;
})
);
}
use(lang: string, data: Record<string, unknown>): void {

View File

@@ -4,7 +4,8 @@ import {
HttpHandler,
HttpHeaders,
HttpInterceptor,
HttpRequest, HttpResponse,
HttpRequest,
HttpResponse,
HttpResponseBase
} from '@angular/common/http';
import { Injectable, Injector } from '@angular/core';
@@ -14,7 +15,8 @@ import { environment } from '@env/environment';
import { NzNotificationService } from 'ng-zorro-antd/notification';
import { BehaviorSubject, Observable, of, throwError } from 'rxjs';
import { catchError, filter, mergeMap, switchMap, take } from 'rxjs/operators';
import {LocalStorageService} from "../../service/local-storage.service";
import { LocalStorageService } from '../../service/local-storage.service';
const CODE_MESSAGE: { [key: number]: string } = {
200: '服务器成功返回请求的数据。',
@@ -44,7 +46,7 @@ export class DefaultInterceptor implements HttpInterceptor {
private refreshToking = false;
private refreshToken$: BehaviorSubject<any> = new BehaviorSubject<any>(null);
constructor(private injector: Injector, private storageSvc: LocalStorageService) { }
constructor(private injector: Injector, private storageSvc: LocalStorageService) {}
private get notification(): NzNotificationService {
return this.injector.get(NzNotificationService);
@@ -71,8 +73,7 @@ export class DefaultInterceptor implements HttpInterceptor {
*/
private refreshTokenRequest(): Observable<any> {
const refreshToken = this.storageSvc.getRefreshToken();
return this.http.post(`/account/auth/refresh`, null, null,
{ headers: { Authorization: `Bearer ${refreshToken}` }});
return this.http.post(`/account/auth/refresh`, null, null, { headers: { Authorization: `Bearer ${refreshToken}` } });
}
// #region 刷新Token方式一使用 401 重新刷新 Token
@@ -124,12 +125,11 @@ export class DefaultInterceptor implements HttpInterceptor {
let token = this.storageSvc.getAuthorizationToken();
return req.clone({
setHeaders: {
'Authorization': `Bearer ${token}`
Authorization: `Bearer ${token}`
}
});
}
private toLogin(): void {
this.notification.error(`未登录或登录已过期,请重新登录。`, ``);
this.goTo('/passport/login');
@@ -150,14 +150,13 @@ export class DefaultInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
let url = req.url;
if (!url.startsWith('https://') && !url.startsWith('http://')) {
if (!url.startsWith('https://') && !url.startsWith('http://') && !url.startsWith('.')) {
const { baseUrl } = environment.api;
url = baseUrl + (baseUrl.endsWith('/') && url.startsWith('/') ? url.substring(1) : url);
}
const newReq = req.clone({ url, setHeaders: this.fillHeaders(req.headers) });
return next.handle(newReq).pipe(
mergeMap(httpEvent => {
if (httpEvent instanceof HttpResponseBase) {
// todo 处理成功状态响应
@@ -192,7 +191,7 @@ export class DefaultInterceptor implements HttpInterceptor {
break;
}
this.checkStatus(err);
console.warn(`${err.status} == ${err.message}`)
console.warn(`${err.status} == ${err.message}`);
return throwError(err);
})
);

View File

@@ -1,17 +1,17 @@
import { HttpClient } from '@angular/common/http';
import { Injectable, Inject } from '@angular/core';
import { Router } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import { ACLService } from '@delon/acl';
import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
import { ALAIN_I18N_TOKEN, MenuService, SettingsService, TitleService } from '@delon/theme';
import { ACLService } from '@delon/acl';
import { I18NService } from '../i18n/i18n.service';
import { Observable, zip, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import type { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzIconService } from 'ng-zorro-antd/icon';
import { Observable, zip, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { ICONS } from '../../../style-icons';
import { ICONS_AUTO } from '../../../style-icons-auto';
import { I18NService } from '../i18n/i18n.service';
/**
* Used for application startup
* Generally used to get the basic data of the application, like: Menu Data, User Data, etc.
@@ -32,45 +32,31 @@ export class StartupService {
iconSrv.addIcon(...ICONS_AUTO, ...ICONS);
}
private viaHttp(): Observable<void> {
const defaultLang = this.i18n.defaultLang;
return zip(this.i18n.loadLangData(defaultLang), this.httpClient.get('http://localhost:4200/assets/tmp/app-data.json')).pipe(
catchError((res: NzSafeAny) => {
console.warn(`StartupService.load: Network request failed`, res);
setTimeout(() => this.router.navigateByUrl(`/exception/500`));
return [];
}),
map(([langData, appData]: [Record<string, string>, NzSafeAny]) => {
// setting language data
this.i18n.use(defaultLang, langData);
// Application data
// Application information: including site name, description, year
this.settingService.setApp(appData.app);
// User information: including name, avatar, email address
// this.settingService.setUser(appData.user);
// ACL: Set the permissions to full, https://ng-alain.com/acl/getting-started
this.aclService.setFull(true);
// Menu data, https://ng-alain.com/theme/menu
this.menuService.add(appData.menu);
// Can be set page suffix title, https://ng-alain.com/theme/title
this.titleService.suffix = appData.app.name;
})
);
}
private viaMockI18n(): Observable<void> {
private viaHttp(): Observable<void> {
const defaultLang = this.i18n.defaultLang;
return this.i18n.loadLangData(defaultLang).pipe(
map((langData: NzSafeAny) => {
this.i18n.use(defaultLang, langData);
return zip(this.i18n.loadLangData(defaultLang), this.httpClient.get('./assets/app-data.json')).pipe(
catchError((res: NzSafeAny) => {
console.warn(`StartupService.load: Network request failed`, res);
setTimeout(() => this.router.navigateByUrl(`/exception/500`));
return [];
}),
map(([langData, appData]: [Record<string, string>, NzSafeAny]) => {
// setting language data
this.i18n.use(defaultLang, langData);
this.viaMock();
})
);
// Application data
// Application information: including site name, description, year
this.settingService.setApp(appData.app);
// User information: including name, avatar, email address
// this.settingService.setUser(appData.user);
// ACL: Set the permissions to full, https://ng-alain.com/acl/getting-started
this.aclService.setFull(true);
// Menu data, https://ng-alain.com/theme/menu
this.menuService.add(appData.menu);
// Can be set page suffix title, https://ng-alain.com/theme/title
this.titleService.suffix = appData.app.name;
})
);
}
private viaMock(): Observable<void> {