zhengnaiwen_citu 5 ヶ月 前
コミット
c8add9ec69

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

@@ -49,7 +49,6 @@ import { getCurrentLocaleLang } from '@/utils/lang.js'
 import { useEnterpriseStore } from '@/store/enterprise'
 
 const enterpriseStore = useEnterpriseStore()
-
 const list = computed(() => {
   return getList(enterpriseStore.enterpriseMenu)
 })

+ 78 - 13
src/permission.js

@@ -12,6 +12,7 @@ import { useEnterpriseStore } from '@/store/enterprise'
 const { start, done } = useNProgress()
 
 let isRefresh = true
+const ENTERPRISE_PATH = '/recruit/enterprise'
 
 // loginType:1.enterprise: 企业路由
 //            2.personal: 个人路由
@@ -19,6 +20,16 @@ let isRefresh = true
 //            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')
+  }
   localStorage.setItem('routerTest', to.path) // 本地环境保存代码热更新会导致路径缺失问题
   // 获取商城装修模版
   const mallStore = useMallStore()
@@ -28,8 +39,6 @@ router.beforeEach(async (to, from, next) => {
   }
   
   const tokenIndex = getIsEnterprise() ? 1: 2
-  start()
-  // loadStart()
   if (to.path === '/enterpriseVerification') {
     const res = JSON.parse(localStorage.getItem('emailLoginInfo') || "false")
     const obj = res ? { ...res, type: 'emailLogin' } : {}
@@ -42,23 +51,39 @@ router.beforeEach(async (to, from, next) => {
     return
   }
   if (getToken(tokenIndex)) {
-    if (tokenIndex === 1) { // 获取企业路由
+    if (isEnterprise) {
+      // 获取企业路由
       if (!enterpriseStore.enterpriseMenu || !enterpriseStore.enterpriseMenu.length ) {
         const { menus } = await enterpriseStore.getEnterpriseMenu()
         enterpriseStore.saveEnterpriseMenu(menus)
       }
+      // 渲染路由
       if (isRefresh) {
-        try {
-          isRefresh = false
-          const routes = enterpriseStore.assignEnterpriseMenu(enterpriseStore.enterpriseMenu)
-          routes.forEach(route => {
-            router.addRoute(route)
-          })
-          next({ ...to, replace: true })
-        } catch(error) {
-          console.log(error)
+        isRefresh = false
+        const routes = enterpriseStore.assignEnterpriseMenu(enterpriseStore.enterpriseMenu)
+        routes.forEach(route => {
+          router.addRoute(route)
+        })
+        // 判断是否存在路由
+        if (to.path !== ENTERPRISE_PATH && !hasRoute(to.path)) {
+          next('/404')
+          return
         }
-        // debugger
+        if (to.path === ENTERPRISE_PATH) {
+          const firstPath = routes[0]
+          if (!firstPath.children) {
+            next(firstPath.path)
+          } else {
+            // 查找二级路由
+            next(routes[0].children[0].path)
+          }
+        }
+        next({ ...to, replace: true })
+        return
+      }
+      // 判断是否存在路由
+      if (!hasRoute(to.path)) {
+        next('/404')
         return
       }
     }
@@ -111,6 +136,46 @@ router.afterEach((to) => {
   // 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))) {

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

@@ -55,13 +55,6 @@ const common = [
           title: '注册新企业'
         },
       },
-      {
-        path: '/recruit/entRegister/joiningEnterprise',
-        component: () => import('@/views/recruit/entRegister/joiningEnterprise'),
-        meta: {
-          title: '加入企业'
-        }
-      },
       {
         path: '/recruit/entRegister/inReview',
         component: () => import('@/views/recruit/entRegister/inReview.vue'),

+ 15 - 18
src/router/modules/components/recruit/enterprise.js

@@ -2,11 +2,13 @@
 import Layout from '@/layout/enterprise.vue'
 
 const enterprise = [
-  {
-    path: '/enterprise', // 企业账号登录时,缺省进去企业路由,防止用户在地址栏直接输入地址访问其他页面(不可删,permission中用到)
-    show: true,
-    redirect: '/recruit/enterprise',
-  },
+  // { path: '/enterprise', component: {template: '<div></div>'} }
+  // {
+  //   path: '/enterprise', // 企业账号登录时,缺省进去企业路由,防止用户在地址栏直接输入地址访问其他页面(不可删,permission中用到)
+  //   show: true,
+  //   redirect: '/recruit/enterprise/position',
+  //   component: {template: '<div></div>'}
+  // },
   // { 不能重定向,用于切换企业登录拦截
   //   path: '/enterpriseVerification', // 切换企业后先校验是否具备必填信息
   //   show: true,
@@ -16,11 +18,6 @@ const enterprise = [
   //   // redirect: '/enterprise',
   // },
 
-  {
-    path: '/recruit/enterprise',
-    show: true,
-    redirect: '/recruit/enterprise/position',
-  },
   // {
   //   path: '/recruit/enterprise/position',
   //   component: Layout,
@@ -40,14 +37,14 @@ const enterprise = [
   //       },
   //       component: () => import('@/views/recruit/enterprise/positionManagement/index.vue')
   //     },
-  //     {
-  //       path: '/recruit/enterprise/position/add',
-  //       show: true,
-  //       meta: {
-  //         title: '新增职位'
-  //       },
-  //       component: () => import('@/views/recruit/enterprise/positionManagement/components/add.vue')
-  //     },
+      // {
+      //   path: '/recruit/enterprise/position/add',
+      //   show: true,
+      //   meta: {
+      //     title: '新增职位'
+      //   },
+      //   component: () => import('@/views/recruit/enterprise/positionManagement/components/add.vue')
+      // },
   //     {
   //       path: '/recruit/enterprise/position/edit',
   //       show: true,

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

@@ -132,11 +132,12 @@ const remainingRouter = [
       title: '404'
     }
   },
+  // { path: '/enterpriseVerification', component: {template: '<div></div>'} },
   // {
   //   path: '/:path(.*)*',
   //   redirect: '/404',
   //   name: '404PageRedirect',
-  // },
+  // }
   // {
   //   path: '/:catchAll(.*)',
   //   redirect: '/404'
@@ -145,9 +146,8 @@ const remainingRouter = [
 setLoginType(remainingRouter, 'personalCommon') // 暂定:登录企业端不能访问personalCommon路由
 setLoginType(common, 'common') // common 没有身份,任何情况都能访问
 const routeArray = [
-  ...remainingRouter,
   ...recruit,
-  ...common
+  ...common,
+  ...remainingRouter
 ]
-
 export default routeArray

+ 17 - 3
src/store/enterprise.js

@@ -27,9 +27,20 @@ export const useEnterpriseStore = defineStore('enterpriseStore',
       MENU: 2,
       BUTTON: 3
     }
+
+    // const registerComponent = (componentPath) => {
+    //   for (const item in modules) {
+    //     if (item.includes(componentPath)) {
+    //       // 使用异步组件的方式来动态加载组件
+    //       // @ts-ignore
+    //       return defineAsyncComponent(modules[item])
+    //     }
+    //   }
+    // }
+
     // 动态加载路由函数  
     const assignEnterpriseMenu = (menuTree) => {  
-      const modules = import.meta.glob('../views/recruit/enterprise/**/*.{vue,tsx}')
+      const modules = import.meta.glob('../views/recruit/enterprise/**/*.vue')
       const modulesRoutesKeys = Object.keys(modules)
       const formatRoutes = (menu) => {
         return menu.map(item => {
@@ -50,8 +61,11 @@ export const useEnterpriseStore = defineStore('enterpriseStore',
           if (item.type === MENU_TYPE.MENU) {
             const index = modulesRoutesKeys.findIndex((ev) => ev.includes(data.component))
             if (index > -1) {
-              data.component = modules[modulesRoutesKeys[index]]
-              data.path = `/${item.path}`
+              data.component = defineAsyncComponent(modules[modulesRoutesKeys[index]])
+            }
+            data.name = data.componentName
+            if (data.path[0] !== '/') {
+              data.path = '/' + data.path
             }
           }
 

+ 2 - 2
src/store/user.js

@@ -182,7 +182,7 @@ export const useUserStore = defineStore('user',
         await this.getEnterpriseUserAccountInfo()
         
         Snackbar.success(res?.type === 'emailLogin' ? '登录成功' : '切换成功')
-        let href = '/enterprise'
+        let href = '/recruit/enterprise'
         // 是否存在重定向
         if (localStorage.getItem('enterpriseRedirect')) {
           href = localStorage.getItem('enterpriseRedirect')
@@ -190,7 +190,7 @@ export const useUserStore = defineStore('user',
         }
         // 人才推荐不需要跳转
         if (!res.noJump) {
-          setTimeout(() => { window.location.href = href }, 1000)
+          window.location.href = href
         }
       },
       // 获取当前登录的企业用户信息

+ 0 - 117
src/views/recruit/entRegister/joiningEnterprise.vue

@@ -1,117 +0,0 @@
-<template>
-  <div class="pt-5">
-    <v-card class="default-width pa-5">
-      <!-- 标题 -->
-      <div class="resume-header">
-        <div class="resume-title">{{ $t('enterprise.joiningEnterprise') }}</div>
-      </div>
-      <!-- 表单 -->
-      <div class="CtFormClass" style="width: 600px;">
-        <CtForm ref="CtFormRef" :items="formItems" style="width: 100%;"></CtForm>
-      </div>
-      <div class="text-center">
-        <!-- 完成 -->
-        <v-btn
-          :loading="loginLoading"
-          color="primary" class="white--text mt-8" min-width="350"
-          @click="handleCommit"
-        >
-        {{ $t('common.complete') }}
-        </v-btn>
-      </div>
-      <!-- 底部 -->
-      <div class="text-center mt-5">
-        <v-btn color="primary" variant="text" @click="router.push({ path: '/recruit/entRegister' })">{{ $t('enterprise.registeringNewEnterprise') }}</v-btn>
-      </div>
-    </v-card>
-  </div>
-</template>
-
-<script setup>
-import CtForm from '@/components/CtForm'
-import { enterpriseSearchByName } from '@/api/recruit/personal/resume'
-import { useRouter } from 'vue-router'
-import Snackbar from '@/plugins/snackbar'
-import { useI18n } from '@/hooks/web/useI18n'
-import { ref } from 'vue'
-
-defineOptions({name: 'enterprise-enterpriseRegister-joiningEnterprise'})
-const router = useRouter()
-const loginLoading = ref(false)
-const { t } = useI18n()
-
-// 企业名称下拉列表
-const getSchoolListData = async (name) => {
-  const item = formItems.value.options.find(e => e.key === 'enterpriseId')
-  if (!item) return
-  const data = await enterpriseSearchByName({ name })
-  item.items = data
-}
-
-const formItems = ref({
-  options: [
-    {
-      type: 'autocomplete',
-      key: 'enterpriseId',
-      value: null,
-      default: null,
-      label: '企业名称 *',
-      outlined: true,
-      clearable: true,
-      itemText: 'value',
-      itemValue: 'key',
-      rules: [v => !!v || '请选择企业名称'],
-      search: getSchoolListData,
-      items: []
-    },
-    {
-      type: 'text',
-      key: 'email',
-      value: '',
-      label: '职务 *',
-      rules: [v => !!v || '请输入职务']
-    },
-    {
-      type: 'text',
-      key: 'name',
-      value: '',
-      label: '姓名 *',
-      counter: 15,
-      rules: [v => !!v || '请输入姓名']
-    },
-  ]
-})
-
-// 提交
-const handleCommit = () => {
-  Snackbar.success(t('common.submittedSuccessfully'))
-  setTimeout(() => {
-    router.push({ path: '/recruit/enterprise' })
-  }, 3000);
-}
-</script>
-<style lang="scss" scoped>
-.CtFormClass {
-  margin: 0 auto;
-}
-.note {
-  color: var(--color-666);
-  font-size: 14px;
-  line-height: 32px;
-}
-.file-input-box {
-  position: relative;
-  height: 80px;
-  width: 100px;
-  border: 1px solid rgb(188, 188, 188);
-  border-radius: 5px;
-  cursor: pointer;
-  .icon {
-    position: absolute;
-    top: 45%;
-    left: 50%;
-    transform: translate(-50%, -50%);
-    color: var(--color-999);
-  }
-}
-</style>

+ 2 - 1
src/views/recruit/enterprise/jobFair/editJob.vue → src/views/recruit/enterprise/jobFair/editJob/index.vue

@@ -17,7 +17,7 @@
 <script setup>
 defineOptions({ name: 'editJob' })
 import { ref } from 'vue'
-import {  useRoute, useRouter } from 'vue-router'
+import { useRoute, useRouter } from 'vue-router'
 import CtForm from '@/components/CtForm'
 import Add from '@/views/recruit/enterprise/positionManagement/components/add.vue'
 import { useI18n } from '@/hooks/web/useI18n'
@@ -29,6 +29,7 @@ import {
 } from '@/api/recruit/enterprise/jobFair'
 import Snackbar from '@/plugins/snackbar'
 
+
 const { t } = useI18n()
 const route = useRoute()
 const router = useRouter()

+ 5 - 4
src/views/recruit/enterprise/staffChangePassword/index.vue

@@ -109,10 +109,11 @@ const handleCommit = async () => {
   Snackbar.success('修改成功')
   if (props.entChangePassword) {
     localStorage.setItem('entUpdatePassword', 'doNotNeedChange')
-    setTimeout(() => {
-      loading.value = false
-      window.location.href = '/recruit/enterprise'
-    }, 1500)
+    loading.value = false
+    // setTimeout(() => {
+    //   loading.value = false
+    //   window.location.href = '/enterprise'
+    // }, 1500)
   } else {
     loading.value = false
     router.go(-1)