/** * @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 { ElMessage } from 'element-plus' import store from '..' // 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(); if (data.length == 0) { store.state.auth = 0 ElMessage.warning('此角色暂无分配权限,请先联系超级管理员分配权限 ! ') } else { store.state.auth = 1 } data[0].meta.affix = false data.unshift({ path: "/home", hidden: false, redirect: "/index/index", component: "Layout", meta: { title: "数据看板", icon: "home", }, children: [{ path: "/index/index", hidden: false, component: "@/views/index/index", meta: { title: "数据看板", icon: "home", affix: true } }] }) data.push({ path: "/tenantManage", hidden: false, redirect: "/tenantManage/tenantUnit", component: "Layout", meta: { title: "租户管理", icon: "systemManage", }, children: [{ meta: { title: "租户单位配置", icon: "systemManage", }, path: "/tenantUnit", hidden: false, component: "@/views/tenantManage/tenantUnit", }, { meta: { title: "管理员配置", icon: "systemManage", }, path: "/adminConfig", hidden: false, component: "@/views/tenantManage/adminConfig", }, { meta: { title: "系统配置", icon: "systemManage", }, path: "/systemConfig", hidden: false, component: "@/views/tenantManage/systemConfig", }, { meta: { title: "权限配置", icon: "systemManage", }, path: "/authConfig", hidden: false, component: "@/views/tenantManage/authConfig", }, ] }) // data.push({ // "path": "/systemManage", // "hidden": false, // "redirect": "/systemManage/userManage", // "component": "Layout", // "meta": { // "title": "租户管理", // "icon": "systemManage", // "affix": null // }, // "children": [{ // "path": "userManage", // "hidden": false, // "component": "@/views/systemManage/userManage/index", // "meta": { // "title": "租户单位配置", // "icon": "systemManage", // "affix": null // } // }, { // "path": "rolePermission1", // "hidden": false, // "component": "@/views/tenantManage/rolePermission1/index", // "meta": { // "title": "管理员配置", // "icon": "systemManage", // "affix": null // } // }] // }) data.forEach(function(item) { if (item.children.length > 1) { item.children.forEach(function(i) { i.meta.icon = '' }) } }) console.log('data') console.log(data) store.state.middleList = 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 }