123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- /**
- * @author chuzhixin 1204505056@qq.com
- * @description 路由拦截状态管理,目前两种模式:all模式与intelligence模式,其中partialRoutes是菜单暂未使用
- */
- import { asyncRoutes, constantRoutes } from '@/router'
- import { getRouterList } from '@/api/router'
- import { convertRouter, filterRoutes } from '@/utils/routes'
- // import { Layout } from 'ant-design-vue'
- const state = () => ({
- routes: [],
- partialRoutes: [],
- })
- const getters = {
- routes: (state) => state.routes,
- partialRoutes: (state) => state.partialRoutes,
- }
- const mutations = {
- setRoutes(state, routes) {
- state.routes = routes
- },
- setPartialRoutes(state, routes) {
- state.partialRoutes = routes
- },
- }
- const actions = {
- /**
- * @author chuzhixin 1204505056@qq.com
- * @description intelligence模式设置路由
- * @param {*} { commit }
- * @returns
- */
- async setRoutes({ commit }) {
- const finallyRoutes = filterRoutes([...constantRoutes, ...asyncRoutes])
- commit('setRoutes', finallyRoutes)
- return [...asyncRoutes]
- },
- /**
- * @author chuzhixin 1204505056@qq.com
- * @description all模式设置路由
- * @param {*} { commit }
- * @returns
- */
- async setAllRoutes({ commit }) {
- let { data } = await getRouterList()
- // let data = [
- // {
- // path: 'external-link',
- // component: "Layout",
- // children: [{
- // path: '/home',
- // meta: { title: '首页', icon: 'home', }
- // }]
- // },
- // {
- // path: '/',
- // redirect: '/alarmManage/index',
- // meta: {
- // title: '告警管理',
- // icon: 'alarmManage',
- // affix: true,
- // },
- // component: "Layout",
- // children: [{
- // meta: {
- // title: '告警管理',
- // icon: 'alarmManage',
- // },
- // path: '/alarmManage/index',
- // component: '@/views/alarmManage/index',
- // },]
- // }
- // ]
- data.unshift({
- path: 'external-link',
- component: 'Layout',
- children: [{
- path: '/home',
- meta: { title: '首页', icon: 'home', }
- }]
- }, )
- console.log('data')
- console.log(data)
- if (data[data.length - 1].path !== '*')
- data.push({ path: '/*', redirect: '/404', hidden: true })
- const asyncRoutes = convertRouter(data)
- const finallyRoutes = filterRoutes([...constantRoutes, ...asyncRoutes])
- commit('setRoutes', finallyRoutes)
- return [...asyncRoutes]
- },
- /**
- * @author chuzhixin 1204505056@qq.com
- * @description 画廊布局、综合布局设置路由
- * @param {*} { commit }
- * @param accessedRoutes 画廊布局、综合布局设置路由
- */
- setPartialRoutes({ commit }, accessedRoutes) {
- commit('setPartialRoutes', accessedRoutes)
- },
- }
- export default { state, getters, mutations, actions }
|