necessaryInfoDialog.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!-- 完善个人信息 -->
  2. <template>
  3. <v-app>
  4. <CtDialog
  5. :visible="dialog"
  6. :widthType="2"
  7. titleClass="text-h6"
  8. title="完善个人信息"
  9. :closeable="false"
  10. otherBtnText="退出登录"
  11. @other="handleLogout"
  12. @submit="simpleInfoSubmit"
  13. >
  14. <studentInfoForm v-if="isStudent" ref="formRef" :option="option"></studentInfoForm>
  15. <infoForm v-else ref="formRef" :option="option"></infoForm>
  16. </CtDialog>
  17. <Loading :visible="overlay"></Loading>
  18. </v-app>
  19. </template>
  20. <script setup>
  21. defineOptions({name: 'dialogExtend-dialog'})
  22. import infoForm from './infoForm.vue'
  23. import studentInfoForm from './studentInfoForm.vue'
  24. import { savePersonSimpleInfo, saveStudentSimpleInfo } from '@/api/recruit/personal/shareJob'
  25. import CtDialog from '@/components/CtDialog'
  26. import { useUserStore } from '@/store/user'; const userStore = useUserStore()
  27. import { useRoute } from 'vue-router'; const route = useRoute()
  28. import { useRouter } from 'vue-router'; const router = useRouter()
  29. import Confirm from '@/plugins/confirm'
  30. import { onMounted, ref } from 'vue'
  31. import { getToken } from '@/utils/auth'
  32. import Snackbar from '@/plugins/snackbar'
  33. import { showImprovePersonaInfo } from '@/utils/whiteList'
  34. const props = defineProps({
  35. // title: String,
  36. // text: String,
  37. // cancel: Function,
  38. sure: Function,
  39. other: Function,
  40. option: {
  41. type: Object,
  42. default: () => {}
  43. },
  44. setInfo: {
  45. type: Object,
  46. default: () => {}
  47. }
  48. })
  49. const dialog = ref(false)
  50. const isStudent = ref(localStorage.getItem('chooseRole') === 'student')
  51. // const isMobile = ref(false)
  52. onMounted(() => {
  53. const parsedUrl = new URL(window.location.href)
  54. const pathName = parsedUrl.pathname
  55. // 在白名单内不弹窗
  56. if (showImprovePersonaInfo(pathName)) {
  57. props.sure() // 如果在白名单内->不打开弹窗且继续下一步调用
  58. } else {
  59. dialog.value = true // 打开弹窗
  60. }
  61. dialog.value = pathName ? Boolean(!showImprovePersonaInfo(pathName)) : true
  62. })
  63. const overlay = ref(false)
  64. const formRef = ref()
  65. const simpleInfoSubmit = async () => {
  66. if (!getToken()) {
  67. Confirm('系统提示', '登录失效,请重新登录', { hideCancelBtn: true }).then(() => {
  68. window.location.reload()
  69. })
  70. return
  71. }
  72. try {
  73. const obj = await formRef.value.getQuery()
  74. if (!obj) return
  75. overlay.value = true
  76. const apiFun = isStudent.value ? saveStudentSimpleInfo : savePersonSimpleInfo
  77. await apiFun(obj)
  78. Snackbar.success('保存成功')
  79. // const info = localStorage.getItem('baseInfo') ? JSON.parse(localStorage.getItem('baseInfo')) : {}
  80. // localStorage.setItem('baseInfo', JSON.stringify({ ...info, ...obj }))
  81. // localStorage.setItem('necessaryInfoReady', 'ready') //
  82. await useUserStore().getUserBaseInfos() // 更新用户信息
  83. if (isStudent.value) localStorage.removeItem('chooseRole')
  84. dialog.value = false
  85. overlay.value = false
  86. props.sure()
  87. } catch (error) {
  88. console.error('error', error)
  89. }
  90. }
  91. // 退出登录
  92. const handleLogout = () => {
  93. Confirm('系统提示', '是否确定退出当前登录账号?').then(async () => {
  94. await userStore.userLogout(1)
  95. props.other()
  96. if (!route || route.path === '/recruitHome') location.reload()
  97. else router.push({ path: '/recruitHome' })
  98. })
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. </style>