Skip to content

Commit

Permalink
♻ refactor️(login): 优化登录页面布局和样式,增强代码可读性
Browse files Browse the repository at this point in the history
本次重构主要集中在登录页面的HTML和SCSS文件,调整了布局以达到更好的视觉效果,
同时清理了一些冗余的代码,提高了代码的可读性和可维护性。具体改动包括:
- 重新安排了社交登录和注册账号的按钮排布,使用更合理的grid布局。
- 为图标添加了title属性,提升了可访问性。
- 调整了登录卡片的宽度,提供了更好的填写表单体验。
- 在SCSS中修正了一些混合方法的使用,规整了样式定义。

此外,还更新了登录组件的typescript定义,增强了类型检查。登录逻辑及相关服务
未做调整,保持了功能的稳定性。
  • Loading branch information
vnobo committed Jun 12, 2024
1 parent aa9bf8b commit aeeeeab
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
1 change: 0 additions & 1 deletion ui/projects/web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<meta content="ie=edge" http-equiv="X-UA-Compatible"/>
<title>Loading page ....</title>
<base href="/">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link href="favicon.ico" rel="icon" type="image/x-icon">
</head>
<body>
Expand Down
14 changes: 7 additions & 7 deletions ui/projects/web/src/pages/security/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ <h5 class="text-center mb-4" i18n="@@app.login.subtitle">
</div>
</div>
</form>
<div class="row align-items-center justify-content-between mt-2 gy-2">
<div class="col col-sm-5"><span class="ms-3">社交账号登录</span></div>
<div class="col col-sm-4 align-items-start">
<a href="./"><i class="bi bi-github" style="color: #3492ed"></i></a>
<a class="mx-2" href="./"><i class="bi bi-sina-weibo" style="color: #cf1900"></i></a>
<a href="./"><i class="bi bi-wechat" style="color: #4daf29"></i></a>
<div class="row align-items-center mt-2">
<div class="col col-sm-4"><span class="me-auto">社交账号登录</span></div>
<div class="col col-sm-4 justify-content-around">
<a href="./" title="a"><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></a>
<a href="./" title="a"><i class="bi bi-wechat" style="color: #4daf29"></i></a>
</div>
<div class="col col-sm-3"><a class="ms-4" href="./">注册帐号</a></div>
<div class="col col-sm-4 text-end"><a class="me-2" href="./">注册帐号</a></div>
</div>
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions ui/projects/web/src/pages/security/login/login.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@

.page {
background-image: url(https://bing.biturl.top/?resolution=1920&format=image&index=0&mkt=zh-CN),
url('/assets/th.jpg'), linear-gradient(rgba(0, 0, 255, 0.5), rgba(255, 255, 0, 0.5));
url("/assets/th.jpg"),
linear-gradient(rgba(0, 0, 255, 0.5), rgba(255, 255, 0, 0.5));
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}

.card {
width: 25rem;
width: 28rem;
}

.bi {
font-size: 1.5rem;
margin-left: 0.1rem;
margin-right: 0.1rem;
}
51 changes: 28 additions & 23 deletions ui/projects/web/src/pages/security/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,69 @@
import {Component, OnDestroy, OnInit} from '@angular/core';
import {FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms";
import {Credentials, LoginService} from "./login.service";
import {ActivatedRoute, Router} from "@angular/router";
import {Subject, takeUntil} from "rxjs";
import {FormBuilder, FormControl, FormGroup, Validators,} from '@angular/forms';
import {Credentials, LoginService} from './login.service';
import {ActivatedRoute, Router} from '@angular/router';
import {Subject, takeUntil} from 'rxjs';

@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
styleUrls: ['./login.component.scss'],
})
export class LoginComponent implements OnInit, OnDestroy {

loginForm: FormGroup<{
username: FormControl<string | null>,
password: FormControl<string | null>,
rememberMe: FormControl<boolean | null>
username: FormControl<string | null>;
password: FormControl<string | null>;
rememberMe: FormControl<boolean | null>;
}>;

private _subject: Subject<void> = new Subject<void>();
private componentDestroyed$: Subject<void> = new Subject<void>();

constructor(private router: Router,
private route: ActivatedRoute,
private formBuilder: FormBuilder,
private loginService: LoginService) {
constructor(
private router: Router,
private route: ActivatedRoute,
private formBuilder: FormBuilder,
private loginService: LoginService
) {
this.loginForm = this.formBuilder.group({
username: new FormControl('', [
Validators.required,
Validators.minLength(5),
Validators.maxLength(64)
Validators.maxLength(64),
]),
password: new FormControl('', [
Validators.required,
Validators.minLength(6),
Validators.maxLength(64)
Validators.maxLength(64),
]),
rememberMe: new FormControl(false)
rememberMe: new FormControl(false),
});
}

onSubmit(): void {
const credentials: Credentials = {
username: this.loginForm.value.username,
password: this.loginForm.value.password
password: this.loginForm.value.password,
};

if (this.loginForm.value.rememberMe) {
this.loginService.rememberMe(credentials);
}
const login = this.loginService.login(credentials);
const result = login.pipe(takeUntil(this._subject));
result.subscribe(() => {
this.router.navigate(['/home'], {relativeTo: this.route}).then();
const result = login.pipe(takeUntil(this.componentDestroyed$));
result.subscribe({
next: (v) => {
console.log(v);
this.router.navigate(['/home'], {relativeTo: this.route}).then();
},
error: (e) => console.log(e),
});
}

ngOnInit(): void {
}

ngOnDestroy(): void {
this._subject.next();
this._subject.complete();
this.componentDestroyed$.next();
this.componentDestroyed$.complete();
}
}

0 comments on commit aeeeeab

Please sign in to comment.