register.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view class="bg-white height-vh">
  3. <view class="width100 flex-column-plus pad-32">
  4. <view class="flex-items mar-l-40 mar-t-20">
  5. <!-- <image class="logo" src="../../static/images/image5@3x.png" mode=""></image> -->
  6. </view>
  7. <view class=" mar-t-50 pad-32 radius-16">
  8. <view class="input-container">
  9. <input class="uni-input" v-model="user.email" placeholder="请输入邮箱" />
  10. <view class="clear-btn" @click="clearInput('email')" v-if="user.email">x</view>
  11. </view>
  12. <view class="input-container mar-t-16">
  13. <input class="uni-input" type="password" v-model="user.password" placeholder="请输入密码" />
  14. <view class="clear-btn" @click="clearInput('password')" v-if="user.password">x</view>
  15. </view>
  16. <view class="input-container mar-t-16">
  17. <input class="uni-input" type="password" v-model="user.repassword" placeholder="再次确认密码" />
  18. <view class="clear-btn" @click="clearInput('repassword')" v-if="user.repassword">x</view>
  19. </view>
  20. <view class="input-container mar-t-16 flex-row flex-items flex-sp-between input-code-container">
  21. <input class="uni-input input-code" v-model="user.code" placeholder="邮箱验证码" />
  22. <view class="clear-btn" @click="clearInput('code')" v-if="user.code">x</view>
  23. <button type="primary" size="mini" :plain="true" @click="getCode">{{ text }}</button>
  24. </view>
  25. <button class="mar-t-32 font32" style="background-color: #3C86F7;" type="primary" :loading="loading"
  26. @click="register">注册</button>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import {
  33. getCode,
  34. register
  35. } from '@/config/api.js';
  36. const seconds = 60 // 60秒倒计时
  37. export default {
  38. data() {
  39. return {
  40. user: {
  41. email: '',
  42. password: '',
  43. repassword: '',
  44. code: '',
  45. memberCode: '',
  46. payPwd: ''
  47. },
  48. loading: false,
  49. timer: null,
  50. seconds: seconds,
  51. status: false,
  52. text: ''
  53. }
  54. },
  55. onLoad() {
  56. this.text = "获取验证码"
  57. },
  58. onShow() {},
  59. onUnload() {
  60. this.timer && this.clearTimer();
  61. },
  62. methods: {
  63. async getCode() {
  64. if (this.status) return
  65. //校验验邮箱
  66. // console.log("jiaoyan", this.$utils.checkmail(this.user.email))
  67. // if (!this.$utils.checkmail(this.user.email)) {
  68. // return uni.$u.toast(this.$t('login').test_email)
  69. // }
  70. const res = await getCode({
  71. mail: this.user.email
  72. })
  73. if (res.code !== 200) return uni.$u.toast(res.msg)
  74. this.status = true
  75. this.countdown()
  76. this.timer = setInterval(() => {
  77. if (this.seconds === 0) {
  78. this.timer && this.clearTimer()
  79. this.status = false
  80. this.text = "获取验证码"
  81. this.seconds = seconds
  82. } else {
  83. this.countdown()
  84. }
  85. }, 1000)
  86. uni.$u.toast("验证码已发送")
  87. },
  88. countdown() {
  89. this.seconds--
  90. this.text = this.seconds + 's'
  91. },
  92. clearTimer() {
  93. console.log('注销定时器')
  94. clearInterval(this.timer)
  95. this.timer = null
  96. },
  97. register() {
  98. // 检查密码和长度
  99. // let reg = /^[a-zA-Z0-9]\w{5,14}$/
  100. // if (!reg.test(this.user.password)) return uni.$u.toast(this.$t('login').r_password)
  101. // // 检查确认密码
  102. // if (this.user.repassword !== this.user.password) return uni.$u.toast(this.$t('login').r_password_msg)
  103. // // 请输入验证码
  104. // if (!this.user.code || this.user.code.length !== 6) return uni.$u.toast(this.$t('login').code_len)
  105. // 请求注册
  106. register({
  107. mail: this.user.email,
  108. password: this.user.password,
  109. memberCode: this.user.memberCode,
  110. code: this.user.code,
  111. payPwd: this.user.payPwd
  112. }).then(res => {
  113. console.log(res)
  114. if (res.code === 400) return uni.$u.toast(res.msg)
  115. uni.showToast({
  116. title: "注册成功",
  117. duration: 2000,
  118. mask: true,
  119. complete: res => {
  120. this.$route('/pages/user/login');
  121. }
  122. });
  123. })
  124. },
  125. clearInput(field) {
  126. this.user[field] = '';
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss">
  132. page {
  133. background-color: white;
  134. }
  135. .logo {
  136. width: 170rpx;
  137. height: 47rpx;
  138. }
  139. .uni-input {
  140. height: 80rpx;
  141. line-height: 80rpx;
  142. border: none; // 去掉输入框边框
  143. outline: none; // 去掉输入框聚焦时的外边框
  144. flex: 1;
  145. padding: 0;
  146. }
  147. .input-container {
  148. display: flex;
  149. align-items: center;
  150. border-bottom: 1px solid #ccc; // 添加底部浅灰色线条
  151. padding-bottom: 5rpx;
  152. margin-bottom: 16rpx;
  153. }
  154. .input-code-container {
  155. display: flex;
  156. align-items: center;
  157. justify-content: space-between;
  158. box-sizing: border-box;
  159. }
  160. .input-code {
  161. margin-left: 0;
  162. box-sizing: border-box;
  163. }
  164. button {
  165. white-space: nowrap;
  166. margin-right: 10rpx;
  167. }
  168. .clear-btn {
  169. cursor: pointer;
  170. padding: 0 10rpx;
  171. color: #999;
  172. font-size: 30rpx;
  173. display: flex;
  174. align-items: center;
  175. justify-content: center;
  176. }
  177. .clear-btn:hover {
  178. color: #333;
  179. }
  180. </style>