Page({ data: { username: '', // 用户名 password: '', // 密码 errorMessage: '' // 错误信息 }, // 输入用户名 inputUsername: function (e) { this.setData({ username: e.detail.value }); }, // 输入密码 inputPassword: function (e) { this.setData({ password: e.detail.value }); }, // 登录逻辑 login: function () { const { username, password } = this.data; // 简单验证逻辑:用户名和密码为 "123" 时验证通过 if (!username || !password) { wx.showToast({ title: '用户名和密码不能为空', icon: 'none', duration: 2000 }); return; } wx.showLoading({ title: '登录中...' }); setTimeout(() => { if (username === '123' && password === '123') { wx.hideLoading(); wx.switchTab({ // 跳转到 tabBar 页面 url: '/pages/Calculate/Calculate' }); } else { wx.hideLoading(); this.setData({ errorMessage: '用户名或密码错误' }); wx.showToast({ title: '用户名或密码错误', icon: 'none', duration: 2000 }); } }, 1500); } });