register.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. var api = require('../../../config/api.js');
  2. var app = getApp();
  3. Page({
  4. data: {
  5. username: '',
  6. password: '',
  7. confirmPassword: '',
  8. code: '',
  9. loginErrorCount: 0
  10. },
  11. onLoad: function (options) {
  12. // 页面初始化 options为页面跳转所带来的参数
  13. // 页面渲染完成
  14. },
  15. onReady: function () {
  16. },
  17. onShow: function () {
  18. // 页面显示
  19. },
  20. onHide: function () {
  21. // 页面隐藏
  22. },
  23. onUnload: function () {
  24. // 页面关闭
  25. },
  26. startRegister: function () {
  27. var that = this;
  28. if (that.data.password.length < 3 || that.data.username.length < 3) {
  29. wx.showModal({
  30. title: '错误信息',
  31. content: '用户名和密码不得少于3位',
  32. showCancel: false
  33. });
  34. return false;
  35. }
  36. if (that.data.password != that.data.confirmPassword) {
  37. wx.showModal({
  38. title: '错误信息',
  39. content: '确认密码不一致',
  40. showCancel: false
  41. });
  42. return false;
  43. }
  44. wx.request({
  45. url: api.ApiRootUrl + 'auth/register',
  46. data: {
  47. username: that.data.username,
  48. password: that.data.password
  49. },
  50. method: 'POST',
  51. header: {
  52. 'content-type': 'application/json'
  53. },
  54. success: function (res) {
  55. if (res.data.code == 200) {
  56. that.setData({
  57. 'loginErrorCount': 0
  58. });
  59. wx.setStorage({
  60. key: "token",
  61. data: res.data.data.token,
  62. success: function () {
  63. wx.switchTab({
  64. url: '/pages/ucenter/index/index'
  65. });
  66. }
  67. });
  68. }
  69. console.log(res.data.data.token)
  70. }
  71. });
  72. },
  73. bindUsernameInput: function (e) {
  74. this.setData({
  75. username: e.detail.value
  76. });
  77. },
  78. bindPasswordInput: function (e) {
  79. this.setData({
  80. password: e.detail.value
  81. });
  82. },
  83. bindConfirmPasswordInput: function (e) {
  84. this.setData({
  85. confirmPassword: e.detail.value
  86. });
  87. },
  88. bindCodeInput: function (e) {
  89. this.setData({
  90. code: e.detail.value
  91. });
  92. },
  93. clearInput: function (e) {
  94. switch (e.currentTarget.id) {
  95. case 'clear-username':
  96. this.setData({
  97. username: ''
  98. });
  99. break;
  100. case 'clear-password':
  101. this.setData({
  102. password: ''
  103. });
  104. break;
  105. case 'clear-confirm-password':
  106. this.setData({
  107. confirmPassword: ''
  108. });
  109. break;
  110. case 'clear-code':
  111. this.setData({
  112. code: ''
  113. });
  114. break;
  115. }
  116. }
  117. })