import { Component } from '@angular/core'; import { AlertController } from '@ionic/angular'; @Component({ selector: 'app-tab3', templateUrl: 'tab3.page.html', styleUrls: ['tab3.page.scss'], standalone: false, }) export class Tab3Page { isLoggedIn: boolean = false; isDarkMode: boolean = false; constructor(private alertController: AlertController) {} // 登录函数 async login() { const alert = await this.alertController.create({ header: '登录', inputs: [ { name: 'username', type: 'text', placeholder: '账号' }, { name: 'password', type: 'password', placeholder: '密码' } ], buttons: [ { text: '取消', role: 'cancel' }, { text: '登录', handler: () => { this.isLoggedIn = true; return false; // 防止弹窗自动关闭 } } ] }); await alert.present(); } // 登出函数 logout() { this.isLoggedIn = false; } // 切换主题 toggleTheme() { this.isDarkMode = !this.isDarkMode; // 保存主题偏好到本地存储 localStorage.setItem('theme', this.isDarkMode ? 'dark' : 'light'); } // 初始化主题(如果之前有设置过) ngOnInit() { const savedTheme = localStorage.getItem('theme'); if (savedTheme === 'dark') { this.isDarkMode = true; } } }