index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. Page({
  2. data: {
  3. username: '',
  4. password: '',
  5. role: '' // 保存角色信息
  6. },
  7. // 页面加载时获取角色参数
  8. onLoad(options) {
  9. this.setData({
  10. role: options.role || '' // 默认角色为空
  11. });
  12. },
  13. // 更新输入框的值
  14. onInputChange(e) {
  15. const { field } = e.currentTarget.dataset;
  16. this.setData({ [field]: e.detail.value });
  17. },
  18. // 登录逻辑
  19. onLogin() {
  20. const { username, password, role } = this.data;
  21. if (!username || !password) {
  22. wx.showToast({
  23. title: '请输入用户名和密码',
  24. icon: 'none'
  25. });
  26. return;
  27. }
  28. wx.showLoading({ title: '登录中...' });
  29. setTimeout(() => {
  30. wx.hideLoading();
  31. // 模拟登录成功后跳转
  32. wx.setStorageSync('userRole', role); // 存储角色信息
  33. if (role === 'admin') {
  34. wx.redirectTo({ url: '/pages/admin/threshold/threshold' });
  35. } else {
  36. wx.redirectTo({ url: '/pages/Regular User/Home/Home' });
  37. }
  38. }, 1000);
  39. }
  40. });