招聘网页
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

usePermissionStore.ts 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { Module } from 'vuex';
  2. import { useAsRouter } from '@/hooks/useAsRouter';
  3. import { routesModuleList } from '@/router/dynamic';
  4. import { routesManageModuleList } from '@/router/manageDynamic';
  5. import { routesJobseekerModuleList } from '@/router/jobseekerDynamic';
  6. import { LayoutRoute } from '@/router/routes';
  7. const { routerDynamic, routerAdd, routerInit } = useAsRouter();
  8. const NotFound = {
  9. path: '/:pathMatch(.*)*',
  10. name: 'NotFound',
  11. component: () => import('@/views/404.vue'),
  12. meta: {
  13. title: '系统找不到页面',
  14. }
  15. }
  16. export interface PermissionState {
  17. menuList : string[];
  18. permissionList : string[] | null;
  19. breadcrumbList : string[];
  20. }
  21. const state : PermissionState = {
  22. menuList: [],
  23. permissionList: null,
  24. breadcrumbList: []
  25. };
  26. const mutations = {
  27. SET_PERMISSION(state, routes) {
  28. state.permissionList = routes
  29. },
  30. SET_MENU(state, menu) {
  31. state.menuList = menu
  32. }
  33. };
  34. const actions = {
  35. async FETCH_PERMISSION({
  36. commit,rootState
  37. }) {
  38. try {
  39. // let res = await LOGIN.permissions();
  40. // let arr = res.data.data;
  41. console.log(rootState)
  42. if(rootState.token && rootState.role === 'company' && rootState.pageType == 'company' ) {
  43. LayoutRoute.children = [];
  44. commit('SET_MENU', []);
  45. commit('SET_PERMISSION', null);
  46. LayoutRoute.children = routesManageModuleList;
  47. commit('SET_MENU', LayoutRoute.children);
  48. routerAdd(LayoutRoute);
  49. routerAdd(NotFound);
  50. let initialRoutes = routerInit();
  51. commit('SET_PERMISSION', [...initialRoutes]);
  52. } else if(rootState.token && rootState.role === 'personal' && rootState.pageType == 'personal'){
  53. LayoutRoute.children = [];
  54. commit('SET_MENU', []);
  55. commit('SET_PERMISSION', null);
  56. LayoutRoute.children = routesJobseekerModuleList;
  57. commit('SET_MENU', LayoutRoute.children);
  58. routerAdd(LayoutRoute);
  59. routerAdd(NotFound);
  60. let initialRoutes = routerInit();
  61. commit('SET_PERMISSION', [...initialRoutes]);
  62. } else {
  63. LayoutRoute.children = [];
  64. commit('SET_MENU', []);
  65. commit('SET_PERMISSION', null);
  66. LayoutRoute.children = routesModuleList;
  67. commit('SET_MENU', LayoutRoute.children);
  68. routerAdd(LayoutRoute);
  69. routerAdd(NotFound);
  70. let initialRoutes = routerInit();
  71. commit('SET_PERMISSION', [...initialRoutes]);
  72. }
  73. } catch {
  74. }
  75. }
  76. };
  77. export const permissionsModule : Module<PermissionState> = {
  78. namespaced: true,
  79. state,
  80. mutations,
  81. actions
  82. };