login.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { Component } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import { FormsModule } from '@angular/forms';
  4. import { Router, RouterModule } from '@angular/router';
  5. @Component({
  6. selector: 'app-login',
  7. standalone: true,
  8. imports: [CommonModule, FormsModule, RouterModule],
  9. templateUrl: './login.html',
  10. styleUrls: ['./login.scss']
  11. })
  12. export class LoginPage {
  13. username = '';
  14. password = '';
  15. loading = false;
  16. error = '';
  17. currentYear = new Date().getFullYear();
  18. constructor(private router: Router) {}
  19. async signIn() {
  20. this.error = '';
  21. this.loading = true;
  22. try {
  23. // 这里保留为演示登录流程的占位,不破坏现有业务逻辑
  24. await new Promise(r => setTimeout(r, 400));
  25. // 登录成功后可跳转到常用角色,实际项目中可根据权限返回跳转
  26. await this.router.navigateByUrl('/customer-service/dashboard');
  27. } catch (e) {
  28. this.error = '登录失败,请重试';
  29. } finally {
  30. this.loading = false;
  31. }
  32. }
  33. goToRole(role: 'customer-service' | 'designer' | 'team-leader' | 'finance' | 'hr' | 'admin') {
  34. const map: Record<string, string> = {
  35. 'customer-service': '/customer-service/dashboard',
  36. 'designer': '/designer/dashboard',
  37. 'team-leader': '/team-leader/dashboard',
  38. 'finance': '/finance/dashboard',
  39. 'hr': '/hr/dashboard',
  40. 'admin': '/admin/dashboard'
  41. };
  42. // iOS 风格过渡动画(与项目内其他页面行为一致)
  43. document.body.classList.add('ios-page-transition');
  44. setTimeout(() => {
  45. this.router.navigateByUrl(map[role]).finally(() => {
  46. setTimeout(() => document.body.classList.remove('ios-page-transition'), 300);
  47. });
  48. }, 100);
  49. }
  50. }