index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. Page({
  2. data: {
  3. username: '', // 用户名
  4. password: '', // 密码
  5. errorMessage: '' // 错误信息
  6. },
  7. // 输入用户名
  8. inputUsername: function (e) {
  9. this.setData({
  10. username: e.detail.value
  11. });
  12. },
  13. // 输入密码
  14. inputPassword: function (e) {
  15. this.setData({
  16. password: e.detail.value
  17. });
  18. },
  19. // 登录逻辑
  20. login: function () {
  21. const { username, password } = this.data;
  22. // 简单验证逻辑:用户名和密码为 "123" 时验证通过
  23. if (!username || !password) {
  24. wx.showToast({
  25. title: '用户名和密码不能为空',
  26. icon: 'none',
  27. duration: 2000
  28. });
  29. return;
  30. }
  31. wx.showLoading({
  32. title: '登录中...'
  33. });
  34. setTimeout(() => {
  35. if (username === '123' && password === '123') {
  36. wx.hideLoading();
  37. wx.switchTab({ // 跳转到 tabBar 页面
  38. url: '/pages/Calculate/Calculate'
  39. });
  40. } else {
  41. wx.hideLoading();
  42. this.setData({
  43. errorMessage: '用户名或密码错误'
  44. });
  45. wx.showToast({
  46. title: '用户名或密码错误',
  47. icon: 'none',
  48. duration: 2000
  49. });
  50. }
  51. }, 1500);
  52. }
  53. });