register.vue 5.4 KB

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