index.js 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import Vue from 'vue';
  2. import VueRouter from 'vue-router';
  3. import HomeView from '@/views/HomeView.vue';
  4. import { getToken } from '@/utils/token-util';
  5. Vue.use(VueRouter);
  6. let routerInstance = null;
  7. export function getRouter() { return routerInstance; }
  8. const dev = process.env.NODE_ENV === 'development';
  9. const routes = [
  10. { path: '/login', name: 'login', component: () => import('@/views/login/index.vue'), meta: { title: '登录', public: true, fullPage: true } },
  11. { path: '/', name: 'home', component: HomeView, meta: { title: '首页', public: dev } },
  12. { path: '/organization', name: 'organization', component: () => import('@/views/organization/index.vue'), meta: { title: '组织架构', public: dev } },
  13. { path: '/position-management', name: 'positionManagement', component: () => import('@/views/positionManagement/index.vue'), meta: { title: '岗位设定', public: dev } },
  14. { path: '/position-sequence', name: 'positionSequence', component: () => import('@/views/positionSequence/index.vue'), meta: { title: '岗位序列', public: dev } },
  15. { path: '/position-application', name: 'positionApplication', component: () => import('@/views/positionApplication/index.vue'), meta: { title: '岗位申请', public: dev } },
  16. { path: '/employee-archive', name: 'employeeArchive', component: () => import('@/views/employeeArchive/index.vue'), meta: { title: '员工档案', public: dev } },
  17. { path: '/performance-scoring', name: 'performanceScoring', component: () => import('@/views/performanceScoring/index.vue'), meta: { title: '绩效评分', public: dev } },
  18. { path: '/performance-scheme', name: 'performanceScheme', component: () => import('@/views/performanceScheme/index.vue'), meta: { title: '绩效方案', public: dev } },
  19. { path: '/personnel-structure-dashboard', name: 'personnelStructureDashboard', component: () => import('@/views/personnelStructureDashboard/index.vue'), meta: { title: '人员结构看板', public: dev } },
  20. { path: '/personnel-structure-analysis-board', name: 'personnelStructureAnalysisBoard', component: () => import('@/views/personnelStructureAnalysisBoard/index.vue'), meta: { title: '人员结构分析看板', public: dev } },
  21. { path: '/recruitment-plan', name: 'recruitmentPlan', component: () => import('@/views/recruitmentPlan/index.vue'), meta: { title: '招聘需求计划', public: dev } },
  22. { path: '/talent-pool', name: 'talentPool', component: () => import('@/views/talentPool/index.vue'), meta: { title: '人才库', public: dev } },
  23. { path: '/onboarding-contract-template', name: 'onboardingContractTemplate', component: () => import('@/views/onboardingContractTemplate/index.vue'), meta: { title: '入职合同模板', public: dev } },
  24. { path: '/regularization-handling', name: 'regularizationHandling', component: () => import('@/views/regularizationHandling/index.vue'), meta: { title: '转正办理', public: dev } },
  25. { path: '/regularization-template', name: 'regularizationTemplate', component: () => import('@/views/regularizationTemplate/index.vue'), meta: { title: '转正申请模板', public: dev } },
  26. { path: '/onboarding-handling', name: 'onboardingHandling', component: () => import('@/views/onboardingHandling/index.vue'), meta: { title: '办理入职', public: dev } },
  27. { path: '/resignation-letter', name: 'resignationLetter', component: () => import('@/views/resignationLetter/index.vue'), meta: { title: '辞职申请书', public: dev } },
  28. { path: '/resignation-application', name: 'resignationApplication', component: () => import('@/views/resignationApplication/index.vue'), meta: { title: '离职申请', public: dev } },
  29. { path: '/resignation-handover-order', name: 'resignationHandoverOrder', component: () => import('@/views/resignationHandoverOrder/index.vue'), meta: { title: '离职交接单', public: dev } },
  30. { path: '/resignation-handover-table', name: 'resignationHandoverTable', component: () => import('@/views/resignationHandoverTable/index.vue'), meta: { title: '离职交接表', public: dev } },
  31. { path: '/resignation-certificate', name: 'resignationCertificate', component: () => import('@/views/resignationCertificate/index.vue'), meta: { title: '离职证明', public: dev } }
  32. ];
  33. export default function createRouter(routerBase) {
  34. const router = new VueRouter({ mode: 'history', base: window.__POWERED_BY_QIANKUN__ ? routerBase || process.env.VUE_APP_QIANKUN_ACTIVE_RULE : process.env.VUE_APP_PUBLIC_PATH, routes, scrollBehavior: () => ({ x: 0, y: 0 }) });
  35. routerInstance = router;
  36. router.beforeEach((to, from, next) => {
  37. if (to.meta && to.meta.title) document.title = `${to.meta.title} - ${process.env.VUE_APP_NAME}`;
  38. if (!window.__POWERED_BY_QIANKUN__ && !to.meta?.public && !getToken()) { next({ path: '/login', query: to.fullPath === '/' ? {} : { from: to.fullPath } }); return; }
  39. if (to.path === '/login' && getToken()) { next('/'); return; }
  40. next();
  41. });
  42. return router;
  43. }