simple.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!-- 快速填写-简易人才信息 -->
  2. <template>
  3. <CtDialog
  4. :visible="openDialog"
  5. :widthType="2"
  6. :closeText="closeText"
  7. titleClass="text-h6"
  8. title="补充基本信息"
  9. :closeable="props.closeable"
  10. @close="openDialog = props.closeable ? false : true"
  11. @submit="simpleInfoSubmit"
  12. >
  13. <simpleInfoForm ref="formRef"></simpleInfoForm>
  14. </CtDialog>
  15. </template>
  16. <script setup>
  17. import { getToken } from '@/utils/auth'
  18. import simpleInfoForm from '../form/simpleInfo.vue'
  19. import { savePersonSimpleInfo } from '@/api/recruit/personal/shareJob'
  20. import { useI18n } from '@/hooks/web/useI18n'; const { t } = useI18n()
  21. import Snackbar from '@/plugins/snackbar'
  22. import { ref } from 'vue'
  23. defineOptions({name: 'shareJob-sendResume-simple'})
  24. const emit = defineEmits(['simpleInfoReady'])
  25. const props = defineProps({
  26. closeable: {
  27. type: Boolean,
  28. default: true
  29. },
  30. closeText: {
  31. type: String,
  32. default: '取消'
  33. }
  34. })
  35. const openDialog = ref(false) // 默认不打开弹窗,先检验simpleInfoReady
  36. const info = ref(null)
  37. // 查询用户基本信息
  38. const timer = ref(null)
  39. timer.value = setInterval(() => { getUserInfoVerify() }, 100)
  40. // 十秒后停止获取清除timer
  41. setTimeout(() => { if (!info.value) getUserInfoFail() }, 10000);
  42. // 查询用户基本信息
  43. const getUserInfoVerify = () => {
  44. if (!getToken()) {
  45. clearInterval(timer.value); timer.value = null
  46. return
  47. }
  48. if (info.value) {
  49. if (timer.value) clearInterval(timer.value); timer.value = null
  50. const keyArr = ['name', 'phone', 'jobStatus', 'expType', 'eduType'] // 必填人才信息
  51. const simpleInfoReady = Object.keys(info.value).length && keyArr.every(e => info.value[e] && info.value[e] !== 0) // 校验必填人才信息
  52. if (simpleInfoReady) {
  53. emit('simpleInfoReady') // 存在
  54. } else {
  55. openDialog.value = true // 不存在
  56. Snackbar.warning('请先完善个人基本信息')
  57. localStorage.setItem('simpleCompleteDialogHaveBeenShow', true)
  58. }
  59. }
  60. info.value = JSON.parse(localStorage.getItem('baseInfo'))
  61. }
  62. // 查询用户基本信息-失败
  63. const getUserInfoFail = () => {
  64. if (timer.value) clearInterval(timer.value); timer.value = null
  65. Snackbar.error(t('login.getUserInfoFailed')+','+t('login.loginAgain'))
  66. }
  67. const formRef = ref()
  68. const simpleInfoSubmit = async () => {
  69. try {
  70. const obj = await formRef.value.getQuery()
  71. if (!obj) return
  72. await savePersonSimpleInfo(obj)
  73. localStorage.setItem('baseInfo', JSON.stringify(obj))
  74. openDialog.value = false
  75. emit('simpleInfoReady')
  76. } catch (error) {
  77. console.error('error', error)
  78. }
  79. }
  80. </script>
  81. <style lang="scss" scoped>
  82. </style>