123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import router from './router'
- import { useNProgress } from '@/hooks/web/useNProgress'
- import { useTitle } from '@/hooks/web/useTitle'
- import { getToken, getIsEnterprise } from '@/utils/auth'
- // import { useDictStore } from '@/store/dict'
- import { useUserStore } from '@/store/user'
- import Confirm from '@/plugins/confirm'
- import fullScreen from '@/plugins/fullScreen'
- import dialogExtend from '@/plugins/dialogExtend'
- import { useMallStore } from '@/store/mall'
- const { start, done } = useNProgress()
- const TEACHER_PATH = '/recruit/teacher'
- // 路由守卫
- router.beforeEach(async (to, from, next) => {
- // 获取商城装修模版
- const mallStore = useMallStore()
- if (!localStorage.getItem('mallTemplate')) {
- await mallStore.getMallDiyTemplate()
- }
- const tokenIndex = getIsEnterprise() ? 1: 2
- start()
-
- const isTeacherRoute = to.path.includes(TEACHER_PATH)
- const schoolInfo = localStorage.getItem('schoolInfo')
- if (isTeacherRoute && !schoolInfo) {
- next(`/flameLogin?redirect=${to.fullPath}`)
- }
-
- if (to.path === '/enterpriseVerification') {
- const res = JSON.parse(localStorage.getItem('emailLoginInfo') || "false")
- const obj = res ? { ...res, type: 'emailLogin' } : {}
- useUserStore().changeRole(obj)
- next()
- } else if (getToken(tokenIndex)) {
- // 强制修改密码
- if (localStorage.getItem('entUpdatePassword') === 'needChange') fullScreen('entUpdatePassword')
- // 强制填写个人信息 fddeaddc47868b/ready
- else if (localStorage.getItem('chooseRole') === 'showChooseRole' && to.path !== '/register/selectedPersonRole' && tokenIndex === 2) next('/register/selectedPersonRole')
- else if (localStorage.getItem('necessaryInfoReady') === 'fddeaddc47868b' && tokenIndex === 2 && localStorage.getItem('chooseRole') !== 'showChooseRole') dialogExtend('necessaryInfoDialog')
- // 企业信息完成度提示
- else if (localStorage.getItem('checkEnterpriseBaseInfoFalseHref') && tokenIndex === 1) {
- if (to.path !== '/recruit/enterprise/position/add') { // 除了点击企业登录免费职位广告提示跳转路由不提示
- const href = localStorage.getItem('checkEnterpriseBaseInfoFalseHref')
- localStorage.setItem('checkEnterpriseBaseInfoFalseHref', '')
- localStorage.setItem('entUpdatePassword', '')
- if (to.path !== href) {
- setTimeout(() => {
- Confirm('系统提示', '企业信息设置未完善,是否前往完善?').then(() => {
- window.location.href = href
- })
- }, 4000)
- }
- }
- }
- if (to.fullPath === '/login') {
- if (from.path !== '/login' && from.path !== '/') {
- window.location.reload()
- } else {
- next({ path: '/recruitHome' })
- }
- }
- // 获取字典信息
- // const dictStore = useDictStore()
- // dictStore.getDictTypeData()
- next()
- } else {
- if (to.meta?.commonPage) { // 公共页面,路由不重定向
- next()
- } else {
- next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
- }
- }
- })
- router.afterEach((to) => {
- useTitle(to?.meta?.title)
- done() // 结束Progress
- // loadDone()
- })
- // router.onError(error => {
- // const fetchResourcesErrors = ['Failed to fetch dynamically imported module', 'Importing a module script failed']
- // if (fetchResourcesErrors.some((item) => error?.message && error.message?.includes(item))) {
- // window.location.reload()
- // }
- // });
|