username_login.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // pages/username_login/username_login.js
  2. let log = require('../../../utils/log.js');
  3. let Util = require("../../../utils/util");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. loginName: null,
  10. password: null,
  11. checkPass: false,
  12. errorMsg: '',
  13. passwordFocus:false,
  14. servicetel: getApp().globalData.helpPhoneNum,
  15. queryip: ''
  16. },
  17. onError(e) {
  18. wx.showModal({
  19. title: '温馨提示',
  20. content: '当前网络环境较差,无法连接服务器,请稍后重试。有问题请联系客服电话4009608068,接听时段08:30-17:00。',
  21. showCancel: false,
  22. confirmColor:'#00AADD',
  23. });
  24. },
  25. inputAccount(e) {
  26. this.setData({
  27. loginName: e.detail.value
  28. });
  29. //console.log(e);
  30. if (this.data.loginName && this.data.password) {
  31. this.setData({
  32. checkPass: true
  33. });
  34. } else {
  35. this.setData({
  36. checkPass: false
  37. });
  38. }
  39. },
  40. inputPassword(e) {
  41. this.setData({
  42. password: e.detail.value
  43. });
  44. //console.log(e);
  45. if (this.data.loginName && this.data.password) {
  46. this.setData({
  47. checkPass: true
  48. });
  49. } else {
  50. this.setData({
  51. checkPass: false
  52. });
  53. }
  54. },
  55. loginUser(e) {
  56. let that = this;
  57. that.loginUserInner(e,that,that.data.queryip)
  58. },
  59. loginUserInner(e,that,ip) {
  60. console.info("fff")
  61. console.info(ip)
  62. let { loginName, password } = that.data;
  63. log.info('[登录]', '[登录]', '[请求]', { loginName, password });
  64. let ipp = ip;
  65. wx.login({
  66. success(loginRes) {
  67. wx.request({
  68. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/login',
  69. data: {
  70. loginName,
  71. // ip:ipp,
  72. password,
  73. code: loginRes.code
  74. },
  75. method: 'POST',
  76. success(res) {
  77. //console.log(res1);
  78. //console.log(res1.data.code == 1);
  79. log.info('[登录]', '[登录]', '[响应]', res.data);
  80. if (res.data.code == 1) {
  81. if(res.data.msg!=null && res.data.msg.startsWith("503")){
  82. getApp().showNetworkError();
  83. return;
  84. }
  85. that.setData({
  86. password: null,
  87. passwordFocus:true//,
  88. //errorMsg: res.data.msg
  89. });
  90. wx.showModal({
  91. title: '提示',
  92. content:res.data.msg,
  93. showCancel:false,
  94. confirmColor:'#00AADD',
  95. });
  96. log.info('[登录]', '[登录]', '[失败code==1]', res.data);
  97. } else {
  98. //返回该用户
  99. //跳转到上一页
  100. wx.setStorageSync("userInfo", res.data);
  101. wx.setStorageSync("isLogin", true);
  102. //let url = `/pages/ucenter/index/index`;
  103. log.info('[登录]', '[登录]', '[成功返回上一个界面]', res.data);
  104. wx.navigateBack();
  105. //wx.redirectTo({
  106. // url
  107. //});
  108. }
  109. },
  110. fail(e){
  111. getApp().showNetworkError();
  112. }
  113. });
  114. }
  115. });
  116. },
  117. phoneCall(){
  118. wx.makePhoneCall({
  119. phoneNumber: this.data.servicetel
  120. })
  121. },
  122. goToVcodeLogin(e){
  123. let url = '/pages/login/phone_login/phone_login';
  124. wx.redirectTo({
  125. url
  126. })
  127. },
  128. goToRegister(e) {
  129. console.log(e);
  130. let url = '/pages/register/register';
  131. wx.redirectTo({
  132. url
  133. })
  134. },
  135. goToForget(e){
  136. console.log(e);
  137. let url = '/pages/forget/forget';
  138. wx.redirectTo({
  139. url
  140. })
  141. },
  142. /**
  143. * 生命周期函数--监听页面加载
  144. */
  145. onLoad: function (options) {
  146. let that = this
  147. log.info('[登录]', '[加载完成]');
  148. wx.request({
  149. url: 'https://ipv4.icanhazip.com/',
  150. method: 'POST',
  151. success(rrr){
  152. console.info(rrr);
  153. var query = (rrr == null?'':rrr==null?'':rrr);
  154. var query = (rrr == null?'':rrr==null?'':rrr);
  155. let queryip = query.data==null? '':query.data.replace("\n","");
  156. that.setData({
  157. queryip
  158. })
  159. },
  160. fail(rrr){
  161. that.setData({
  162. queryip: ''
  163. })
  164. }
  165. })
  166. },
  167. /**
  168. * 生命周期函数--监听页面初次渲染完成
  169. */
  170. onReady: function () {
  171. },
  172. /**
  173. * 生命周期函数--监听页面显示
  174. */
  175. onShow: function () {
  176. },
  177. /**
  178. * 生命周期函数--监听页面隐藏
  179. */
  180. onHide: function () {
  181. },
  182. /**
  183. * 生命周期函数--监听页面卸载
  184. */
  185. onUnload: function () {
  186. },
  187. /**
  188. * 页面相关事件处理函数--监听用户下拉动作
  189. */
  190. onPullDownRefresh: function () {
  191. },
  192. /**
  193. * 页面上拉触底事件的处理函数
  194. */
  195. onReachBottom: function () {
  196. },
  197. /**
  198. * 用户点击右上角分享
  199. */
  200. onShareAppMessage: function () {
  201. }
  202. })