@/router#asyncRoutes JavaScript Examples

The following examples show how to use @/router#asyncRoutes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: permission.js    From fund_management-eastmoney with Apache License 2.0 6 votes vote down vote up
actions = {
  generateRoutes({ commit }, roles) {
    return new Promise(resolve => {
      let accessedRoutes
      if (roles.includes('admin')) {
        accessedRoutes = asyncRoutes || []
      } else {
        accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)
      }
      commit('SET_ROUTES', accessedRoutes)
      resolve(accessedRoutes)
    })
  }
}
Example #2
Source File: routes.js    From vue-admin-better-template with Mozilla Public License 2.0 6 votes vote down vote up
actions = {
  async setRoutes({ commit }, permissions) {
    //开源版只过滤动态路由permissions,admin不再默认拥有全部权限
    const finallyAsyncRoutes = await filterAsyncRoutes(
      [...asyncRoutes],
      permissions
    )
    commit('setRoutes', finallyAsyncRoutes)
    return finallyAsyncRoutes
  },
  async setAllRoutes({ commit }) {
    let { data } = await getRouterList()
    data.push({ path: '*', redirect: '/404', hidden: true })
    let accessRoutes = convertRouter(data)
    commit('setAllRoutes', accessRoutes)
    return accessRoutes
  },
  setPartialRoutes({ commit }, accessRoutes) {
    commit('setPartialRoutes', accessRoutes)
    return accessRoutes
  },
}
Example #3
Source File: permission.js    From ferry_web with GNU Lesser General Public License v3.0 6 votes vote down vote up
actions = {
  generateRoutes({ commit }, roles) {
    return new Promise(resolve => {
      const loadMenuData = []

      getRoutes().then(response => {
        // console.log(JSON.stringify(response))
        let data = response
        if (response.code !== 200) {
          this.$message({
            message: '菜单数据加载异常',
            type: 0
          })
        } else {
          data = response.data
          Object.assign(loadMenuData, data)

          generaMenu(asyncRoutes, loadMenuData)
          asyncRoutes.push({ path: '*', redirect: '/404', hidden: true })
          commit('SET_ROUTES', asyncRoutes)
          resolve(asyncRoutes)
        }
      }).catch(error => {
        console.log(error)
      })
    })
  }
}
Example #4
Source File: permission.js    From NCF with Apache License 2.0 5 votes vote down vote up
actions = {
  generateRoutes({commit}, {roleCodes, menuTree}) {
    return new Promise(resolve => {
      let accessedRoutes
      //超级管理员(administrator)有全部异步路由的权限
      if (roleCodes.includes('administrator')) {
        accessedRoutes = asyncRoutes || []
      } else {
        accessedRoutes = filterAsyncRoutes(asyncRoutes, menuTree)
      }
      state.accessedRoutes = accessedRoutes
      commit('SET_ROUTES', accessedRoutes)
      resolve(accessedRoutes)
    })
  },
  setRoutes({commit}, routes) {
    console.log(777,routes)
    console.log("moduleRouter",moduleRouter)
    let list = {...moduleRouter, ...{}}

    //是否是远程加载的路由
    routes.forEach(item => {
      if (item.name === 'b-home1') {
        console.log('item',item.name)
        item.meta = {
          title: '拓展模块b-home1'
        }
        list.children.push(item)
      }
      if (item.name === 'b-about1') {
        item.meta = {
          title: '拓展模块b-about1'
        }
        list.children = [...list.children, ...[item]]
      }
    })
    console.log('list',list)
    state.accessedRoutes.forEach((item,index)=>{
      if(item.name==='Module'){
        console.log(index,item.name)
        state.accessedRoutes[index] = list
        // state.accessedRoutes[index].children = [
        //   ...state.accessedRoutes[index].children,
        //   ...
        //   [{
        //   "path": "/Admin/AdminUserInfo/Index",
        //   "name": "管理员管理",
        //   "meta": {
        //     "title": "管理员管理"
        //   }
        // },
        //   {
        //     "path": "/Admin/Role/Index",
        //     "name": "角色管理",
        //     "meta": {
        //       "title": "角色管理"
        //     }
        //   }]
        // ]
      }
    })

    // list = [...state.accessedRoutes, ...list]
    console.log('路由state.accessedRoutes',state.accessedRoutes)
    commit('SET_ROUTES', state.accessedRoutes)
  }
}
Example #5
Source File: permission.js    From EduAdmin with MIT License 4 votes vote down vote up
actions = {
  generateRoutes({ commit }) {
    return new Promise(async resolve => {
      if (!store.getters.manager.tel) {
        await store.dispatch('manager/getInfo')
      }
      let accessedRoutes
      // if (store.getters.manager.role == 1) {
      //   // 分校工作员
      //   accessedRoutes = asyncRoutes || []
      // } else {
        // 管理员
        accessedRoutes = filterAsyncRoutes(asyncRoutes, store.getters.manager.role)
      // }

      // const topPlatformRoute = {
      //   path: '/platform',
      //   component: Layout,
      //   redirect: 'noRedirect',
      //   alwaysShow: true,
      //   name: 'platform',
      //   meta: {
      //     title: 'platform',
      //     icon: 'nested'
      //   },
      //   children: [
      //   ]
      // }
      let myPlatformList = store.getters.manager.myPlatformList; 
      if (myPlatformList) {
        let index = 0;
        myPlatformList.forEach(platform => {
          index++;
          const platformRoute = {
            path: '/platform/' + index.toString(10),// platform.Id,
            redirect: 'noRedirect',
            component: Layout,
            name: platform.Id,
            meta: { title: platform.Label, icon: "platform" },
            children: [
              {
                path: 'web',
                redirect: 'noRedirect',
                component: () => import('@/views/web/container'), // Parent router-view
                name: 'web' + platform.Id.toString(10),
                meta: { title: 'web', icon: "website" },
                children: [
                  {
                    path: 'banner/' + platform.Id.toString(10),
                    component: () => import('@/views/web/banner'),
                    name: 'banner' + index.toString(10),
                    meta: { title: 'banner', icon: "banner" }
                  },
                  {
                    path: 'docDownload/' + platform.Id.toString(10),
                    name: 'docDownload' + index.toString(10),
                    component: () => import('@/views/web/docDownload'),
                    meta: { title: 'docDownload', icon: "download" }
                  },
                  {
                    path: 'news/' + platform.Id.toString(10),
                    name: 'newsList' + index.toString(10),
                    component: () => import('@/views/web/news'),
                    meta: { title: 'news', icon: "news" }
                  },
                  {
                    path: 'jingsai/' + platform.Id.toString(10),
                    name: 'jingsai' + index.toString(10),
                    component: () => import('@/views/web/jingsai'),
                    meta: { title: 'jingsai', icon: "jingsai" }
                  },
                  {
                    path: 'teacher/' + platform.Id.toString(10),
                    name: 'teacher' + index.toString(10),
                    component: () => import('@/views/web/teacher'),
                    meta: { title: 'teacher', icon: "hotteacher" }
                  },
                  {
                    path: 'linker/' + platform.Id.toString(10),
                    name: 'linker' + index.toString(10),
                    component: () => import('@/views/web/linker'),
                    meta: { title: 'linker', icon: "linker" }
                  }
                ]
              },
              {
                path: 'managers/' + platform.Id,
                component: () => import('@/views/system/managerlist'),
                name: 'managerList' + index.toString(10),
                meta: { title: 'managerList', icon: "user" },

              }
              ,
              {
                path: 'list/' + platform.Id,
                component: () => import('@/views/custom/customList'),
                name: 'customList' + index.toString(10),
                meta: { title: 'platformCustom', icon: 'student' }
              },
              {
                path: 'classList/' + platform.Id,
                component: () => import('@/views/platform/classList'), // Parent router-view
                name: "classList" + index.toString(10),
                meta: { title: "classList", icon: "platform" }
              },
              {
                path: 'contractList/' + platform.Id,
                component: () => import('@/views/custom/contractList'),
                name: 'contractList' + index.toString(10),
                meta: { title: 'contractList', icon: 'contract' }
              }
            ]
          }
          accessedRoutes.push(platformRoute) 
        })
      }
      // accessedRoutes.push(topPlatformRoute)
      commit('SET_ROUTES', accessedRoutes)
      resolve(accessedRoutes)
    })
  }
}