Regular.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. Page({
  2. data: {
  3. name: '', // 用户名
  4. password: '', // 密码
  5. errorMessage: '', // 错误提示
  6. },
  7. // 输入用户名
  8. inputName: function (e) {
  9. this.setData({
  10. name: e.detail.value
  11. });
  12. },
  13. <<<<<<< HEAD:pages/b/b.js
  14. // 输入密码
  15. inputPassword: function (e) {
  16. =======
  17. // 取消登录弹窗
  18. potNo() {
  19. this.setData({
  20. isHidden: true
  21. });
  22. },
  23. // 确认登录弹窗
  24. popYes() {
  25. const { avatarUrl, nickName } = this.data;
  26. if (!avatarUrl || !nickName) {
  27. wx.showToast({
  28. icon: 'error',
  29. title: '请获取头像和昵称',
  30. });
  31. return;
  32. }
  33. this.setData({
  34. isLogin: true,
  35. isHidden: true,
  36. });
  37. // 登录成功后跳转到指定页面
  38. wx.switchTab({
  39. url: '/pages/Regular User/Home/Home',
  40. });
  41. },
  42. // 用户名密码登录
  43. inputUsername(e) {
  44. this.setData({
  45. username: e.detail.value
  46. });
  47. },
  48. inputPassword(e) {
  49. >>>>>>> origin/soligd:pages/Regular/Regular.js
  50. this.setData({
  51. password: e.detail.value
  52. });
  53. },
  54. // 注册逻辑
  55. register: function () {
  56. const { name, password } = this.data;
  57. // 检查用户名和密码是否为空
  58. if (!name || !password) {
  59. wx.showToast({
  60. title: '用户名和密码不能为空',
  61. icon: 'none',
  62. duration: 2000
  63. });
  64. return;
  65. }
  66. wx.showLoading({
  67. title: '注册中...'
  68. });
  69. setTimeout(() => {
  70. // 发送请求到后端,进行用户注册
  71. wx.request({
  72. url: 'https://soilgd.com:5000/register', // 后端注册接口
  73. method: 'POST',
  74. data: {
  75. name: name, // 修改为 name
  76. password: password,
  77. },
  78. success: (res) => {
  79. wx.hideLoading();
  80. if (res.data.success) {
  81. wx.showToast({
  82. title: '注册成功',
  83. icon: 'success',
  84. duration: 2000
  85. });
  86. // 清空输入框
  87. this.setData({
  88. name: '',
  89. password: '',
  90. errorMessage: ''
  91. });
  92. <<<<<<< HEAD:pages/b/b.js
  93. // 跳转到登录页面
  94. wx.switchTab({
  95. url: '/pages/Home/Home'
  96. });
  97. } else {
  98. wx.showToast({
  99. title: res.data.message || '注册失败',
  100. icon: 'none',
  101. duration: 2000
  102. });
  103. }
  104. },
  105. fail: (err) => {
  106. wx.hideLoading();
  107. wx.showToast({
  108. title: '网络错误,请重试',
  109. icon: 'none',
  110. duration: 2000
  111. });
  112. console.error('注册失败:', err);
  113. }
  114. });
  115. =======
  116. // 登录成功后跳转到指定页面
  117. wx.switchTab({
  118. url: '/pages/Regular User/Home/Home',
  119. });
  120. } else {
  121. this.setData({
  122. errorMessage: '用户名或密码错误'
  123. });
  124. wx.showToast({
  125. title: '用户名或密码错误',
  126. icon: 'none',
  127. duration: 2000
  128. });
  129. }
  130. >>>>>>> origin/soligd:pages/Regular/Regular.js
  131. }, 1500);
  132. },
  133. });