business.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * 发送验证码
  3. * 验证码时间 _self.sendCodeTime
  4. * 是否在发送中 _self.isSendCodeUse true 发送中
  5. */
  6. function sendCode(data,callback){
  7. let _self = this
  8. if(!checkPhone(data.phone)){
  9. // uni.showToast({
  10. // title: "手机号格式不正确",
  11. // duration: 1500,
  12. // mask: false,
  13. // icon: 'none',
  14. // })
  15. return
  16. }
  17. if(_self.isSendCodeUse){return}
  18. //设置定时器 60s 内发送
  19. _self.isSendCodeUse = true
  20. let times = setInterval(function(){
  21. _self.sendCodeTime--
  22. if(_self.sendCodeTime<0){
  23. _self.isSendCodeUse = false
  24. _self.sendCodeTime = 60
  25. clearInterval(times)
  26. }
  27. },1000)
  28. // Load.open(_self)
  29. _self.request({
  30. url:"/Send/sendSmsCode",
  31. data,
  32. success(r){
  33. if(r.code==200){
  34. showToast({title:r.msg})
  35. if(callback){
  36. callback()
  37. }
  38. }
  39. }
  40. })
  41. }
  42. /*
  43. * 验证手机号
  44. */
  45. function checkPhone(phone){
  46. let reg=/^[1][3,4,5,6,7,8,9][0-9]{9}$/
  47. let _self = this
  48. if(!phone){
  49. uni.showToast({
  50. title: "手机号不能为空",
  51. duration: 1500,
  52. mask: false,
  53. icon: 'none',
  54. })
  55. return false
  56. }
  57. if (!reg.test(phone)) {
  58. uni.showToast({
  59. title: "手机号格式不正确",
  60. duration: 1500,
  61. mask: false,
  62. icon: 'none',
  63. })
  64. return false
  65. } else {
  66. return true
  67. }
  68. }
  69. function checkCode(code){
  70. let _self = this
  71. if(!code){
  72. _self.toast("验证码不能为空")
  73. return false
  74. }else{
  75. return true
  76. }
  77. }
  78. function checkInvite(invite){
  79. let _self = this
  80. if(!invite){
  81. _self.toast("请填写推荐码")
  82. return false
  83. }else{
  84. return true
  85. }
  86. }
  87. function checkPwd(pwd){
  88. let _self = this
  89. if(!pwd){
  90. _self.toast("密码不能为空")
  91. return false
  92. }
  93. if(pwd.length<6||pwd.length>20){
  94. _self.toast("密码长度不正确")
  95. return false
  96. }else{
  97. return true
  98. }
  99. }
  100. function showToast(config){
  101. config.duration = config.duration || 1500;
  102. uni.showToast({
  103. title: config.title,
  104. duration: config.duration,
  105. mask: config.mask||false,
  106. icon: config.icon||'none',
  107. success(){
  108. setTimeout(config.success||function(){},config.duration)
  109. }
  110. })
  111. }