Browse Source

区分个人端登录和企业端登录

lifanagju_citu 10 months ago
parent
commit
62aec2b144

+ 1 - 1
src/layout/company/side.vue

@@ -46,7 +46,7 @@
 defineOptions({ name: 'enterprise-side'})
 import { computed } from 'vue'
 import { getCurrentLocaleLang } from '@/utils/lang.js'
-import enterpriseRoute from '@/router/modules/enterprise'
+import enterpriseRoute from '@/router/modules/components/recruit/enterprise'
 
 const list = computed(() => {
   return getList(enterpriseRoute)

+ 3 - 3
src/layout/personal/navBar.vue

@@ -27,7 +27,7 @@
         </div>
         
         <div class="d-flex user-nav">
-          <div class="btns d-flex align-center" v-if="!getToken()">
+          <div class="btns d-flex align-center" v-if="!getPersonalToken()">
             <!-- <span class="nav-resume-tools">
               <a href="">{{ $t('sys.lookingJob') }}</a>
               <a href="">{{ $t('sys.recruit') }}</a>
@@ -36,7 +36,7 @@
           </div>
           
           <!-- 头像用户名 -->
-          <div class="d-flex align-center" v-if="getToken()">
+          <div class="d-flex align-center" v-if="getPersonalToken()">
             <a target="_blank" href="/mall/purchasePackage" class="cursor-pointer mr-5" style="color: #FB8C00;">{{ $t('vipPackage.purchasePackage') }}</a>
             <span class="cursor-pointer" @click="router.push({ path: '/recruit/personal/TaskCenter' })">{{ $t('sys.signIn') }}</span>
             <span class="cursor-pointer mx-5">{{ $t('sys.news') }}</span>
@@ -105,7 +105,7 @@
 
 <script setup>
 import { ref } from 'vue'
-import { getToken } from '@/utils/auth'
+import { getPersonalToken } from '@/utils/auth'
 import { useUserStore } from '@/store/user'
 import { useLocaleStore } from '@/store/locale'
 import { useI18n } from '@/hooks/web/useI18n'

+ 4 - 4
src/permission.js

@@ -22,7 +22,7 @@ const { start, done } = useNProgress()
 
 // loginType:1.enterprise: 企业路由
 //            2.personal: 个人路由
-//            3.noLogin: 无需登录也能访问的页面(personal里面的一种特殊类型,企业相关路由都需要登录)
+//            3.noLogin: 无需登录也能访问的页面
 // 路由守卫
 router.beforeEach(async (to, from, next) => {
   start()
@@ -34,9 +34,9 @@ router.beforeEach(async (to, from, next) => {
       const type = localStorage.getItem('loginType')
       // 判断企业路由和个人路由,防止互串
       if (!type) { removeToken(); next(`/login?redirect=${to.fullPath}`) }
-      else if (to.path === '/mall') next()
-      else if (type === 'enterprise' && to.meta?.loginType === 'noLogin') next({ path: `/${type}` })
-      else if (type === 'personal' && to.meta?.loginType === 'noLogin') next()
+      else if (to.meta?.loginType === 'noLogin') next()
+      // else if (type === 'enterprise' && to.meta?.loginType === 'noLogin') next({ path: `/${type}` }) // 企业端不能访问个人端路由
+      // else if (type === 'personal' && to.meta?.loginType === 'noLogin') next()
       else if (to.meta?.loginType === type) next()
       else next({ path: `/${type}` })
       // next()

+ 40 - 0
src/router/modules/common.js

@@ -0,0 +1,40 @@
+// 公共路由(任何身份都可以访问的路由 如:商城)
+
+const common = [
+  {
+    path: '', // 门墩项目列表/项目入口页
+    redirect: '/entrances',
+    children: [
+      { path: '/', redirect: '/entrances' },
+      {
+        path: '/entrances',
+        component: () => import('@/views/entrances/index'),
+        meta: {
+          title: '门墩儿应用中心'
+        }
+      }
+    ]
+  },
+  {
+    path: '/mall',
+    children: [
+      {
+        path: '/mall',
+        component: () => import('@/views/mall/index'),
+        meta: {
+          title: '臻选商城'
+        }
+      }
+    ]
+  },
+  {
+    path: '/shareJob',
+    name: 'shareJob',
+    meta: {
+      title: '分享职位'
+    },
+    component: () => import('@/views/recruit/personal/shareJob/index.vue')
+  },
+]
+
+export default common

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


+ 0 - 0
src/router/modules/personal.js → src/router/modules/components/recruit/personal.js


+ 31 - 1
src/router/modules/recruit.js

@@ -1,11 +1,31 @@
 
 // 门墩儿招聘
+import enterprise from './components/recruit/enterprise'
+import personal from './components/recruit/personal'
 import Layout from '@/layout'
+import { setLoginType } from '@/utils/loginType'
 const recruit = [
   {
     path: '/recruit',
     redirect: '/home'
   },
+  {
+    path: '/personal', // 个人账号登录时,缺省只能访问个人账号路由和不需要登录,防止用户在地址栏直接输入地址访问其他页面(不可删,permission中用到)
+    redirect: '/home'
+  },
+  {
+    path: '/home',
+    component: Layout,
+    children: [
+      {
+        path: '/home',
+        component: () => import('@/views/recruit/personal/home'),
+        meta: {
+          title: '首页'
+        }
+      }
+    ]
+  },
   {
     path: '/recruit/personal/position',
     component: Layout,
@@ -55,4 +75,14 @@ const recruit = [
     ]
   }
 ]
-export default recruit
+
+setLoginType(recruit, 'noLogin'),
+setLoginType(enterprise, 'enterprise'),
+setLoginType(personal, 'personal')
+
+const routeArray = [
+  ...recruit,
+  ...enterprise,
+  ...personal
+]
+export default routeArray

+ 4 - 56
src/router/modules/remaining.js

@@ -1,5 +1,4 @@
-import personal from './personal'
-import enterprise from './enterprise'
+import common from './common'
 import recruit from './recruit'
 import Layout from '@/layout'
 import { setLoginType } from '@/utils/loginType'
@@ -43,66 +42,15 @@ const remainingRouter = [
       }
     ]
   },
-  {
-    path: '',
-    redirect: '/entrances',
-    children: [
-      { path: '/', redirect: '/entrances' },
-      {
-        path: '/entrances',
-        component: () => import('@/views/entrances/index'),
-        meta: {
-          title: '门墩儿应用中心'
-        }
-      }
-    ]
-  },
-  {
-    path: '/home',
-    component: Layout,
-    children: [
-      { path: '/personal', redirect: '/home' }, // 个人账号登录时,缺省只能访问个人账号路由和不需要登录,防止用户在地址栏直接输入地址访问其他页面(不可删,permission中用到)
-      {
-        path: '/home',
-        component: () => import('@/views/recruit/personal/home'),
-        meta: {
-          title: '首页'
-        }
-      }
-    ]
-  },
-  {
-    path: '/mall',
-    children: [
-      {
-        path: '/mall',
-        component: () => import('@/views/mall/index'),
-        meta: {
-          title: '臻选商城'
-        }
-      }
-    ]
-  },
-  {
-    path: '/shareJob',
-    name: 'shareJob',
-    meta: {
-      title: '分享职位'
-    },
-    component: () => import('@/views/recruit/personal/shareJob/index.vue')
-  },
 ]
-
 setLoginType(remainingRouter, 'noLogin')
-setLoginType(recruit, 'noLogin')
-setLoginType(personal, 'personal')
-setLoginType(enterprise, 'enterprise')
+setLoginType(common, 'noLogin')
 
 const routeArray = [
   ...remainingRouter,
   ...recruit,
-  ...personal,
-  ...enterprise
+  ...common
 ]
+console.log('recruit', recruit)
 
 export default routeArray

+ 10 - 0
src/utils/auth.js

@@ -31,3 +31,13 @@ export const getTenantId = () => {
 export const setTenantId = (username) => {
   localStorage.setItem('tenantId', username)
 }
+
+// 招聘端个人token
+export const getEnterpriseToken = () => {
+  return localStorage.getItem('loginType') === 'enterprise' && localStorage.getItem('ACCESS_TOKEN')
+}
+
+// 招聘端企业token
+export const getPersonalToken = () => {
+  return localStorage.getItem('loginType') === 'personal' && localStorage.getItem('ACCESS_TOKEN')
+}