index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="login-box">
  3. <div class="login-content">
  4. <div class="text-end pr-5 pt-5">
  5. <span class="color-error cursor-pointer text-decoration-underline" @click="router.push('/register/selected')">还没有登录账户?去注册</span>
  6. </div>
  7. <div class="login-content-box mb-10">
  8. <div class="login-tab">
  9. <v-tabs v-model="tab" align-tabs="center" color="primary" class="mb-10">
  10. <v-tab :value="1">验证码</v-tab>
  11. <v-tab :value="2">账号</v-tab>
  12. <v-tab :value="3">二维码</v-tab>
  13. </v-tabs>
  14. <v-window v-model="tab">
  15. <!-- 验证码登录 -->
  16. <v-window-item :value="1">
  17. <phoneFrom ref="phoneRef" @handleEnter="handleLogin"></phoneFrom>
  18. </v-window-item>
  19. <!-- 账号密码登录 -->
  20. <v-window-item :value="2">
  21. <passwordFrom ref="passRef" @handleEnter="handleLogin"></passwordFrom>
  22. </v-window-item>
  23. <v-window-item :value="3">
  24. <div class="d-flex align-center flex-column">
  25. <span class="text-decoration-underline">微信扫描二维码进行登录</span>
  26. <v-img src="https://minio.citupro.com/dev/menduner/login-qrCode.png" width="150" height="150"></v-img>
  27. </div>
  28. </v-window-item>
  29. </v-window>
  30. </div>
  31. <div class="font-size-14 tips">
  32. <span class="float-left color-666 cursor-pointer" v-if="tab === 2" @click="router.push('/forgotPassword')">忘记密码</span>
  33. </div>
  34. <v-btn :loading="loginLoading" color="primary" class="white--text mt-5" min-width="350" @click="handleLogin">
  35. {{ $t('login.login') }}
  36. </v-btn>
  37. <div class="login-tips mt-3">
  38. {{ $t('login.agreeLogin') }}
  39. <span class="color" style="cursor: pointer;" @click="handleToUserAgreement"> [{{ $t('login.userAgreement') }}] </span>和
  40. <span class="color" style="cursor: pointer;" @click="handlePrivacyPolicy">[{{ $t('login.privacyPolicy') }}]</span>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </template>
  46. <script setup>
  47. import { ref } from 'vue'
  48. import passwordFrom from './components/passwordPage.vue'
  49. import phoneFrom from '@/components/VerificationCode'
  50. import { useUserStore } from '@/store/user'
  51. import { useRouter } from 'vue-router'
  52. import { useI18n } from '@/hooks/web/useI18n'
  53. import Snackbar from '@/plugins/snackbar'
  54. defineOptions({ name: 'login-index' })
  55. const { t } = useI18n()
  56. const router = useRouter()
  57. const tab = ref(1)
  58. // 验证码登录
  59. const phoneRef = ref()
  60. const passRef = ref()
  61. const loginLoading = ref(false)
  62. const userStore = useUserStore()
  63. const handleLogin = async () => {
  64. const { valid } = tab.value === 1 ? await phoneRef.value.phoneForm.validate() : await passRef.value.passwordForm.validate()
  65. if (!valid) return
  66. loginLoading.value = true
  67. try {
  68. let params, api = {}
  69. if (tab.value === 1) { params = { ...phoneRef.value.loginData }; api = 'handleSmsLogin'}
  70. else { params = { ...passRef.value.loginData }; api = 'handlePasswordLogin'}
  71. // 邮箱为企业招聘, 手机号为个人求职
  72. if (tab.value === 2) {
  73. const pattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  74. const isEnterprise = pattern.test(params.phone)
  75. params.isEnterprise = isEnterprise
  76. }
  77. // if (params.isEnterprise) router.push({ path: '/enterpriseVerification' }) // 先跳转到会使用企业token的路由
  78. await userStore[api](params)
  79. // 跳转
  80. if (params.isEnterprise) return // 企业邮箱登录
  81. Snackbar.success(t('login.loginSuccess'))
  82. router.push({ path: '/recruitHome' })
  83. }
  84. finally {
  85. loginLoading.value = false
  86. }
  87. }
  88. // 隐私、用户协议
  89. const handleToUserAgreement = () => {
  90. router.push({ path: '/userAgreement' })
  91. }
  92. const handlePrivacyPolicy = () => {
  93. router.push({ path: '/privacyPolicy' })
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. .login-box {
  98. position: relative;
  99. width: 100%;
  100. height: 100%;
  101. background-image: url('https://www.mendunerhr.com/images/userfiles/92d7e4a755e2428b94aab3636d5047f3/images/recruitment/adImages/2018/11/1920x940.jpg');
  102. background-size: cover;
  103. }
  104. .login-content {
  105. position: absolute;
  106. top: 50%;
  107. left: 50%;
  108. translate: -50% -50%;
  109. width: 450px;
  110. background-color: #fff;
  111. border-radius: 10px;
  112. }
  113. .login-content-box {
  114. padding: 0 50px;
  115. }
  116. .left {
  117. display: flex;
  118. }
  119. .login-tips {
  120. width: 100%;
  121. font-size: 12px;
  122. text-align: center;
  123. }
  124. .tips {
  125. span:hover {
  126. text-decoration: underline;
  127. }
  128. }
  129. .color {
  130. color: var(--v-primary-base);
  131. }
  132. </style>