This commit is contained in:
MeSHard
2025-11-24 15:25:50 +08:00
parent 186a92e834
commit e228528c96
14 changed files with 2624 additions and 768 deletions

View File

@@ -3,7 +3,7 @@ import router from './router'
import store from './store'
import createRoutes from '@/utils/createRoutes'
import { getDocumentTitle, resetTokenAndClearUser } from './utils'
// import { getMenuList } from './api'
// 是否有菜单数据
let hasMenus = false
router.beforeEach(async (to, from, next) => {
@@ -16,10 +16,22 @@ router.beforeEach(async (to, from, next) => {
next()
} else {
try {
let menuItems = store.state.menuItems
// let apiMenu = []
// await getMenuList({ token: localStorage.getItem('token') }).then((res) => {
// res.forEach((i) => {
// apiMenu.push({
// text: i.text,
// type: i.type,
// children: i.children,
// })
// })
// menuItems = apiMenu
// })
// 这里可以用 await 配合请求后台数据来生成路由
// const data = await axios.get('xxx')
// const routes = createRoutes(data)
const routes = createRoutes(store.state.menuItems)
const routes = createRoutes(menuItems)
// 动态添加路由
router.addRoutes(routes)
hasMenus = true