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