register.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="register-page">
  3. <navBar :name="$t('账号注册')" left="0" bgColor="transparent"></navBar>
  4. <view style="height: 20rpx;"></view>
  5. <ZxInput
  6. v-model="form.email"
  7. :placeholder="$t('请输入邮箱账号')"
  8. />
  9. <ZxInput
  10. v-model="form.passwd"
  11. :placeholder="$t('请输入密码')"
  12. isPassword
  13. />
  14. <ZxInput
  15. v-model="form.second_passwd"
  16. :placeholder="$t('请再次输入密码')"
  17. isPassword
  18. />
  19. <view
  20. v-if="Language == 'zh'"
  21. :class="['agreement-row', checkShakeObj.agreemen && 'shake']"
  22. @tap="isCheckAgreement = !isCheckAgreement"
  23. >
  24. <view :class="['checkbox', isCheckAgreement && 'is-checked']"/>
  25. {{ $t('已阅读并同意') }}
  26. <text class="text" @tap.stop="handleAgreementLink('270')">《{{$t('用户协议')}}》</text>
  27. {{ $t('和') }}<text class="text" @tap.stop="handleAgreementLink('102')">《{{$t('隐私政策')}}》</text>
  28. </view>
  29. <view :class="['zx-form-btn', isSubmt && 'is-submit']" @tap="submit">
  30. {{ $t('立即注册') }}
  31. </view>
  32. <NoticeDialog
  33. :title="$t('注册邮件已发送')"
  34. :btnText="$t('去登录')"
  35. type="register"
  36. @close='close'
  37. :email="form.email"
  38. :text="`${ $t('我们已向') } <span>${this.form.email}</span> ${ $t('发送注册邮件,请您登录邮箱点击链接完成注册。') }`"
  39. v-model="isSendSucceed"
  40. />
  41. </view>
  42. </template>
  43. <script>
  44. import { emailRegex } from '@/common/constant'
  45. import NoticeDialog from '@/component/comPopup/Notice.vue'
  46. import ZxInput from './components/ZxInput.vue'
  47. const config = require('@/common/config.js');
  48. const http = require('@/common/http.js');
  49. import {
  50. Language
  51. } from '@/utils/util.js'
  52. export default {
  53. components: {
  54. NoticeDialog,
  55. ZxInput
  56. },
  57. data() {
  58. return {
  59. Language:Language,
  60. isCheckAgreement: false,
  61. isSendSucceed: false,
  62. form: {},
  63. emailFocus: false,
  64. checkShakeObj: {
  65. agreemen: false
  66. }
  67. }
  68. },
  69. computed: {
  70. isSubmt({ form }) {
  71. return form.email && form.passwd && form.second_passwd
  72. }
  73. },
  74. methods: {
  75. close(){
  76. uni.navigateBack({
  77. delta:1
  78. })
  79. },
  80. handleAgreementLink(id) {
  81. uni.navigateTo({
  82. url: `/pages/contract/contract?contract_id=${id}`
  83. })
  84. },
  85. _applyCheck(field, message) {
  86. this.checkShakeObj[field] = true;
  87. setTimeout(() => {
  88. this.checkShakeObj[field] = false;
  89. }, 500)
  90. uni.showToast({ title: message, icon: 'none' })
  91. },
  92. validatePassword(password) {
  93. const regex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z0-9]{8,18}$/;
  94. return regex.test(password);
  95. },
  96. submit() {
  97. if (!this.isCheckAgreement && this.Language == 'zh') {
  98. this._applyCheck('agreemen', this.$t('请勾选用户协议和隐私政策'))
  99. return
  100. }
  101. if (!emailRegex.test(this.form.email)) {
  102. uni.showToast({ title: this.$t('请输入有效的邮箱地址'), icon: 'none' })
  103. return
  104. }
  105. if(!this.validatePassword(this.form.passwd) || !this.validatePassword(this.form.second_passwd)){
  106. uni.showToast({ title: this.$t('请输入')+'8-18'+this.$t('位密码,包含字母数字'), icon: 'none' })
  107. return
  108. }
  109. if (this.form.passwd !== this.form.second_passwd) {
  110. uni.showToast({ title: this.$t('两次输入的密码不一致'), icon: 'none' })
  111. return
  112. }
  113. http.postApi(config.API_REGISTER_EMAIL, {
  114. ...this.form
  115. }, res => {
  116. const { msg: title } = res.data
  117. if (res.succeed) {
  118. uni.showToast({ title:this.$t('注册邮件发送成功'), icon: 'none' })
  119. this.isSendSucceed = true
  120. } else {
  121. uni.showToast({ title, icon: 'none' })
  122. }
  123. })
  124. },
  125. }
  126. }
  127. </script>
  128. <style lang="scss" scoped>
  129. @import "@/libs/css/layout.scss";
  130. .register-page {
  131. width: 100%;
  132. background: #F1F3F4;
  133. min-height: 100vh;
  134. padding: 0 32rpx;
  135. .agreement-row {
  136. margin: 2rpx 0 64rpx;
  137. display: flex;
  138. align-items: center;
  139. font-family: PingFangSC, PingFang SC;
  140. font-weight: 400;
  141. font-size: 28rpx;
  142. color: #060809;
  143. &.shake {
  144. animation: shake 0.2s ease-in-out 0s 6;
  145. }
  146. .checkbox {
  147. width: 32rpx;
  148. height: 32rpx;
  149. margin-right: 16rpx;
  150. background: url('https://qiniu.bms16.com/Fh5aqDCxGKxEEVfxIQD9u6Ym9OLk');
  151. background-size: 100%;
  152. &.is-checked {
  153. background: url('https://qiniu.bms16.com/FhAi08ilxiBqUhFezVF9H9ff2VMm');
  154. background-size: 100%;
  155. }
  156. }
  157. .text {
  158. font-family: PingFangSC, PingFang SC;
  159. font-weight: 400;
  160. font-size: 28rpx;
  161. color: #0A59F7;
  162. &:active {
  163. opacity: .6;
  164. }
  165. }
  166. }
  167. }
  168. </style>