permission_routes.js 1.19 KB
import util from '@/libs/util.js'
import router from '@router'
import { getNavigation } from '@/api/navigation.js'

const getState = () => {
  return {
    navigation: [],
    routerList:[]
  }
}
const state = getState()
const mutations = {
  GET_NAVIGATION: (state,navigation) => {
    state.navigation = navigation
  }
}

const actions = {
  // 在这里处理后台返回的数据加载左边菜单栏
  getMenus({ commit }) {
    return new Promise((resolve, reject) => {
      getNavigation().then(response => {
        commit('GET_NAVIGATION', response.data)
        // filterAsyncRoutes(data.menuList)
        util.cookies.set('navigation-1',response.data.slice(0,1))
        util.cookies.set('navigation',response.data.slice(1))
        router.push('/panel')
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  },
}
// 在这里处理路由表信息
export function filterAsyncRoutes(routes) {
  routes.map(v => {
    const { path, name } = v
    // 重新构建路由对象
    const item = {
      path,
      name,
      component: () => import(`@/views/${component}`),
      // redirect,
    }
  })

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}