1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import { Module } from 'vuex';
- import { useAsRouter } from '@/hooks/useAsRouter';
- import { routesModuleList } from '@/router/dynamic';
- import { LayoutRoute } from '@/router/routes';
- import { GetUserMenulist } from '@/apis/models';
-
- const { routerDynamic, routerAdd, routerInit } = useAsRouter();
-
-
- export interface PermissionState {
- arrresult : string[];
- menuList : string[];
- permissionList : string[] | null;
- breadcrumbList : string[];
- }
-
- const state : PermissionState = {
- arrresult: [],
- menuList: [],
- permissionList: null,
- breadcrumbList: []
- };
-
- const mutations = {
- SET_PERMISSION(state, routes) {
- state.permissionList = routes
- },
- SET_MENU(state, menu) {
- state.menuList = menu
- }
- };
-
- const actions = {
- async FETCH_PERMISSION({
- state,
- commit
- }) {
- try {
- state.arrresult = [];
- let res = await GetUserMenulist();
- res.data.menulist.map(item => {
- pushItem(item)
- })
- let arr = state.arrresult;
- // 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'];
- let routes = routerDynamic(arr, res.data.menulist);
- LayoutRoute.children.push(...routes);
- commit('SET_MENU', LayoutRoute.children);
- routerAdd(LayoutRoute);
- let initialRoutes = routerInit();
- commit('SET_PERMISSION', [...initialRoutes]);
- } catch {
-
- }
- }
- };
-
- const pushItem = (item : Object) => {
- state.arrresult.push(item.action)
- if (item.childs) {
- for (const child of item.childs) {
- pushItem(child)
- }
- }
-
- return state.arrresult;
- }
-
-
-
-
- export const permissionsModule : Module<PermissionState> = {
- namespaced: true,
- state,
- mutations,
- actions
- };
|