register.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view class="login animated fadeInDown">
  3. <view class="dk" style="margin-top: 30px">
  4. <view class="bg">
  5. <text class="icon">&#xe8b9;</text>
  6. <input type="number" maxlength="11" v-model="item.phone" placeholder="请输入手机号" />
  7. </view>
  8. <view class="bg">
  9. <text class="icon">&#xe624;</text>
  10. <input type="number" v-model="item.smsCode" placeholder="验证码" />
  11. <view class="label" @click="getCode()">{{ msg }}</view>
  12. </view>
  13. <view class="bg">
  14. <text class="icon">&#xe8b2;</text>
  15. <input :password="show" v-model="item.password" placeholder="请输入密码" />
  16. <view class="label">
  17. <view class="icon" :class="{ active: !show }" @click="show = !show">&#xe7a6;</view>
  18. </view>
  19. </view>
  20. <view class="bg">
  21. <text class="icon">&#xe8b2;</text>
  22. <input :password="show" v-model="item.rePassword" placeholder="确认密码" />
  23. <view class="label">
  24. <view class="icon" :class="{ active: !show }" @click="show = !show">&#xe7a6;</view>
  25. </view>
  26. </view>
  27. <view class="xy">
  28. <u-checkbox-group class="checkbox" v-model="item.checked">
  29. <u-checkbox size="15" shape="circle" label="我已阅读并同意" labelSize="13" name="true"></u-checkbox>
  30. </u-checkbox-group>
  31. <text class="a" @click="go('/pages/login/userAgreement?id=1')">《用户协议》</text>
  32. <text>和</text>
  33. <text class="a" @click="go('/pages/login/userAgreement?id=2')">《隐私政策》</text>
  34. </view>
  35. <button class="btn" @click="submit()">确定</button>
  36. <button class="btn register" @click="back()">返回</button>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. show: true,
  45. time: 60,
  46. flag: true,
  47. msg: '获取验证码',
  48. item: {}
  49. };
  50. },
  51. onLoad(option) {
  52. this.item.type = option.type;
  53. },
  54. methods: {
  55. //发送短信验证码
  56. getCode() {
  57. if (!this.flag) {
  58. return;
  59. }
  60. let rule = [{ name: 'phone', checkType: 'notnull', errorMsg: '请输入正确的手机号' }];
  61. if (!this.verify.check(this.item, rule)) {
  62. uni.showModal({ content: this.verify.error, showCancel: false });
  63. return false;
  64. }
  65. this.http.request({
  66. url: '/sp-admin/app/AppUser/getPhoneSmsCode?phone=' + this.item.phone,
  67. success: res => {
  68. uni.showToast({ title: '发送成功' });
  69. //一分钟倒计时
  70. var countdown = setInterval(() => {
  71. this.time--;
  72. if (this.time == 0) {
  73. this.flag = true;
  74. this.msg = '获取短信';
  75. this.time = 60;
  76. clearInterval(countdown);
  77. } else {
  78. this.flag = false;
  79. this.msg = '重新获取(' + this.time + ')';
  80. }
  81. }, 1000);
  82. }
  83. });
  84. },
  85. submit() {
  86. let rule = [
  87. { name: 'phone', checkType: 'phone', errorMsg: '请输入正确的手机号码' },
  88. { name: 'smsCode', checkType: 'notnull', errorMsg: '请输入验证码' },
  89. { name: 'password', checkType: 'notnull', errorMsg: '请输入密码' },
  90. { name: 'rePassword', checkType: 'same', checkRule: this.item.password, errorMsg: '两次输入不一致' },
  91. { name: 'checked', checkType: 'notnull', errorMsg: '请同意并勾选协议' }
  92. ];
  93. if (!this.verify.check(this.item, rule)) {
  94. uni.showModal({ content: this.verify.error, showCancel: false });
  95. return false;
  96. }
  97. let item = JSON.parse(JSON.stringify(this.item));
  98. item.phone = this.util.encrypt(this.item.phone);
  99. item.password = this.util.encrypt(this.item.password);
  100. item.rePassword = this.util.encrypt(this.item.rePassword);
  101. this.http.request({
  102. url: '/sp-admin/app/AppUser/register',
  103. data: item,
  104. method: 'POST',
  105. success: resp => {
  106. uni.showToast({ title: '注册成功' });
  107. setTimeout(() => {
  108. uni.navigateTo({ url: '/pages/login/login' });
  109. }, 1000);
  110. }
  111. });
  112. },
  113. go(url) {
  114. uni.navigateTo({ url: url });
  115. },
  116. back() {
  117. uni.navigateBack();
  118. }
  119. }
  120. };
  121. </script>
  122. <style lang="scss"></style>