web.src.store.menu.index.ts Maven / Gradle / Ivy
/**
* @name: 菜单store
* @author: itmobai
* @date: 2023-02-17 15:09
* @description:菜单store
* @update: 2023-02-17 15:09
*/
import router from '@/router';
import {getMenuApi} from '@/apis/core';
import {generateRoutes} from '@/utils/common';
const state = {
menuList: [],
menuType: 0
}
const mutations = {
SET_MENUS(state: any, menus: any) {
state.menuList = menus;
}
}
const actions = {
getMenuRole(ctx: any) {
return new Promise(resolve => {
getMenuApi().then(e => {
let route =
{
id: 0,
pid: 0,
sort: 1,
path: "/home",
name: "home",
redirect: null,
menuType: null,
component: "/home/index.vue",
meta: {
title: "主页",
isLink: null,
isHide: false,
isKeepAlive: false,
isAffix: false,
isIframe: false,
auth: "admin",
icon: null
},
children: []
}
let menus = [route, ...e] || [route];
console.log(menus,'menus')
ctx.commit("SET_MENUS", menus)
router.addRoutes(generateRoutes(menus))
resolve(null)
}
)
})
}
}
export default {
namespaced: true,
state,
mutations,
actions
}