Register.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Page({
  2. data: {
  3. userInfo: {
  4. username: '', // 用户名
  5. password: '', // 密码
  6. },
  7. },
  8. // 获取用户名输入
  9. inputUsername(e) {
  10. this.setData({
  11. 'userInfo.username': e.detail.value, // 更新用户名
  12. });
  13. },
  14. // 获取密码输入
  15. inputPassword(e) {
  16. this.setData({
  17. 'userInfo.password': e.detail.value, // 更新密码
  18. });
  19. },
  20. // 注册方法
  21. register() {
  22. const { username, password } = this.data.userInfo;
  23. // 检查用户名和密码是否为空
  24. if (!username || !password) {
  25. wx.showToast({
  26. title: '用户名和密码不能为空',
  27. icon: 'none',
  28. });
  29. return;
  30. }
  31. // 保存用户信息(用户名和密码)到缓存
  32. wx.setStorageSync('userInfo', this.data.userInfo);
  33. // 显示注册成功的提示
  34. wx.showToast({
  35. title: '注册成功',
  36. icon: 'success',
  37. });
  38. // 注册成功后跳转到登录页面
  39. wx.reLaunch({
  40. url: '/pages/admin/admin', // 登录页面路径
  41. });
  42. },
  43. });