auth.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Component, OnInit, signal } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import { FormsModule, ReactiveFormsModule } from '@angular/forms';
  4. import { Router, RouterModule } from '@angular/router';
  5. @Component({
  6. selector: 'app-auth',
  7. standalone: true,
  8. imports: [CommonModule, FormsModule, ReactiveFormsModule, RouterModule],
  9. templateUrl: './auth.html',
  10. styleUrls: ['./auth.scss']
  11. })
  12. export class Auth implements OnInit {
  13. // 表单数据
  14. username = signal('');
  15. password = signal('');
  16. // 状态管理
  17. isLoading = signal(false);
  18. errorMessage = signal('');
  19. successMessage = signal('');
  20. ngOnInit() {
  21. // 初始化时可以添加一些动画效果
  22. }
  23. onSubmit() {
  24. this.isLoading.set(true);
  25. this.errorMessage.set('');
  26. this.successMessage.set('');
  27. // 模拟登录请求
  28. setTimeout(() => {
  29. if (this.username() === '1' && this.password() === '1') {
  30. this.successMessage.set('登录成功!');
  31. this.router.navigate(['/hrauth/hr']);
  32. // 这里实际项目中应该是导航到主页
  33. } else {
  34. this.errorMessage.set('企业凭证或密码错误,请重试');
  35. }
  36. this.isLoading.set(false);
  37. }, 1500);
  38. }
  39. constructor(private router: Router){}
  40. }