index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // pages/login/index.js
  2. import util from '../../utils/util'
  3. import http from '../../utils/http'
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. mobile: '',
  11. password: '',
  12. // mobile|wechat|forget
  13. type: 'mobile',
  14. title: '手机号登录',
  15. name: ''
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. },
  22. getUserInfo: function(e) {
  23. util.wechatLogin(e, redirect)
  24. },
  25. switchType: function(e) {
  26. var type = e.currentTarget.dataset.type
  27. var title = '手机号登录'
  28. if(type == 'wechat') {
  29. title = '微信授权登录'
  30. } else if(type == 'forget') {
  31. title = '忘记密码'
  32. }
  33. this.setData({
  34. title,
  35. type
  36. })
  37. },
  38. updateValue: function(e) {
  39. var name = e.currentTarget.dataset.name
  40. this.setData({
  41. [name]: e.detail
  42. })
  43. },
  44. login: function() {
  45. if(!util.checkMobile(this.data.mobile)) {
  46. util.error('手机号格式错误')
  47. return false;
  48. }
  49. if(!this.data.password) {
  50. util.error('密码必填')
  51. return false;
  52. }
  53. http({
  54. url: 'login',
  55. data: {
  56. phone: this.data.mobile,
  57. password: this.data.password
  58. },
  59. loadTitle: '登录中',
  60. success: function(res) {
  61. if(res.code == 0) {
  62. app.loginCallback(res.data)
  63. }
  64. }
  65. })
  66. },
  67. reset: function() {
  68. if(!util.checkMobile(this.data.mobile)) {
  69. util.error('手机号格式错误')
  70. return false;
  71. }
  72. if(!this.data.name) {
  73. util.error('真实姓名必填')
  74. return false;
  75. }
  76. http({
  77. url: 'reset',
  78. data: {
  79. phone: this.data.mobile,
  80. name: this.data.name
  81. },
  82. loadTitle: '提交中',
  83. success: function(res) {
  84. if(res.code == 0) {
  85. wx.showToast({
  86. title: '提交成功',
  87. })
  88. }
  89. }
  90. })
  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. })