login.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <!-- -->
  2. <template>
  3. <div class="my-5">
  4. <phoneFrom ref="phoneRef" @handleEnter="handleLogin"></phoneFrom>
  5. <v-btn :loading="loginLoading" color="primary" class="white--text mt-5" min-width="350" @click="handleLogin">
  6. {{ $t('login.register') }}
  7. </v-btn>
  8. </div>
  9. </template>
  10. <script setup>
  11. import phoneFrom from '@/components/VerificationCode'
  12. import { useUserStore } from '@/store/user'; const userStore = useUserStore()
  13. import { useI18n } from '@/hooks/web/useI18n'; const { t } = useI18n()
  14. import Snackbar from '@/plugins/snackbar'
  15. import { ref } from 'vue'
  16. defineOptions({name: 'shareJob-login'})
  17. const emit = defineEmits(['loginSuccess'])
  18. // 验证码登录
  19. const phoneRef = ref()
  20. const loginLoading = ref(false)
  21. const timer = ref(null)
  22. const baseInfo = ref(null)
  23. const handleLogin = async () => {
  24. localStorage.removeItem('currentRole')
  25. const { valid } = await phoneRef.value.phoneForm.validate()
  26. if (!valid) return
  27. loginLoading.value = true
  28. try {
  29. const params = { ...phoneRef.value.loginData } // 只能验证码登录
  30. await userStore.handleSmsLogin(params)
  31. // 查询用户基本信息
  32. timer.value = setInterval(() => { getUserInfoVerify() }, 1000)
  33. // 十秒后停止获取清除timer
  34. setTimeout(() => { if (!baseInfo.value) getUserInfoFail() }, 10000);
  35. } catch (error) {
  36. console.error('error', error)
  37. }
  38. }
  39. // 查询用户基本信息失败
  40. const getUserInfoVerify = () => {
  41. if (baseInfo.value) {
  42. clearInterval(timer.value)
  43. timer.value = null
  44. loginLoading.value = false
  45. const info = baseInfo.value
  46. const keyArr = ['name', 'phone', 'jobStatus', 'expType', 'eduType']
  47. // type = true, 符合快速投递,进入查看是否存在简历 // type = false, 不符合快速投递,进入填写基本信息
  48. const type = keyArr.every(e => baseInfo.value[e] && baseInfo.value[e] !== 0)
  49. emit('loginSuccess', { type, info, keyArr })
  50. }
  51. baseInfo.value = JSON.parse(localStorage.getItem('baseInfo'))
  52. }
  53. // 查询用户基本信息失败
  54. const getUserInfoFail = () => {
  55. clearInterval(timer.value)
  56. timer.value = null
  57. loginLoading.value = false
  58. Snackbar.success(t('login.getUserInfoFailed')+','+t('login.loginAgain'))
  59. }
  60. </script>
  61. <style lang="scss" scoped>
  62. </style>