register.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // pages/register/register.js
  2. import { $wuxCountDown, $wuxForm } from '../../miniprogram_npm/wux-weapp/index'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. layout: 'horizontal',
  9. validateMessages: {
  10. required: '%s 字段为必填',
  11. },
  12. registerMessage:{
  13. phone:'',
  14. }
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad(options) {
  20. },
  21. /**
  22. * 生命周期函数--监听页面初次渲染完成
  23. */
  24. onReady() {
  25. },
  26. /**
  27. * 生命周期函数--监听页面显示
  28. */
  29. onShow() {
  30. },
  31. /**
  32. * 页面方法集合
  33. */
  34. //表单栏位值发生变化时
  35. onValuesChange(e) {
  36. console.log(e)
  37. const { changedValues, allValues } = e.detail
  38. // this.setValues(changedValues)
  39. Object.keys(changedValues).forEach((field) => {
  40. this.setData({
  41. ['loginMessage['+field+']']: changedValues[field],
  42. })
  43. })
  44. console.log('onValuesChange \n', changedValues, allValues)
  45. },
  46. //发送验证码
  47. onSendCode(){
  48. if (this.c2 && this.c2.interval) return !1
  49. this.c2 = new $wuxCountDown({
  50. date: +new Date() + 60000,
  51. onEnd() {
  52. this.setData({
  53. c2: '重新获取验证码',
  54. })
  55. },
  56. render(date) {
  57. const sec = this.leadingZeros(date.sec, 2) + ' 秒 '
  58. date.sec !== 0 &&
  59. this.setData({
  60. c2: sec,
  61. })
  62. },
  63. })
  64. wx.showModal({
  65. content: `【WuxUI】验证码:123456,有效期5分钟,请勿泄露。`,
  66. showCancel: !1,
  67. })
  68. },
  69. //手机号校验
  70. checkPhone(rule, value){
  71. if(!value){
  72. return Promise.reject(new Error('手机号不能为空!'))
  73. }
  74. const isTel = (value) => /^1[34578]\d{9}$/.test(value)
  75. if(!isTel(value)){
  76. return Promise.reject(new Error('手机号输入错误!'))
  77. }
  78. },
  79. //注册
  80. onSubmit(){
  81. const { validateFields } = $wuxForm()
  82. validateFields((err, values) => {
  83. if (!err) {
  84. wx.showModal({
  85. content: JSON.stringify(values, null, 2),
  86. showCancel: !1,
  87. })
  88. console.log('Received values of form: ', values);
  89. }
  90. })
  91. },
  92. /**
  93. * 生命周期函数--监听页面隐藏
  94. */
  95. onHide() {
  96. },
  97. /**
  98. * 生命周期函数--监听页面卸载
  99. */
  100. onUnload() {
  101. },
  102. /**
  103. * 页面相关事件处理函数--监听用户下拉动作
  104. */
  105. onPullDownRefresh() {
  106. },
  107. /**
  108. * 页面上拉触底事件的处理函数
  109. */
  110. onReachBottom() {
  111. },
  112. /**
  113. * 用户点击右上角分享
  114. */
  115. onShareAppMessage() {
  116. }
  117. })