index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/login/login.js
  2. import * as methods from '../../utils/login'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: false, name: '登录页面', leftArrow: false, useBar: false },
  10. //判断协议是否选中
  11. agreement: false,
  12. //登录数据
  13. form: {},
  14. },
  15. // 验证字段的提示信息,若不传则调用默认的信息
  16. initValidate() {
  17. const rules = {
  18. phone: { required: true, tel: true },
  19. password: { required: true, },
  20. }
  21. const messages = {
  22. phone: { required: '请您输入电话号', },
  23. password: { required: '请您输入密码', },
  24. };
  25. this.WxValidate = new WxValidate(rules, messages)
  26. },
  27. //登录
  28. formSubmit: function (e) {
  29. const that = this;
  30. if (that.data.agreement) {
  31. wx.showToast({ title: `已同意使用协议`, icon: 'success', duration: 2000 })
  32. } else {
  33. wx.showToast({ title: `请同意使用协议`, icon: 'error', duration: 2000 })
  34. return false
  35. }
  36. let params = e.detail.value;
  37. if (!this.WxValidate.checkForm(params)) {
  38. const error = this.WxValidate.errorList[0];
  39. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  40. return false
  41. } else {
  42. wx.request({
  43. url: app.globalData.publicUrl + `/api/hc/user/login`,
  44. method: "post",
  45. data: params,
  46. header: {},
  47. success: (res) => {
  48. if (res.data.errcode == '0') {
  49. app.globalData.userInfo = res.data.data;
  50. wx.navigateTo({ url: `/pages/home/index` })
  51. } else {
  52. wx.showToast({ title: `${res.data.errmsg}`, icon: 'fail', duration: 2000 })
  53. }
  54. },
  55. fail: (res) => { },
  56. complete: (res) => { },
  57. })
  58. }
  59. },
  60. //微信登录
  61. wxlogin: function () {
  62. const that = this;
  63. // 曹悠男:o54og4xQGLGSuuBIbIprE9OEIjbo
  64. if (that.data.agreement) {
  65. wx.showToast({ title: `已同意使用协议`, icon: 'success', duration: 1000 })
  66. } else {
  67. wx.showToast({ title: `请同意使用协议`, icon: 'error', duration: 1000 })
  68. return false
  69. }
  70. let { openid } = app.globalData.wxInfo;
  71. if (openid) {
  72. wx.request({
  73. url: app.globalData.publicUrl + `/api/hc/user/login`,
  74. method: "post",
  75. data: { openid: openid },
  76. header: {},
  77. success: (res) => {
  78. if (res.data.errcode == '0') {
  79. app.globalData.userInfo = res.data.data;
  80. wx.navigateTo({ url: `/pages/home/index` })
  81. } else {
  82. wx.showModal({
  83. title: '信息提示',
  84. content: '当前微信未绑定系统,您是否需要完善资料?',
  85. success: (res) => {
  86. if (res.confirm) {
  87. wx.navigateTo({ url: `/pages/register/index` })
  88. } else if (res.cancel) {
  89. console.log('取消');
  90. }
  91. }
  92. })
  93. }
  94. },
  95. fail: (res) => { },
  96. complete: (res) => { },
  97. })
  98. }
  99. },
  100. //注册
  101. register: function () {
  102. const that = this;
  103. if (that.data.agreement) {
  104. wx.showToast({ title: `已同意使用协议`, icon: 'success', duration: 1000 })
  105. } else {
  106. wx.showToast({ title: `请同意使用协议`, icon: 'error', duration: 1000 })
  107. return false
  108. }
  109. wx.navigateTo({ url: '/pages/register/index', })
  110. },
  111. //忘记密码
  112. noopen: function () {
  113. wx.showToast({ title: `暂未开放`, icon: 'error', duration: 2000 })
  114. },
  115. //使用协议
  116. checkboxChange(e) {
  117. const that = this;
  118. let value = e.detail.value;
  119. if (value.length > 0) that.setData({ agreement: true })
  120. else that.setData({ agreement: false })
  121. },
  122. /**
  123. * 生命周期函数--监听页面加载
  124. */
  125. onLoad: function (options) {
  126. methods.toLogin()
  127. //验证规则函数
  128. this.initValidate()
  129. },
  130. /**
  131. * 生命周期函数--监听页面初次渲染完成
  132. */
  133. onReady: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面显示
  137. */
  138. onShow: function () {
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function () {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage: function () {
  164. }
  165. })