register.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view class="register">
  3. <view class="vheight"></view>
  4. <view class="register_head">
  5. <text>注册账号</text>
  6. <text>请使用手机号注册账号</text>
  7. </view>
  8. <view class="register_ul">
  9. <view class="register_li flex">
  10. <view class="register_ipt"><input type="number" v-model="form.mobile" maxlength="11" placeholder="请输入手机号" placeholder-style="color:#999999" /></view>
  11. </view>
  12. <view class="register_li flex">
  13. <view class="register_ipt"><input type="number" v-model="form.captcha" maxlength="11" placeholder="请输入验证码" placeholder-style="color:#999999" /></view>
  14. <view class="code center" @click="getCode">{{ codeTxt }}</view>
  15. </view>
  16. <view class="register_li flex">
  17. <view class="register_ipt">
  18. <input type="password" v-model="form.password" maxlength="12" placeholder="设置密码:(8-12位数字和字母)" placeholder-style="color:#999999" />
  19. </view>
  20. </view>
  21. <view class="register_li flex">
  22. <view class="register_ipt"><input type="password" v-model="passwordValid" maxlength="12" placeholder="请再次输入密码" placeholder-style="color:#999999" /></view>
  23. </view>
  24. <view class="register_li flex">
  25. <view class="register_ipt"><input type="text" v-model="form.sharecode" placeholder="请输入邀请码(选填)" placeholder-style="color:#999999" /></view>
  26. </view>
  27. </view>
  28. <button class="register_btn" hover-class="hover-view" @click="submit">注册并登录</button>
  29. <view class="register_consent center">
  30. <!-- <image src="/static/logo.png" mode=""></image> -->
  31. <text>登录即表明同意</text>
  32. <text class="blue">《用户协议》</text>
  33. <text>和</text>
  34. <text class="blue">《隐私政策》</text>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import $DB from '../../http/debounce.js';
  40. export default {
  41. data() {
  42. return {
  43. form: {
  44. mobile: '',
  45. password: null,
  46. captcha: null,
  47. sharecode: uni.getStorageSync('sharecode')
  48. },
  49. passwordValid: null,
  50. sending: true,
  51. second: 60,
  52. disabled: false,
  53. flag: true,
  54. codeTxt: '获取验证码'
  55. };
  56. },
  57. created() {
  58. console.log(this.form);
  59. },
  60. methods: {
  61. submit() {
  62. if (!this.form.mobile.match(/^(0|86|17951)?1[3456789]\d{9}$/)) {
  63. uni.showToast({
  64. title: '请输入正确的手机号',
  65. icon: 'none'
  66. });
  67. return;
  68. }
  69. if (!this.form.captcha) return uni.showToast({ title: '请输入验证码', icon: 'none' });
  70. if (this.form.password != this.passwordValid) return uni.showToast({ title: '两次密码输入不一致', icon: 'none' });
  71. if (!this.flag) return;
  72. this.flag = false;
  73. this.$api.register({ ...this.form, msg: '提交中' }).then(res => {
  74. if (res.data.registerurl) {
  75. //存在跳转链接
  76. location.href = res.data.registerurl;
  77. return;
  78. }
  79. if (res.code === 1) {
  80. uni.setStorageSync('token', res.data.token);
  81. uni.setStorageSync('is_notice', res.data.is_notice);
  82. uni.removeStorageSync('is_channel');
  83. uni.switchTab({ url: '/pages/tabbar/index' });
  84. } else {
  85. this.flag = true;
  86. }
  87. });
  88. },
  89. //获取验证码
  90. getCode: $DB(function() {
  91. if (!this.sending) return;
  92. if (!this.form.mobile.match(/^(0|86|17951)?1[3456789]\d{9}$/)) {
  93. uni.showToast({
  94. title: '请输入正确的手机号',
  95. icon: 'none'
  96. });
  97. return;
  98. }
  99. this.$api.send({ mobile: this.form.mobile, msg: '发送中', event: 'register' }).then(res => {
  100. this.sending = false;
  101. this.disabled = true;
  102. if (res.code === 1) {
  103. this.timeDown();
  104. }
  105. uni.showToast({
  106. title: res.msg,
  107. icon: 'none'
  108. });
  109. });
  110. }),
  111. timeDown() {
  112. let result = setInterval(() => {
  113. --this.second;
  114. this.codeTxt = this.second + 'S';
  115. if (this.second < 0) {
  116. clearInterval(result);
  117. this.sending = true;
  118. this.disabled = false;
  119. this.second = 60;
  120. this.codeTxt = '获取验证码';
  121. }
  122. }, 1000);
  123. }
  124. }
  125. };
  126. </script>
  127. <style lang="scss">
  128. page {
  129. background: #ffffff;
  130. }
  131. .vheight {
  132. height: var(--status-bar-height);
  133. width: 100%;
  134. }
  135. .register {
  136. min-height: 100vh;
  137. padding: 0 42rpx;
  138. position: relative;
  139. .register_head {
  140. display: flex;
  141. flex-direction: column;
  142. padding: 30rpx 0 40rpx 0;
  143. text {
  144. &:first-child {
  145. font-size: 40rpx;
  146. font-weight: bold;
  147. }
  148. &:last-child {
  149. color: #999999;
  150. font-size: 26rpx;
  151. margin-top: 20rpx;
  152. }
  153. }
  154. }
  155. .register_li {
  156. padding: 40rpx 0;
  157. border-bottom: 2rpx solid #dddddd;
  158. .register_ipt {
  159. flex: 1;
  160. input {
  161. width: 100%;
  162. font-size: 30rpx;
  163. }
  164. }
  165. .code {
  166. width: 150rpx;
  167. color: #4eabfc;
  168. font-size: 28rpx;
  169. }
  170. }
  171. }
  172. .register_btn {
  173. height: 80rpx;
  174. margin-top: 50rpx;
  175. background-image: linear-gradient(45deg, #89f7fe, #7c66ff);
  176. border-radius: 40rpx;
  177. }
  178. .register_consent {
  179. width: 100%;
  180. position: absolute;
  181. left: 50%;
  182. bottom: 70rpx;
  183. transform: translateX(-50%);
  184. image {
  185. width: 30rpx;
  186. height: 30rpx;
  187. flex-shrink: 0;
  188. margin-right: 10rpx;
  189. }
  190. .blue {
  191. color: #4eabfc;
  192. }
  193. }
  194. </style>