1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /**
- * @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()
- // data[4].redirect = "/dataManage/sameAnalysis"
- console.log('data')
- console.log(data)
- data.unshift({
- path: 'external-link',
- component: 'Layout',
- children: [{
- path: '/home',
- meta: { title: '首页', icon: 'home', }
- }]
- }, )
- // 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 }
|