diff --git a/ui/angular.json b/ui/angular.json index d29b1249..e01a9f7f 100644 --- a/ui/angular.json +++ b/ui/angular.json @@ -82,11 +82,11 @@ ], "styles": [ { - "input": "bootstrap/dist/css/bootstrap.css", + "input": "node_modules/bootstrap/dist/css/bootstrap.css", "bundleName": "bootstrap" }, { - "input": "bootstrap-icons/font/bootstrap-icons.css", + "input": "node_modules/bootstrap-icons/font/bootstrap-icons.css", "bundleName": "icons" }, { @@ -96,7 +96,7 @@ ], "scripts": [ { - "input": "bootstrap/dist/js/bootstrap.bundle.js", + "input": "node_modules/bootstrap/dist/js/bootstrap.bundle.js", "bundleName": "bootstrap" } ], diff --git a/ui/package-lock.json b/ui/package-lock.json index b4b742ae..404166c4 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -22,7 +22,7 @@ "bootstrap-icons": "^1.11.3", "express": "^4.18.2", "ng-zorro-antd": "^18.0.0", - "plate-commons": "latest", + "plate-commons": "^0.0.3", "rxjs": "~7.8.0", "tslib": "^2.3.0" }, @@ -12649,9 +12649,9 @@ } }, "node_modules/plate-commons": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/plate-commons/-/plate-commons-0.0.1.tgz", - "integrity": "sha512-iM39DHeQ5J0XqgMyCJ5FP4nATtRHF1sWggeK7MFprdSidO9KEdGLfeSRrF37GwjnC1MPVZ+SqHDDNhEe/1q5DQ==", + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/plate-commons/-/plate-commons-0.0.3.tgz", + "integrity": "sha512-0xYjBbz3jBM5oUQIU/y4yCWmY+aW2F+E8z/50Sa0AUzp66/8MKGnxojBc0YkfiMMQdZtALxt2oXM7pfqogN0qA==", "license": "Apache-2.0", "dependencies": { "tslib": "^2.3.0" diff --git a/ui/package.json b/ui/package.json index 6281663b..5f16a89e 100644 --- a/ui/package.json +++ b/ui/package.json @@ -26,7 +26,7 @@ "bootstrap-icons": "^1.11.3", "express": "^4.18.2", "ng-zorro-antd": "^18.0.0", - "plate-commons": "latest", + "plate-commons": "^0.0.3", "rxjs": "~7.8.0", "tslib": "^2.3.0" }, diff --git a/ui/projects/web/src/app/app.component.ts b/ui/projects/web/src/app/app.component.ts index d0e105d8..2e07d01e 100644 --- a/ui/projects/web/src/app/app.component.ts +++ b/ui/projects/web/src/app/app.component.ts @@ -4,7 +4,7 @@ import {AsyncPipe} from '@angular/common'; import {NzBackTopModule} from 'ng-zorro-antd/back-top'; import {NzSpinModule} from 'ng-zorro-antd/spin'; import {debounceTime, distinctUntilChanged, tap} from 'rxjs'; -import {LoadingService} from './loading.service'; +import {LoadingService} from '../core/loading.service'; import {toSignal} from '@angular/core/rxjs-interop'; @Component({ diff --git a/ui/projects/web/src/app/app.config.ts b/ui/projects/web/src/app/app.config.ts index 6ff671f6..ff491099 100644 --- a/ui/projects/web/src/app/app.config.ts +++ b/ui/projects/web/src/app/app.config.ts @@ -12,8 +12,8 @@ import { withXsrfConfiguration, } from '@angular/common/http'; import {BrowserStorageServerService, BrowserStorageService,} from 'plate-commons'; -import {authTokenInterceptor, defaultInterceptor} from './http.Interceptor'; -import {PageTitleStrategy} from './title-strategy.service'; +import {authTokenInterceptor, defaultInterceptor} from '../core/http.Interceptor'; +import {PageTitleStrategy} from '../core/title-strategy.service'; import {routes} from './app.routes'; export const ngZorroConfig: NzConfig = { diff --git a/ui/projects/web/src/app/app.routes.ts b/ui/projects/web/src/app/app.routes.ts index 36cd82ae..a2a446f8 100644 --- a/ui/projects/web/src/app/app.routes.ts +++ b/ui/projects/web/src/app/app.routes.ts @@ -1,5 +1,5 @@ import {Routes} from '@angular/router'; -import {NotFoundComponent} from './not-found.component'; +import {NotFoundComponent} from '../core/not-found.component'; export const routes: Routes = [ { diff --git a/ui/projects/web/src/app/http.Interceptor.ts b/ui/projects/web/src/app/http.Interceptor.ts deleted file mode 100644 index 5ed97291..00000000 --- a/ui/projects/web/src/app/http.Interceptor.ts +++ /dev/null @@ -1,86 +0,0 @@ -import {inject} from '@angular/core'; -import {HttpEvent, HttpHandlerFn, HttpRequest} from '@angular/common/http'; -import {catchError, finalize, Observable, throwError, timeout} from 'rxjs'; -import {AuthService} from '../core/auth.service'; -import {LoadingService} from './loading.service'; -import {MessageService} from '../shared/message.service'; -import {Router} from '@angular/router'; -import {environment} from '../../environments/environment'; - -export function defaultInterceptor( - req: HttpRequest, - next: HttpHandlerFn -): Observable> { - const _loading = inject(LoadingService); - const _message = inject(MessageService); - - _loading.show(); - if (req.url.indexOf('assets/') > -1) { - return next(req); - } - const originalUrl = - req.url.indexOf('http') > -1 ? req.url : environment.host + req.url; - const xRequestedReq = req.clone({ - headers: req.headers.append('X-Requested-With', 'XMLHttpRequest'), - url: originalUrl, - }); - return next(xRequestedReq).pipe( - timeout({first: 5_000, each: 10_000}), - catchError(errorResponse => { - if (errorResponse.error.message) { - _message.error(errorResponse.error.message); - return throwError(() => errorResponse.error.message); - } - console.error($localize`:@@errorMessage:Backend returned code ${errorResponse.status}, - body was: ${errorResponse.message}`); - return throwError(() => errorResponse); - }), - finalize(() => _loading.hide()) - ); -} - -export function authTokenInterceptor( - req: HttpRequest, - next: HttpHandlerFn -): Observable> { - const _auth = inject(AuthService); - const _route = inject(Router); - - if (!_auth.isLoggedIn) { - return next(req); - } - - const authReq = req.clone({ - headers: req.headers.set('Authorization', `Bearer ${_auth.authToken()}`), - }); - - return next(authReq).pipe( - catchError(errorResponse => { - if (errorResponse.status === 401) { - _auth.logout(); - _route.navigate([_auth.loginUrl]).then(); - return throwError( - () => $localize`:@@errorMessage401:身份验证无效,请重新登录。` - ); - } else if (errorResponse.status === 407) { - _auth.logout(); - _route.navigate([_auth.loginUrl]).then(); - return throwError( - () => $localize`:@@errorMessage407:认证不正确,请重新登录。` - ); - } else if (errorResponse.status === 403) { - _auth.logout(); - _route.navigate([_auth.loginUrl]).then(); - return throwError( - () => $localize`:@@errorMessage403:验证码令牌错误,请重新登录。` - ); - } else { - console.error( - `Backend returned authToken code ${errorResponse.status}, body was: `, - errorResponse.error - ); - return throwError(() => errorResponse); - } - }) - ); -} diff --git a/ui/projects/web/src/app/loading.service.ts b/ui/projects/web/src/app/loading.service.ts deleted file mode 100644 index 5bf68233..00000000 --- a/ui/projects/web/src/app/loading.service.ts +++ /dev/null @@ -1,17 +0,0 @@ -import {Injectable} from '@angular/core'; -import {Observable, Subject} from 'rxjs'; - -@Injectable({providedIn: 'root'}) -export class LoadingService { - // Observable string sources - private progressSource: Subject = new Subject(); - progress$: Observable = this.progressSource.asObservable(); - - show(): void { - this.progressSource.next(true); - } - - hide(): void { - this.progressSource.next(false); - } -} diff --git a/ui/projects/web/src/app/not-found.component.ts b/ui/projects/web/src/app/not-found.component.ts deleted file mode 100644 index 165d987b..00000000 --- a/ui/projects/web/src/app/not-found.component.ts +++ /dev/null @@ -1,26 +0,0 @@ -import {Component} from '@angular/core'; -import {NzResultModule} from 'ng-zorro-antd/result'; - -@Component({ - selector: 'app-not-found', - standalone: true, - imports: [NzResultModule], - template: ` - -
- Back Home -
-
- `, - styles: ` - :host { - min-height: 100%; - min-width: 100%; - } - `, -}) -export class NotFoundComponent { -} diff --git a/ui/projects/web/src/app/title-strategy.service.ts b/ui/projects/web/src/app/title-strategy.service.ts deleted file mode 100644 index 5c2ef238..00000000 --- a/ui/projects/web/src/app/title-strategy.service.ts +++ /dev/null @@ -1,17 +0,0 @@ -import {RouterStateSnapshot, TitleStrategy} from '@angular/router'; -import {Title} from '@angular/platform-browser'; -import {Injectable} from '@angular/core'; - -@Injectable({providedIn: 'root'}) -export class PageTitleStrategy extends TitleStrategy { - constructor(private readonly title: Title) { - super(); - } - - override updateTitle(routerState: RouterStateSnapshot) { - const title = this.buildTitle(routerState); - if (title !== undefined) { - this.title.setTitle(`盘子管理平台 | ${title}`); - } - } -} diff --git a/ui/projects/web/src/core/login/login.service.ts b/ui/projects/web/src/core/login/login.service.ts index 860f08b9..ffb7a637 100644 --- a/ui/projects/web/src/core/login/login.service.ts +++ b/ui/projects/web/src/core/login/login.service.ts @@ -2,7 +2,7 @@ import {HttpClient, HttpHeaders} from '@angular/common/http'; import {Injectable} from '@angular/core'; import {Observable, tap, throwError} from 'rxjs'; import {AuthService} from '../../core/auth.service'; -import {BrowserStorageService} from 'commons'; +import {BrowserStorageService} from 'plate-commons'; export interface Authentication { token: string; diff --git a/ui/projects/web/src/core/security.module.ts b/ui/projects/web/src/core/security.module.ts index c805c678..e94c0877 100644 --- a/ui/projects/web/src/core/security.module.ts +++ b/ui/projects/web/src/core/security.module.ts @@ -1,6 +1,5 @@ import {NgModule, Optional, SkipSelf} from '@angular/core'; -import {BrowserStorageService} from 'commons'; - +import {BrowserStorageService} from 'plate-commons'; import {SecurityRoutingModule} from './security-routing.module'; @NgModule({