ogin-screen.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { Component, OnInit, OnDestroy } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import { FormsModule } from '@angular/forms';
  4. @Component({
  5. selector: 'app-ogin-screen',
  6. templateUrl: './ogin-screen.html',
  7. styleUrls: ['./ogin-screen.scss'],
  8. standalone: true,
  9. imports: [CommonModule, FormsModule]
  10. })
  11. export class OginScreenComponent implements OnInit, OnDestroy {
  12. activeTab: 'login' | 'register' = 'login';
  13. currentSlideIndex = 0;
  14. showSuccessMessage = false;
  15. messageType: 'login' | 'register' | null = null;
  16. // 表单模型
  17. loginForm = {
  18. email: '',
  19. password: '',
  20. remember: true
  21. };
  22. registerForm = {
  23. restaurantName: '',
  24. contactName: '',
  25. email: '',
  26. password: ''
  27. };
  28. // 轮播图图片
  29. slides = [
  30. 'https://images.unsplash.com/photo-1565299624946-b28f40a0ae38?ixlib=rb-4.0.3&auto=format&fit=crop&w=800&q=80',
  31. 'https://images.unsplash.com/photo-1513104890138-7c749659a591?ixlib=rb-4.0.3&auto=format&fit=crop&w=800&q=80',
  32. 'https://images.unsplash.com/photo-1506354666786-959d6d497f1a?ixlib=rb-4.0.3&auto=format&fit=crop&w=800&q=80',
  33. 'https://images.unsplash.com/photo-1476224203421-9ac39bcb3327?ixlib=rb-4.0.3&auto=format&fit=crop&w=800&q=80'
  34. ];
  35. private slideInterval: any;
  36. ngOnInit(): void {
  37. this.startSlideShow();
  38. }
  39. ngOnDestroy(): void {
  40. if (this.slideInterval) {
  41. clearInterval(this.slideInterval);
  42. }
  43. }
  44. startSlideShow(): void {
  45. this.slideInterval = setInterval(() => {
  46. this.currentSlideIndex = (this.currentSlideIndex + 1) % this.slides.length;
  47. }, 4000);
  48. }
  49. switchTab(tab: 'login' | 'register'): void {
  50. this.activeTab = tab;
  51. }
  52. onSubmitLogin(event: Event): void {
  53. event.preventDefault();
  54. this.showSuccess('login');
  55. }
  56. onSubmitRegister(event: Event): void {
  57. event.preventDefault();
  58. this.showSuccess('register');
  59. }
  60. showSuccess(type: 'login' | 'register'): void {
  61. this.messageType = type;
  62. this.showSuccessMessage = true;
  63. setTimeout(() => {
  64. this.showSuccessMessage = false;
  65. // 在实际应用中,这里会进行导航
  66. // this.router.navigate(['/dashboard']);
  67. }, 2000);
  68. }
  69. getSuccessMessage(): string {
  70. if (this.messageType === 'login') {
  71. return '登录成功!正在进入美食图库...';
  72. } else {
  73. return '注册成功!正在进入美食图库...';
  74. }
  75. }
  76. }