Skip to content

Commit

Permalink
style:代码格式化及调整
Browse files Browse the repository at this point in the history
对多个文件进行了代码格式化,调整了代码的缩进、换行和注释样式,以提高代码的
可读性和一致性。此外,还优化了组件、服务和配置文件的结构和内容。
  • Loading branch information
vnobo committed Jun 25, 2024
1 parent bf17edd commit 91f0a47
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 196 deletions.
3 changes: 2 additions & 1 deletion ui/.prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"arrowParens": "avoid",
"trailingComma": "es5",
"bracketSameLine": true,
"printWidth": 80
"printWidth": 80,
"endOfLine": "auto"
}
10 changes: 10 additions & 0 deletions ui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
"zone.js/testing"
]
}
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"projects/commons/**/*.ts",
"projects/commons/**/*.html"
],
"eslintConfig": "projects/commons/eslint.config.js"
}
}
}
},
Expand Down
46 changes: 42 additions & 4 deletions ui/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
export default [
// @ts-check
const eslint = require('@eslint/js');
const tseslint = require('typescript-eslint');
const angular = require('angular-eslint');
const prettierRecommended = require('eslint-config-prettier');

module.exports = tseslint.config(
{
files: ['**/*.ts'],
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylistic,
...angular.configs.tsRecommended,
prettierRecommended,
],
processor: angular.processInlineTemplates,
rules: {
semi: 'error',
'prefer-const': 'error',
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'app',
style: 'camelCase',
},
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'app',
style: 'kebab-case',
},
],
},
},
];
{
files: ['**/*.html'],
extends: [
...angular.configs.templateRecommended,
...angular.configs.templateAccessibility,
prettierRecommended,
],
rules: {},
}
);
9 changes: 5 additions & 4 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"scripts": {
"ng": "ng",
"start": "ng lint --fix && ng serve",
"build": "ng build",
"build": "ng lint --fix && ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"serve:ssr:web": "node dist/web/server/server.mjs",
"lint": "ng lint"
"lint": "ng lint",
"serve:ssr:app": "node dist/app/server/server.mjs"
},
"private": true,
"dependencies": {
Expand All @@ -26,9 +27,9 @@
"bootstrap-icons": "^1.11.3",
"express": "^4.18.2",
"ng-zorro-antd": "^18.0.0",
"plate-commons": "latest",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"plate-commons": "latest"
"tslib": "^2.3.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^18.0.2",
Expand Down
2 changes: 1 addition & 1 deletion ui/projects/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"sideEffects": false,
"description": "plate dev commons",
"main": "index.js",
"main": "public-api.ts",
"scripts": {
"test": "ng test"
},
Expand Down
2 changes: 0 additions & 2 deletions ui/projects/commons/src/lib/commons.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ import {Injectable} from '@angular/core';
providedIn: 'root',
})
export class CommonsService {
constructor() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class BrowserStorageServerService extends BrowserStorageService {
constructor() {
super({
clear: () => {
console.log('clear');
},
getItem: (key: string) => btoa(JSON.stringify({key})),
setItem: (key: string, value: string) =>
Expand Down
4 changes: 1 addition & 3 deletions ui/projects/web/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ function run(): void {
// Start up the Node server
const server = app();
server.listen(port, () => {
console.log(
`Node Express server listening on http://localhost:${port}`
);
console.log(`Node Express server listening on http://localhost:${port}`);
});
}

Expand Down
4 changes: 1 addition & 3 deletions ui/projects/web/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ export const routes: Routes = [
{
path: 'auth',
loadChildren: () =>
import('../core/security/security.module').then(
m => m.SecurityModule
),
import('../core/security/security.module').then(m => m.SecurityModule),
},
{path: '', pathMatch: 'full', redirectTo: 'auth'},
{path: '**', component: PageNotFoundComponent},
Expand Down
2 changes: 1 addition & 1 deletion ui/projects/web/src/core/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class AuthService {
private authenticatedSource = new Subject<boolean>();
public readonly loginUrl = '/auth/login';
isLoggedIn = false;
private token: string = '';
private token = '';
authenticated$ = this.authenticatedSource.asObservable();

authToken(): string {
Expand Down
11 changes: 3 additions & 8 deletions ui/projects/web/src/core/http.Interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ export function authTokenInterceptor(
}

const authReq = req.clone({
headers: req.headers.set(
'Authorization',
`Bearer ${_auth.authToken()}`
),
headers: req.headers.set('Authorization', `Bearer ${_auth.authToken()}`),
});

return next(authReq).pipe(
Expand All @@ -63,8 +60,7 @@ export function authTokenInterceptor(
_auth.logout();
_route.navigate([_auth.loginUrl]).then();
return throwError(
() =>
$localize`:@@errorMessage401:身份验证无效,请重新登录。`
() => $localize`:@@errorMessage401:身份验证无效,请重新登录。`
);
} else if (errorResponse.status === 407) {
_auth.logout();
Expand All @@ -76,8 +72,7 @@ export function authTokenInterceptor(
_auth.logout();
_route.navigate([_auth.loginUrl]).then();
return throwError(
() =>
$localize`:@@errorMessage403:验证码令牌错误,请重新登录。`
() => $localize`:@@errorMessage403:验证码令牌错误,请重新登录。`
);
} else {
console.error(
Expand Down
65 changes: 21 additions & 44 deletions ui/projects/web/src/core/security/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,22 @@ <h5 class="text-center mb-4" i18n="@@app.login.subtitle">
<form
(ngSubmit)="onSubmit()"
[class.was-validated]="
loginForm.invalid &&
(loginForm.dirty || loginForm.touched)
"
loginForm.invalid && (loginForm.dirty || loginForm.touched)
"
[formGroup]="loginForm"
autocomplete="off">
<div class="container">
<div
class="input-group input-group-sm mb-3 has-validation">
<div class="input-group input-group-sm mb-3 has-validation">
<div class="input-group-text">
<i class="bi bi-person-fill"></i>
</div>
<input
[class.is-invalid]="
loginForm.controls.username.invalid &&
(loginForm.controls.username.dirty ||
loginForm.controls.username.touched)
"
[class.is-valid]="
loginForm.controls.username.valid
"
loginForm.controls.username.invalid &&
(loginForm.controls.username.dirty ||
loginForm.controls.username.touched)
"
[class.is-valid]="loginForm.controls.username.valid"
autocomplete="off"
class="form-control"
formControlName="username"
Expand All @@ -36,29 +32,22 @@ <h5 class="text-center mb-4" i18n="@@app.login.subtitle">
required
type="text"/>
<div
*ngIf="
loginForm.controls.username.errors?.[
'required'
]
"
*ngIf="loginForm.controls.username.errors?.['required']"
class="invalid-feedback">
请输入电子邮件或手机号。
</div>
</div>
<div
class="input-group input-group-sm mb-3 has-validation">
<div class="input-group input-group-sm mb-3 has-validation">
<div class="input-group-text">
<i class="bi bi-key-fill"></i>
</div>
<input
[class.is-invalid]="
loginForm.controls.password.invalid &&
(loginForm.controls.password.dirty ||
loginForm.controls.password.touched)
"
[class.is-valid]="
loginForm.controls.password.valid
"
loginForm.controls.password.invalid &&
(loginForm.controls.password.dirty ||
loginForm.controls.password.touched)
"
[class.is-valid]="loginForm.controls.password.valid"
autocomplete="off"
class="form-control"
formControlName="password"
Expand All @@ -68,23 +57,15 @@ <h5 class="text-center mb-4" i18n="@@app.login.subtitle">
type="password"/>
<div
*ngIf="
loginForm.controls.password.errors?.[
'minlength'
] ||
loginForm.controls.password.errors?.[
'maxlength'
]
"
loginForm.controls.password.errors?.['minlength'] ||
loginForm.controls.password.errors?.['maxlength']
"
class="invalid-feedback">
密码长度为8 ~
20个字符,由字母和数字组成,不能包含空格、特殊字符或表情符号。
</div>
<div
*ngIf="
loginForm.controls.password.errors?.[
'required'
]
"
*ngIf="loginForm.controls.password.errors?.['required']"
class="invalid-feedback">
请输入密码。
</div>
Expand All @@ -96,9 +77,7 @@ <h5 class="text-center mb-4" i18n="@@app.login.subtitle">
id="flexCheckRemember"
name="remember"
type="checkbox"/>
<label
class="form-check-label"
for="flexCheckRemember"
<label class="form-check-label" for="flexCheckRemember"
>记住密码</label
>
<a class="mt-1 float-end" href="./">忘记密码?</a>
Expand All @@ -122,9 +101,7 @@ <h5 class="text-center mb-4" i18n="@@app.login.subtitle">
><i class="bi bi-github" style="color: #3492ed"></i
></a>
<a class="mx-2" href="./" title="a"
><i
class="bi bi-sina-weibo"
style="color: #cf1900"></i
><i class="bi bi-sina-weibo" style="color: #cf1900"></i
></a>
<a href="./" title="a"
><i class="bi bi-wechat" style="color: #4daf29"></i
Expand Down
6 changes: 2 additions & 4 deletions ui/projects/web/src/core/security/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ export class LoginComponent implements OnInit, OnDestroy {
const login = this.loginSer.login(credentials);
const result = login.pipe(takeUntil(this.componentDestroyed$));
result.subscribe({
next: v => {
this.router
.navigate(['/home'], {relativeTo: this.route})
.then();
next: () => {
this.router.navigate(['/home'], {relativeTo: this.route}).then();
},
error: e => console.log(e),
});
Expand Down
2 changes: 1 addition & 1 deletion ui/projects/web/src/core/security/security.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {NgModule, Optional, SkipSelf} from '@angular/core';
import {BrowserStorageService} from '@plate/commons';
import {BrowserStorageService} from 'commons';

import {SecurityRoutingModule} from './security-routing.module';
import {LoginComponent} from './login/login.component';
Expand Down
23 changes: 5 additions & 18 deletions ui/projects/web/src/pages/home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
<nz-layout class="layout">
<nz-header
class="nz-header d-flex justify-content-between align-content-between">
<div class="logo mx-2">
<i class="bi bi-p-circle-fill mx-2"></i>PLATE
</div>
<ul
class="header-menu ms-auto"
nz-menu
nzMode="horizontal"
nzTheme="dark">
<div class="logo mx-2"><i class="bi bi-p-circle-fill mx-2"></i>PLATE</div>
<ul class="header-menu ms-auto" nz-menu nzMode="horizontal" nzTheme="dark">
<li nz-menu-item><a routerLink="/home">我的</a></li>
</ul>
</nz-header>
Expand All @@ -20,15 +14,10 @@
nzWidth="14.6rem">
<ul class="sider-menu" nz-menu nzMode="inline" nzTheme="dark">
<li nz-menu-item>
<i class="bi bi-p-circle-fill mx-2"></i
><a routerLink="/home">首页</a>
<i class="bi bi-p-circle-fill mx-2"></i><a routerLink="/home">首页</a>
</li>
@for (menu of menus$ | async; track menu) {
<li
nz-submenu
nzIcon="user"
nzOpen
nzTitle="{{ menu.name }}">
<li nz-submenu nzIcon="user" nzOpen nzTitle="{{ menu.name }}">
<ul>
@for (child of menu.children; track child) {
<li nz-menu-item>
Expand All @@ -50,9 +39,7 @@
nzOpen
nzTitle="{{ menu.name }}">
<ul>
<li
*ngFor="let child of menu.children; index as i"
nz-menu-item>
<li *ngFor="let child of menu.children; index as i" nz-menu-item>
<a
[state]="child"
routerLink=".{{ child.path }}"
Expand Down
Loading

0 comments on commit 91f0a47

Please sign in to comment.