tab3.page.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Component } from '@angular/core';
  2. import { AlertController } from '@ionic/angular';
  3. @Component({
  4. selector: 'app-tab3',
  5. templateUrl: 'tab3.page.html',
  6. styleUrls: ['tab3.page.scss'],
  7. standalone: false,
  8. })
  9. export class Tab3Page {
  10. isLoggedIn: boolean = false;
  11. isDarkMode: boolean = false;
  12. constructor(private alertController: AlertController) {}
  13. // 登录函数
  14. async login() {
  15. const alert = await this.alertController.create({
  16. header: '登录',
  17. inputs: [
  18. { name: 'username', type: 'text', placeholder: '账号' },
  19. { name: 'password', type: 'password', placeholder: '密码' }
  20. ],
  21. buttons: [
  22. { text: '取消', role: 'cancel' },
  23. {
  24. text: '登录',
  25. handler: () => {
  26. this.isLoggedIn = true;
  27. return false; // 防止弹窗自动关闭
  28. }
  29. }
  30. ]
  31. });
  32. await alert.present();
  33. }
  34. // 登出函数
  35. logout() {
  36. this.isLoggedIn = false;
  37. }
  38. // 切换主题
  39. toggleTheme() {
  40. this.isDarkMode = !this.isDarkMode;
  41. // 保存主题偏好到本地存储
  42. localStorage.setItem('theme', this.isDarkMode ? 'dark' : 'light');
  43. }
  44. // 初始化主题(如果之前有设置过)
  45. ngOnInit() {
  46. const savedTheme = localStorage.getItem('theme');
  47. if (savedTheme === 'dark') {
  48. this.isDarkMode = true;
  49. }
  50. }
  51. }