login.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // pages/login/login.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. loginName: null,
  8. password: null,
  9. checkPass: false,
  10. errorMsg: ''
  11. },
  12. inputAccount(e) {
  13. this.setData({
  14. loginName: e.detail.value
  15. });
  16. //console.log(e);
  17. if (this.data.loginName && this.data.password) {
  18. this.setData({
  19. checkPass: true
  20. });
  21. } else {
  22. this.setData({
  23. checkPass: false
  24. });
  25. }
  26. },
  27. inputPassword(e) {
  28. this.setData({
  29. password: e.detail.value
  30. });
  31. //console.log(e);
  32. if (this.data.loginName && this.data.password) {
  33. this.setData({
  34. checkPass: true
  35. });
  36. } else {
  37. this.setData({
  38. checkPass: false
  39. });
  40. }
  41. },
  42. loginUser(e) {
  43. let that = this;
  44. let { loginName, password } = this.data;
  45. wx.request({
  46. url: getApp().globalData.postHeadAgreement +'://cdgl.xinyhy.cn/restapi/wechat/login',
  47. data: {
  48. loginName,
  49. password
  50. },
  51. method: 'POST',
  52. success(res) {
  53. //console.log(res1);
  54. //console.log(res1.data.code == 1);
  55. if (res.data.code == 1) {
  56. that.setData({
  57. errorMsg: res.data.msg
  58. })
  59. } else {
  60. //返回该用户
  61. //跳转到上一页
  62. wx.setStorageSync("userInfo", res.data);
  63. wx.setStorageSync("isLogin", true);
  64. //let url = `/pages/ucenter/index/index`;
  65. wx.navigateBack();
  66. //wx.redirectTo({
  67. // url
  68. //});
  69. }
  70. }
  71. });
  72. },
  73. goToRegister(e) {
  74. console.log(e);
  75. let url = '/pages/register/register';
  76. wx.redirectTo({
  77. url
  78. })
  79. },
  80. goToForget(e){
  81. console.log(e);
  82. let url = '/pages/forget/forget';
  83. wx.redirectTo({
  84. url
  85. })
  86. },
  87. /**
  88. * 生命周期函数--监听页面加载
  89. */
  90. onLoad: function (options) {
  91. },
  92. /**
  93. * 生命周期函数--监听页面初次渲染完成
  94. */
  95. onReady: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面隐藏
  104. */
  105. onHide: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload: function () {
  111. },
  112. /**
  113. * 页面相关事件处理函数--监听用户下拉动作
  114. */
  115. onPullDownRefresh: function () {
  116. },
  117. /**
  118. * 页面上拉触底事件的处理函数
  119. */
  120. onReachBottom: function () {
  121. },
  122. /**
  123. * 用户点击右上角分享
  124. */
  125. onShareAppMessage: function () {
  126. }
  127. })