No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

register.js 2.9KB

hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // pages/register/register.js
  2. const app = getApp()
  3. let time;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. yesSend:false,//是否发送验证码
  10. minter: 60,//发送验证码60秒后才可再次发送
  11. num:60,
  12. phone: "",//手机号
  13. phoneCode: "",//验证码
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. },
  20. /**
  21. * 生命周期函数--监听页面初次渲染完成
  22. */
  23. onReady: function () {
  24. },
  25. /**
  26. * 生命周期函数--监听页面显示
  27. */
  28. onShow: function () {
  29. },
  30. /**
  31. * 生命周期函数--监听页面隐藏
  32. */
  33. onHide: function () {
  34. },
  35. /**
  36. * 生命周期函数--监听页面卸载
  37. */
  38. onUnload: function () {
  39. },
  40. /**
  41. * 页面相关事件处理函数--监听用户下拉动作
  42. */
  43. onPullDownRefresh: function () {
  44. },
  45. /**
  46. * 页面上拉触底事件的处理函数
  47. */
  48. onReachBottom: function () {
  49. },
  50. /**
  51. * 用户点击右上角分享
  52. */
  53. onShareAppMessage: function () {
  54. },
  55. sendTouch:function(){//发送验证码
  56. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  57. wx.showToast({
  58. title: '手机号错误',
  59. icon: 'none',
  60. duration: 500
  61. })
  62. return;
  63. }
  64. this.setData({
  65. yesSend: true,
  66. })
  67. if (this.data.yesSend) {
  68. time = setInterval(this.setIntervalFn,1000)
  69. }
  70. app.wxRequest(app.globalData.httpUrl + 'smscode', { user_phone:this.data.phone}, e => {
  71. console.log(e)
  72. if(e.code==200){
  73. wx.showToast({
  74. title: e.message,
  75. icon: 'success',
  76. duration: 500
  77. })
  78. }
  79. }, this)
  80. },
  81. setIntervalFn:function(){//定时器
  82. if (this.data.num > 0) {
  83. this.data.num--;
  84. if (this.data.num == 0) {
  85. this.setData({
  86. yesSend: false,
  87. })
  88. if (!this.data.yesSend){
  89. this.setData({
  90. num: 60,
  91. minter: 60,
  92. })
  93. }
  94. clearInterval(time);
  95. }
  96. }
  97. this.setData({
  98. minter: this.data.num
  99. })
  100. console.log(this.data.minter)
  101. },
  102. registerFn:function(){//注册
  103. app.wxRequest(app.globalData.httpUrl + 'register', { user_phone: this.data.phone, code_num: this.data.phoneCode }, e => {
  104. console.log(e)
  105. if (e.code == 200) {
  106. clearInterval(time);
  107. this.setData({
  108. minter: 60,
  109. num: 60
  110. })
  111. wx.showToast({
  112. title: '注册成功',
  113. icon: 'success',
  114. duration: 500
  115. })
  116. setTimeout(function () {
  117. wx.switchTab({
  118. url: '../index/index'
  119. })
  120. }, 1000)
  121. }
  122. }, this,"POST")
  123. },
  124. getPhone: function (e) {//获取手机号
  125. console.log(e.detail.value);
  126. this.setData({
  127. phone: e.detail.value
  128. })
  129. },
  130. getCode: function (e) {//获取验证码
  131. console.log(e.detail.value);
  132. this.setData({
  133. phoneCode: e.detail.value
  134. })
  135. },
  136. })