فهرست منبع

去掉loginType

lifanagju_citu 2 ماه پیش
والد
کامیت
6b01c4b3e5

+ 1 - 3
components.d.ts

@@ -33,9 +33,7 @@ declare module 'vue' {
     Echarts: typeof import('./src/components/Echarts/index.vue')['default']
     ElCascader: typeof import('element-plus/es')['ElCascader']
     ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
-    ElIcon: typeof import('element-plus/es')['ElIcon']
     ElTree: typeof import('element-plus/es')['ElTree']
-    ElUpload: typeof import('element-plus/es')['ElUpload']
     Empty: typeof import('./src/components/Empty/index.vue')['default']
     File: typeof import('./src/components/Upload/file.vue')['default']
     HeadSearch: typeof import('./src/components/headSearch/index.vue')['default']
@@ -49,7 +47,7 @@ declare module 'vue' {
     IndustryTypeCard: typeof import('./src/components/industryTypeCard/index.vue')['default']
     Info: typeof import('./src/components/Enterprise/info.vue')['default']
     InitPay: typeof import('./src/components/personalRecharge/initPay.vue')['default']
-    Item: typeof import('./src/components/PositionLongStrip/item.vue')['default']
+    Item: typeof import('./src/components/Position/item.vue')['default']
     JobTypeCard: typeof import('./src/components/jobTypeCard/index.vue')['default']
     ListGroup: typeof import('./src/components/FormUI/nestedListGroup/components/listGroup.vue')['default']
     Loading: typeof import('./src/components/Loading/index.vue')['default']

+ 8 - 11
src/permission.js

@@ -16,10 +16,6 @@ let isRefresh = true
 const ENTERPRISE_PATH = '/recruit/enterprise'
 const TEACHER_PATH = '/recruit/teacher'
 
-// loginType:1.enterprise: 企业路由
-//            2.personal: 个人路由
-//            3.common: 没有限制访问权限
-//            3.personalCommon: 无需登录也能访问的页面
 // 路由守卫
 router.beforeEach(async (to, from, next) => {
   start()
@@ -32,6 +28,10 @@ router.beforeEach(async (to, from, next) => {
   if (!isEnterprise && to.path !== '/enterpriseVerification' && !hasRoute(to.path)) {
     next('/404')
   }
+  const isTeacher = to.path.includes(TEACHER_PATH)
+  
+  const tokenIndex = isEnterprise ? 1 : isTeacher ? 3 : 2 // 1:企业 2:个人 3:教师
+
   // 获取商城装修模版
   const mallStore = useMallStore()
   const enterpriseStore = useEnterpriseStore()
@@ -40,7 +40,6 @@ router.beforeEach(async (to, from, next) => {
   }
 
   localStorage.setItem('routerTest', to.path) // 本地环境保存代码热更新会导致路径缺失问题
-  const tokenIndex = getIsEnterprise() ? 1: 2
   if (to.path === '/enterpriseVerification') {
     const res = JSON.parse(localStorage.getItem('emailLoginInfo') || "false")
     const obj = res ? { ...res, type: 'emailLogin' } : {}
@@ -128,7 +127,9 @@ router.beforeEach(async (to, from, next) => {
         return
       }
     }
-    
+
+    // if (isTeacher) {}
+
     // 强制填写个人信息 fddeaddc47868b/ready
     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')
@@ -140,14 +141,10 @@ router.beforeEach(async (to, from, next) => {
     next()
     return
   }
-  if (to.meta?.loginType === 'personalCommon' || to.meta?.loginType === 'common') { // 路由不重定向
+  if (to.meta?.commonPage) { // 公共页面,路由不重定向
     next()
     return
   }
-  if (to.meta?.loginType === 'enterprise') { // 没有企业token->去个人首页
-    next('/recruitHome')
-    return
-  }
   next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
 })
 

+ 205 - 0
src/permissionTest.js

@@ -0,0 +1,205 @@
+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'
+import { useEnterpriseStore } from '@/store/enterprise'
+
+const { start, done } = useNProgress()
+
+let isRefresh = true
+const ENTERPRISE_PATH = '/recruit/enterprise'
+const TEACHER_PATH = '/recruit/teacher'
+
+// loginType:1.enterprise: 企业路由
+//            2.personal: 个人路由
+//            3.common: 没有限制访问权限
+//            3.personalCommon: 无需登录也能访问的页面
+// 路由守卫
+router.beforeEach(async (to, from, next) => {
+  start()
+  // 个人端 404 处理
+  if (to.path === '/404') {
+    next()
+    return
+  }
+  const isEnterprise = to.path.includes(ENTERPRISE_PATH)
+  if (!isEnterprise && to.path !== '/enterpriseVerification' && !hasRoute(to.path)) {
+    next('/404')
+  }
+  // 获取商城装修模版
+  const mallStore = useMallStore()
+  const enterpriseStore = useEnterpriseStore()
+  if (!localStorage.getItem('mallTemplate')) {
+    await mallStore.getMallDiyTemplate()
+  }
+
+  localStorage.setItem('routerTest', to.path) // 本地环境保存代码热更新会导致路径缺失问题
+  const tokenIndex = getIsEnterprise() ? 1: 2
+  if (to.path === '/enterpriseVerification') {
+    const res = JSON.parse(localStorage.getItem('emailLoginInfo') || "false")
+    const obj = res ? { ...res, type: 'emailLogin' } : {}
+
+    // 清除路由表
+    enterpriseStore.clearEnterpriseMenu()
+    isRefresh = true
+    useUserStore().changeRole(obj)
+    next()
+    return
+  }
+  if (getToken(tokenIndex)) {
+    if (isEnterprise) {
+      // 获取企业路由
+      if (!enterpriseStore.enterpriseMenu || !enterpriseStore.enterpriseMenu.length ) {
+        const { menus } = await enterpriseStore.getEnterpriseMenu()
+        enterpriseStore.saveEnterpriseMenu(menus)
+      }
+      // 渲染路由
+      if (isRefresh) {
+        isRefresh = false
+        const routes = enterpriseStore.assignEnterpriseMenu(enterpriseStore.enterpriseMenu)
+
+        // 有角色但可访问的菜单权限则提示联系管理员分配菜单权限
+        if (!routes || !routes.length) {
+          next('/permissionPrompt')
+          return
+        }
+
+        routes.forEach(route => {
+          router.addRoute(route)
+        })
+        // 判断是否存在路由
+        if (to.path !== ENTERPRISE_PATH && !hasRoute(to.path)) {
+          next('/404')
+          return
+        }
+
+        // 强制修改密码
+        if (localStorage.getItem('entUpdatePassword') === 'needChange') fullScreen('entUpdatePassword')
+        // 企业登录-招聘会广告
+        else if (hasRoute('/recruit/enterprise/jobFair/index') && !localStorage.getItem('jobFairAd') && tokenIndex === 1) {
+          localStorage.setItem('jobFairAd', 'hasBeenShow')
+          dialogExtend('jobFairAd')
+        }
+        // 企业登录-免费职位广告提示
+        else if (hasRoute('/recruit/enterprise/position/index') && localStorage.getItem('positionAd') && tokenIndex === 1) {
+          localStorage.setItem('positionAd', '')
+          dialogExtend('positionAd')
+        }
+        // 企业信息完成度提示(只有企业管理弹)
+        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.path === ENTERPRISE_PATH) {
+          next(findPath(routes))
+          function findPath (nodes, root = '') {
+            const first = nodes[0]
+            const path = root + first.path
+            if (!first.children || !first.children.length) {
+              return path
+            }
+            return findPath(first.children, path + '/')
+          }
+        }
+
+        next({ ...to, replace: true })
+        return
+      }
+      // 判断是否存在路由
+      if (!hasRoute(to.path)) {
+        next('/404')
+        return
+      }
+    }
+    
+    // 强制填写个人信息 fddeaddc47868b/ready
+    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')
+    
+    if (to.fullPath === '/login') {
+      next('/recruitHome')
+      return
+    }
+    next()
+    return
+  }
+  if (to.meta?.loginType === 'personalCommon' || to.meta?.loginType === 'common') { // 路由不重定向
+    next()
+    return
+  }
+  if (to.meta?.loginType === 'enterprise') { // 没有企业token->去个人首页
+    next('/recruitHome')
+    return
+  }
+  next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
+})
+
+router.afterEach((to) => {
+  useTitle(to?.meta?.title)
+  done() // 结束Progress
+  // loadDone()
+})
+
+
+function hasRoute (path) {
+  const routes = router.getRoutes()
+  return routeFlattening(routes).some(_path => {
+    if (_path.includes(':')) {
+      const change = path.split('/')
+      const _change = _path.split('/')
+      if (change.length !== _change.length) {
+        return false
+      }
+      const res = _change.reduce((e, v, i) => {
+        if (v.includes(':')) {
+          e.push(true)
+          return e
+        }
+        e.push(change[i] === v)
+        return e
+      }, [])
+      return res.every(e => e)
+    }
+    // 检查常规路由或包含参数的路由  
+    return _path === path
+  })
+}
+
+/**
+ * @param {Array} routes
+ * @returns {Array}
+ * 路由扁平化 抽离children字段
+ */
+function routeFlattening (routes) {
+  return routes.reduce((prev, cur) => {
+    prev.push(cur.path)
+    if (cur.children && cur.children.length) {
+      prev.push(...routeFlattening(cur.children))
+    }
+    return prev
+  }, [])
+}
+
+// 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()
+//    }
+// });

+ 0 - 3
src/router/modules/components/recruit/enterprise.js

@@ -12,9 +12,6 @@ const enterprise = [
   // { 不能重定向,用于切换企业登录拦截
   //   path: '/enterpriseVerification', // 切换企业后先校验是否具备必填信息
   //   show: true,
-  //   meta: {
-  //     loginType: 'enterprise'
-  //   }
   //   // redirect: '/enterprise',
   // },
 

+ 0 - 4
src/router/modules/recruit.js

@@ -4,7 +4,6 @@ import teacher from './components/recruit/teacher'
 import enterprise from './components/recruit/enterprise'
 import personal from './components/recruit/personal'
 import Layout from '@/layout'
-import { setLoginType } from '@/utils/loginType'
 
 const recruit = [
   {
@@ -285,9 +284,6 @@ const recruit = [
     },
 ]
 
-setLoginType(recruit, 'personalCommon'),
-setLoginType(enterprise, 'enterprise'),
-setLoginType(personal, 'personal')
 
 const routeArray = [
   ...recruit,

+ 0 - 3
src/router/modules/remaining.js

@@ -1,7 +1,6 @@
 import common from './common'
 import recruit from './recruit'
 // import Layout from '@/layout'
-import { setLoginType } from '@/utils/loginType'
 
 
 const remainingRouter = [
@@ -186,8 +185,6 @@ const remainingRouter = [
     }
   }
 ]
-setLoginType(remainingRouter, 'personalCommon') // 暂定:登录企业端不能访问personalCommon路由
-setLoginType(common, 'common') // common 没有身份,任何情况都能访问
 const routeArray = [
   ...recruit,
   ...common,

+ 0 - 1
src/store/enterprise.js

@@ -49,7 +49,6 @@ export const useEnterpriseStore = defineStore('enterpriseStore',
             meta: {
               title: item.name,
               icon: item.icon,
-              loginType: 'enterprise'
             }
           })
 

+ 0 - 11
src/utils/loginType.js

@@ -1,11 +0,0 @@
-export const setLoginType = (arr, type) => {
-  traverse(arr)
-
-  function traverse(list) {
-    list.forEach(e => {
-      if (!e.meta) e.meta = {}
-      if (!e.meta.loginType) e.meta.loginType = type // 存在的话取e.meta.loginType,meta.loginType优先级高于这里默认的type
-      if (e.children?.length) traverse(e.children)
-    })
-  }
-}

+ 2 - 1
src/views/recruit/components/message/index.vue

@@ -225,6 +225,7 @@ import { previewFile } from '@/utils'
 import { timesTampChange } from '@/utils/date'
 import { useRouter } from 'vue-router'
 import studentDeliveryForm from '@/views/recruit/personal/components/studentDeliveryForm.vue'
+import { getIsEnterprise } from '@/utils/auth'
 
 const { t } = useI18n()
 const chatRef = ref()
@@ -865,7 +866,7 @@ const handleAgree = (val) => {
   const query = {
     id: val.id
   }
-  const type = route?.meta?.loginType === 'enterprise' ? 'entBaseInfo' : 'baseInfo'
+  const type = getIsEnterprise() ? 'entBaseInfo' : 'baseInfo'
   const baseInfo = localStorage.getItem(type)
   if (baseInfo) {
     const { phone } = JSON.parse(baseInfo)