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 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Module } from 'vuex';
  2. import { useAsRouter } from '@/hooks/useAsRouter';
  3. import { routesModuleList } from '@/router/dynamic';
  4. import { LayoutRoute } from '@/router/routes';
  5. import { GetUserMenulist } from '@/apis/models';
  6. const { routerDynamic, routerAdd, routerInit } = useAsRouter();
  7. export interface PermissionState {
  8. arrresult : string[];
  9. menuList : string[];
  10. permissionList : string[] | null;
  11. breadcrumbList : string[];
  12. }
  13. const state : PermissionState = {
  14. arrresult: [],
  15. menuList: [],
  16. permissionList: null,
  17. breadcrumbList: []
  18. };
  19. const mutations = {
  20. SET_PERMISSION(state, routes) {
  21. state.permissionList = routes
  22. },
  23. SET_MENU(state, menu) {
  24. state.menuList = menu
  25. }
  26. };
  27. const actions = {
  28. async FETCH_PERMISSION({
  29. state,
  30. commit
  31. }) {
  32. try {
  33. state.arrresult = [];
  34. let res = await GetUserMenulist();
  35. res.data.menulist.map(item => {
  36. pushItem(item)
  37. })
  38. let arr = state.arrresult;
  39. // let arr = ['permission', 'role', 'account', 'company', 'vip', 'member', 'homemake', 'homemakeType', 'homemakePosition', 'homemakeDemand', 'homemakeAppointment', 'job', 'department', 'jobSeeker', 'jobResume', 'jobFair', 'jobFairList', 'jobFairCompany', 'information', 'section', 'article', 'list', 'putIn', 'advertisementList', 'advertisement', 'activity', 'activityList', 'activityAddress', 'statistics', 'statisticsResume', 'statisticsResumeMajor'];
  40. let routes = routerDynamic(arr, res.data.menulist);
  41. LayoutRoute.children.push(...routes);
  42. commit('SET_MENU', LayoutRoute.children);
  43. routerAdd(LayoutRoute);
  44. let initialRoutes = routerInit();
  45. commit('SET_PERMISSION', [...initialRoutes]);
  46. } catch {
  47. }
  48. }
  49. };
  50. const pushItem = (item : Object) => {
  51. state.arrresult.push(item.action)
  52. if (item.childs) {
  53. for (const child of item.childs) {
  54. pushItem(child)
  55. }
  56. }
  57. return state.arrresult;
  58. }
  59. export const permissionsModule : Module<PermissionState> = {
  60. namespaced: true,
  61. state,
  62. mutations,
  63. actions
  64. };