login.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // pages/login/login.js
  2. let log = require('../../utils/log.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. loginName: null,
  9. password: null,
  10. checkPass: false,
  11. errorMsg: '',
  12. passwordFocus:false
  13. },
  14. onError(e) {
  15. wx.showModal({
  16. title: '温馨提示',
  17. content: '当前网络环境较差,无法连接服务器,请稍后重试。有问题请联系客服电话18211188302,接听时段08:00-17:00。',
  18. showCancel: false
  19. });
  20. },
  21. inputAccount(e) {
  22. this.setData({
  23. loginName: e.detail.value
  24. });
  25. //console.log(e);
  26. if (this.data.loginName && this.data.password) {
  27. this.setData({
  28. checkPass: true
  29. });
  30. } else {
  31. this.setData({
  32. checkPass: false
  33. });
  34. }
  35. },
  36. inputPassword(e) {
  37. this.setData({
  38. password: e.detail.value
  39. });
  40. //console.log(e);
  41. if (this.data.loginName && this.data.password) {
  42. this.setData({
  43. checkPass: true
  44. });
  45. } else {
  46. this.setData({
  47. checkPass: false
  48. });
  49. }
  50. },
  51. loginUser(e) {
  52. let that = this;
  53. let { loginName, password } = this.data;
  54. log.info('[登录]', '[登录]', '[请求]', { loginName, password });
  55. wx.request({
  56. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/login',
  57. data: {
  58. loginName,
  59. password
  60. },
  61. method: 'POST',
  62. success(res) {
  63. //console.log(res1);
  64. //console.log(res1.data.code == 1);
  65. log.info('[登录]', '[登录]', '[响应]', res.data);
  66. if (res.data.code == 1) {
  67. that.setData({
  68. password: null,
  69. passwordFocus:true//,
  70. //errorMsg: res.data.msg
  71. });
  72. wx.showModal({
  73. title: '提示',
  74. content:res.data.msg,
  75. showCancel:false,
  76. confirmColor:'#4359b5'
  77. });
  78. log.info('[登录]', '[登录]', '[失败code==1]', res.data);
  79. } else {
  80. //返回该用户
  81. //跳转到上一页
  82. wx.setStorageSync("userInfo", res.data);
  83. wx.setStorageSync("isLogin", true);
  84. //let url = `/pages/ucenter/index/index`;
  85. log.info('[登录]', '[登录]', '[成功返回上一个界面]', res.data);
  86. wx.navigateBack();
  87. //wx.redirectTo({
  88. // url
  89. //});
  90. }
  91. },
  92. fail(e){
  93. getApp().showNetworkError();
  94. }
  95. });
  96. },
  97. goToRegister(e) {
  98. console.log(e);
  99. let url = '/pages/register/register';
  100. wx.redirectTo({
  101. url
  102. })
  103. },
  104. goToForget(e){
  105. console.log(e);
  106. let url = '/pages/forget/forget';
  107. wx.redirectTo({
  108. url
  109. })
  110. },
  111. /**
  112. * 生命周期函数--监听页面加载
  113. */
  114. onLoad: function (options) {
  115. log.info('[登录]', '[加载完成]');
  116. },
  117. /**
  118. * 生命周期函数--监听页面初次渲染完成
  119. */
  120. onReady: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面显示
  124. */
  125. onShow: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面隐藏
  129. */
  130. onHide: function () {
  131. },
  132. /**
  133. * 生命周期函数--监听页面卸载
  134. */
  135. onUnload: function () {
  136. },
  137. /**
  138. * 页面相关事件处理函数--监听用户下拉动作
  139. */
  140. onPullDownRefresh: function () {
  141. },
  142. /**
  143. * 页面上拉触底事件的处理函数
  144. */
  145. onReachBottom: function () {
  146. },
  147. /**
  148. * 用户点击右上角分享
  149. */
  150. onShareAppMessage: function () {
  151. }
  152. })