2026-05-15 18:18:51 +08:00
|
|
|
import { constantRoutes } from '@/router'
|
|
|
|
|
import { getMenuList } from '@/api/system'
|
|
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
|
routes: [],
|
|
|
|
|
addRoutes: []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mutations = {
|
|
|
|
|
SET_ROUTES: (state, routes) => {
|
|
|
|
|
state.addRoutes = routes
|
|
|
|
|
state.routes = constantRoutes.concat(routes)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const actions = {
|
2026-05-17 17:24:43 +08:00
|
|
|
generateRoutes({ commit, state }) {
|
2026-05-15 18:18:51 +08:00
|
|
|
return new Promise(resolve => {
|
2026-05-17 17:24:43 +08:00
|
|
|
if (state.addRoutes.length > 0) {
|
|
|
|
|
resolve(state.addRoutes)
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-05-15 18:18:51 +08:00
|
|
|
getMenuList().then(response => {
|
|
|
|
|
const menuData = response.data || []
|
|
|
|
|
const accessedRoutes = filterAsyncRoutes(menuData)
|
|
|
|
|
commit('SET_ROUTES', accessedRoutes)
|
|
|
|
|
resolve(accessedRoutes)
|
|
|
|
|
}).catch(() => {
|
2026-05-17 17:24:43 +08:00
|
|
|
commit('SET_ROUTES', [])
|
|
|
|
|
resolve([])
|
2026-05-15 18:18:51 +08:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function filterAsyncRoutes(routes) {
|
|
|
|
|
return routes.filter(route => {
|
2026-05-17 17:24:43 +08:00
|
|
|
if (!route.component || route.component === '') {
|
2026-05-19 17:56:44 +08:00
|
|
|
route.component = () => import('@/modules/dashboardBig/views/index.vue')
|
2026-05-17 17:24:43 +08:00
|
|
|
} else if (route.component !== 'Layout') {
|
|
|
|
|
route.component = loadComponent(route.component)
|
2026-05-15 18:18:51 +08:00
|
|
|
}
|
|
|
|
|
if (route.children && route.children.length > 0) {
|
|
|
|
|
route.children = filterAsyncRoutes(route.children)
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadComponent(componentPath) {
|
2026-05-17 17:24:43 +08:00
|
|
|
const path = componentPath.replace(/^\//, '').replace(/\.vue$/, '')
|
2026-05-15 18:18:51 +08:00
|
|
|
const componentMap = {
|
2026-05-17 17:24:43 +08:00
|
|
|
'Layout': () => import('@/layout/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'),
|
2026-05-19 17:56:44 +08:00
|
|
|
'screens/acid-rolling/index': () => import('@/views/screens/acid-rolling/index.vue')
|
2026-05-15 18:18:51 +08:00
|
|
|
}
|
2026-05-19 17:56:44 +08:00
|
|
|
return componentMap[path] || (() => import('@/modules/dashboardBig/views/index.vue'))
|
2026-05-15 18:18:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
namespaced: true,
|
|
|
|
|
state,
|
|
|
|
|
mutations,
|
|
|
|
|
actions
|
2026-05-19 17:56:44 +08:00
|
|
|
}
|