feat: 更新布局、大屏页面、酸轧报表接口,调整导航栏/侧边栏联动
This commit is contained in:
@@ -14,27 +14,33 @@ const mutations = {
|
||||
}
|
||||
|
||||
const actions = {
|
||||
generateRoutes({ commit }) {
|
||||
generateRoutes({ commit, state }) {
|
||||
return new Promise(resolve => {
|
||||
// 避免重复加载
|
||||
if (state.addRoutes.length > 0) {
|
||||
resolve(state.addRoutes)
|
||||
return
|
||||
}
|
||||
getMenuList().then(response => {
|
||||
const menuData = response.data || []
|
||||
const accessedRoutes = filterAsyncRoutes(menuData)
|
||||
commit('SET_ROUTES', accessedRoutes)
|
||||
resolve(accessedRoutes)
|
||||
}).catch(() => {
|
||||
commit('SET_ROUTES', constantRoutes)
|
||||
resolve(constantRoutes)
|
||||
commit('SET_ROUTES', [])
|
||||
resolve([])
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 修复:Layout正常加载,空组件赋值首页
|
||||
function filterAsyncRoutes(routes) {
|
||||
return routes.filter(route => {
|
||||
if (route.component && route.component !== '') {
|
||||
route.component = loadComponent(route.component)
|
||||
} else {
|
||||
if (!route.component || route.component === '') {
|
||||
route.component = () => import('@/views/home/index.vue')
|
||||
} else if (route.component !== 'Layout') {
|
||||
route.component = loadComponent(route.component)
|
||||
}
|
||||
if (route.children && route.children.length > 0) {
|
||||
route.children = filterAsyncRoutes(route.children)
|
||||
@@ -44,23 +50,30 @@ function filterAsyncRoutes(routes) {
|
||||
}
|
||||
|
||||
function loadComponent(componentPath) {
|
||||
const path = componentPath.replace(/^\//, '')
|
||||
// 去除开头/和.vue后缀
|
||||
const path = componentPath.replace(/^\//, '').replace(/\.vue$/, '')
|
||||
const componentMap = {
|
||||
'home/index.vue': () => import('@/views/home/index.vue'),
|
||||
'dashboard/demo/index.vue': () => import('@/views/dashboard/demo/index.vue'),
|
||||
'dashboard/order/index.vue': () => import('@/views/dashboard/order/index.vue'),
|
||||
'dashboard/cost/index.vue': () => import('@/views/dashboard/cost/index.vue'),
|
||||
'dashboard/energy/index.vue': () => import('@/views/dashboard/energy/index.vue'),
|
||||
'screens/index.vue': () => import('@/views/screens/index.vue'),
|
||||
'screens/acid-rolling/index.vue': () => import('@/views/screens/acid-rolling/index.vue'),
|
||||
'reports/index.vue': () => import('@/views/reports/index.vue'),
|
||||
'reports/acid-rolling/index.vue': () => import('@/views/reports/acid-rolling/index.vue'),
|
||||
'reports/acid-stop/index.vue': () => import('@/views/reports/acid-stop/index.vue'),
|
||||
'system/user/index.vue': () => import('@/views/system/user/index.vue'),
|
||||
'system/role/index.vue': () => import('@/views/system/role/index.vue'),
|
||||
'system/menu/index.vue': () => import('@/views/system/menu/index.vue'),
|
||||
'system/config/index.vue': () => import('@/views/system/config/index.vue'),
|
||||
'data-source/index.vue': () => import('@/views/data-source/index.vue')
|
||||
'Layout': () => import('@/layout/index.vue'),
|
||||
'home/index': () => import('@/views/home/index.vue'),
|
||||
'modules/dashboardBig/views/index': () => import('@/modules/dashboardBig/views/index.vue'),
|
||||
'modules/dashboardBig/views/order': () => import('@/modules/dashboardBig/views/order.vue'),
|
||||
'modules/dashboardBig/views/cost': () => import('@/modules/dashboardBig/views/cost.vue'),
|
||||
'modules/dashboardBig/views/energy': () => import('@/modules/dashboardBig/views/energy.vue'),
|
||||
'modules/dashboardBig/views/oee': () => import('@/modules/dashboardBig/views/oee.vue'),
|
||||
'modules/dashboardBig/views/output': () => import('@/modules/dashboardBig/views/output.vue'),
|
||||
'modules/dashboardBig/views/stopAnalysis': () => import('@/modules/dashboardBig/views/stopAnalysis.vue'),
|
||||
'screens/list': () => import('@/views/screens/list.vue'),
|
||||
'screens/create': () => import('@/views/screens/create.vue'),
|
||||
'screens/edit': () => import('@/views/screens/edit.vue'),
|
||||
'screens/acid-rolling/index': () => import('@/views/screens/acid-rolling/index.vue'),
|
||||
'reports/index': () => import('@/views/reports/index.vue'),
|
||||
'reports/acid-rolling/index': () => import('@/views/reports/acid-rolling/index.vue'),
|
||||
'reports/acid-stop/index': () => import('@/views/reports/acid-stop/index.vue'),
|
||||
'system/user/index': () => import('@/views/system/user/index.vue'),
|
||||
'system/role/index': () => import('@/views/system/role/index.vue'),
|
||||
'system/menu/index': () => import('@/views/system/menu/index.vue'),
|
||||
'system/config/index': () => import('@/views/system/config/index.vue'),
|
||||
'data-source/index': () => import('@/views/data-source/index.vue')
|
||||
}
|
||||
return componentMap[path] || (() => import('@/views/home/index.vue'))
|
||||
}
|
||||
@@ -70,4 +83,4 @@ export default {
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user