RegisterView.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div class="login">
  3. <img src="@/assets/png-denglu-bg.png" class="top-bg !absolute w-full h-[200px] top-0 left-0 !z-0" alt="" />
  4. <div class="login-content h-full">
  5. <div class="text-white text-[26px] AlimamaShuHeiTi">Hi,歡迎來到走馬短劇</div>
  6. <!-- 可以使用 CellGroup 作为容器 -->
  7. <van-form @submit="onSubmit">
  8. <van-cell-group :border="false">
  9. <van-field
  10. label-align="top"
  11. clearable
  12. v-model="form.email"
  13. :rules="[
  14. {
  15. required: true,
  16. pattern: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
  17. message: '请输入正确内容'
  18. }
  19. ]"
  20. :label="$t('login.email')"
  21. :placeholder="$t('login.emailPla')"
  22. >
  23. <template #left-icon>
  24. <img class="left-icon" src="@/assets/login_icon_zhanghao.png" alt="" />
  25. </template>
  26. <template #label>
  27. <div class="text-white text-[14px]">{{ $t('login.email') }}</div>
  28. </template>
  29. </van-field>
  30. <van-field
  31. label-align="top"
  32. clearable
  33. v-model="form.username"
  34. :label="$t('login.username')"
  35. :placeholder="$t('login.usernamePla')"
  36. :rules="[
  37. {
  38. required: true,
  39. message: $t('login.usernamePla')
  40. }
  41. ]"
  42. >
  43. <template #left-icon>
  44. <img class="left-icon" src="@/assets/login_icon_zhanghao.png" alt="" />
  45. </template>
  46. <template #label>
  47. <div class="text-white text-[14px]">{{ $t('login.username') }}</div>
  48. </template>
  49. </van-field>
  50. <van-field
  51. label-align="top"
  52. type="password"
  53. clearable
  54. v-model="form.password"
  55. :label="$t('login.password')"
  56. :placeholder="$t('login.passwordPla')"
  57. :rules="[
  58. {
  59. required: true,
  60. message: $t('login.passwordPla')
  61. }
  62. ]"
  63. >
  64. <template #left-icon>
  65. <img class="left-icon" src="@/assets/login_icon_mima.png" alt="" />
  66. </template>
  67. <template #label>
  68. <div class="text-white text-[14px]">{{ $t('login.password') }}</div>
  69. </template>
  70. </van-field>
  71. <van-field
  72. label-align="top"
  73. type="password"
  74. clearable
  75. v-model="form.password2"
  76. label="密碼"
  77. :placeholder="$t('login.password2Pla')"
  78. :rules="[
  79. {
  80. validator,
  81. message: '两次密码输入不一致'
  82. }
  83. ]"
  84. >
  85. <template #left-icon>
  86. <img class="left-icon" src="@/assets/login_icon_mima.png" alt="" />
  87. </template>
  88. <template #label>
  89. <div class="text-white text-[14px]">{{ $t('login.password2') }}</div>
  90. </template>
  91. </van-field>
  92. <!-- <div @click="loginCode = !loginCode" class="text-[#61657A] text-right text-xs underline pt-[10px]">
  93. {{ loginCode ? '密碼登录' : '验证码登录' }}
  94. </div> -->
  95. <div class="btn py-[64px] px-[17px]">
  96. <van-button type="primary" class="AlimamaShuHeiTi" block round native-type="submit"
  97. >注册</van-button
  98. >
  99. <div class="text-[#61657A] text-sm mt-[20px] text-center" @click="goLogin">
  100. 已有帳號,立即登入
  101. </div>
  102. </div>
  103. </van-cell-group>
  104. </van-form>
  105. <div class="rule flex justify-center van-safe-area-bottom">
  106. <van-checkbox v-model="checked">點擊同意注册協定</van-checkbox>
  107. </div>
  108. </div>
  109. </div>
  110. </template>
  111. <script setup>
  112. import { ref } from 'vue'
  113. import { http } from '@/plugins/http'
  114. import { useUserStore } from '../stores/user'
  115. import { showNotify } from 'vant'
  116. import { useRouter } from 'vue-router'
  117. import { useI18n } from 'vue-i18n'
  118. import { showLoadingToast, closeToast } from 'vant'
  119. const form = ref({
  120. email: '',
  121. username: '',
  122. password: '',
  123. password2: ''
  124. })
  125. const checked = ref(false)
  126. const loginCode = ref(false)
  127. function validator(val) {
  128. return form.value.password === val
  129. }
  130. const router = useRouter()
  131. function goLogin() {
  132. router.back()
  133. }
  134. const { t } = useI18n()
  135. const { register } = useUserStore()
  136. showLoadingToast({
  137. message: t('loading'),
  138. forbidClick: true
  139. })
  140. function onSubmit() {
  141. register(form.value.email, form.value.username, form.value.password).then(res => {
  142. closeToast()
  143. showNotify({ type: 'success', message: t('login.register') })
  144. router.go(-2)
  145. })
  146. }
  147. </script>
  148. <style lang="less" scoped>
  149. .login {
  150. .login-content {
  151. position: relative;
  152. z-index: 1;
  153. padding: 30px;
  154. }
  155. }
  156. .van-cell-group {
  157. --van-cell-group-background: transparent;
  158. --van-cell-background: transparent;
  159. --van-cell-border-color: #4d61657a;
  160. --van-field-placeholder-text-color: #61657a;
  161. /deep/.van-field__label--top {
  162. margin-bottom: 14px;
  163. }
  164. /deep/.van-cell__value {
  165. line-height: 44px;
  166. }
  167. .van-cell {
  168. --van-cell-value-color: #fff;
  169. --van-cell-font-size: 14px;
  170. --van-field-input-text-color: #fff;
  171. --van-field-clear-icon-color: #404455;
  172. padding: 40px 0 0;
  173. &::after {
  174. left: 0;
  175. right: 0;
  176. }
  177. }
  178. .left-icon {
  179. width: 24px;
  180. height: 24px;
  181. }
  182. }
  183. .rule {
  184. // position: fixed;
  185. // bottom: 30px;
  186. // left: 50%;
  187. // transform: translateX(-50%);
  188. .van-checkbox {
  189. --van-checkbox-size: 16px;
  190. --van-checkbox-border-color: #61657a;
  191. --van-checkbox-label-color: #61657a;
  192. font-size: 12px;
  193. }
  194. }
  195. </style>