Skip to content

Commit

Permalink
feat(server-client): impl dynamic router for app
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Sep 2, 2021
1 parent 0aa9288 commit 0f7f74d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 46 deletions.
76 changes: 32 additions & 44 deletions packages/system-client/src/router/async.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import Layout from '@/layout'
import Layout from '@/layout/app.vue'

/**
* asyncRoutes
* the routes that need to be dynamically loaded based on user roles
*/
export const asyncRoutes = [
{
path: '/development',
path: '/app/:appid/dashboard',
component: Layout,
hidden: true,
children: [
{
path: 'index',
component: () => import('@/views/dashboard/index'),
name: 'Dashboard',
meta: { title: '欢迎', icon: 'dashboard', noCache: true }
}
]
},
{
path: '/app/:appid/development',
component: Layout,
redirect: '/development/functions',
meta: {
title: '开发控制台', icon: 'example'
title: '云函数', icon: 'example'
},
children: [
{
Expand All @@ -20,7 +32,7 @@ export const asyncRoutes = [
meta: {
title: '云函数',
icon: 'bug',
permissions: ['function.read']
noCache: true
}
},
{
Expand All @@ -30,8 +42,7 @@ export const asyncRoutes = [
hidden: true,
meta: {
title: '调试云函数',
icon: 'bug',
permissions: ['function.read']
icon: 'bug'
}
},
{
Expand All @@ -40,8 +51,7 @@ export const asyncRoutes = [
name: 'AllFunctionLogs',
meta: {
title: '云函数日志',
icon: 'documentation',
permissions: ['function.read', 'function.edit', 'function.create', 'function.debug']
icon: 'documentation'
}
},
{
Expand All @@ -51,8 +61,7 @@ export const asyncRoutes = [
hidden: true,
meta: {
title: '云函数日志',
icon: 'lock',
permissions: ['function_logs.read', 'function.read', 'function.edit', 'function.create', 'function.debug']
icon: 'lock'
}
},
{
Expand All @@ -62,19 +71,16 @@ export const asyncRoutes = [
hidden: true,
meta: {
title: '云函数触发器',
icon: 'lock',
permissions: ['trigger.read', 'trigger.edit', 'trigger.create', 'trigger.delete']
icon: 'lock'
}
}
]
},
{
path: '/database',
path: '/app/:appid/database',
component: Layout,
redirect: '/database/collections',
meta: {
title: '数据管理', icon: 'excel',
permissions: ['policy.read']
title: '数据管理', icon: 'excel'
},
children: [
{
Expand All @@ -84,8 +90,7 @@ export const asyncRoutes = [
meta: {
title: '访问策略',
icon: 'eye',
noCache: true,
permissions: ['policy.read']
noCache: true
}
},
{
Expand All @@ -104,8 +109,7 @@ export const asyncRoutes = [
name: 'CollectionManagement',
meta: {
title: '集合管理',
icon: 'example',
permissions: ['database.manage', 'collections.get', 'collections.createIndex', 'collections.deleteIndex']
icon: 'example'
}
},
{
Expand All @@ -115,8 +119,7 @@ export const asyncRoutes = [
meta: {
title: '文件管理',
icon: 'zip',
noCache: true,
permissions: ['file.read']
noCache: true
}
},
{
Expand All @@ -127,42 +130,27 @@ export const asyncRoutes = [
meta: {
title: '文件列表',
icon: 'documentation',
noCache: false,
permissions: ['file.read']
noCache: false
}
}
]
},
{
path: '/system',
path: '/app/:appid/collaborators',
component: Layout,
redirect: '/system/role',
meta: {
title: '成员管理', icon: 'peoples',
permissions: ['admin.read'],
noCache: true
},
children: [
{
path: 'admin',
path: 'index',
component: () => import('@/views/system/admin'),
name: 'AdminListPage',
name: 'CollaboratorListPage',
meta: {
title: '开发者',
title: '成员管理',
icon: 'people',
noCache: true,
permissions: ['admin.read']
}
},
{
path: 'role',
component: () => import('@/views/system/role'),
name: 'RoleListPage',
meta: {
title: '角色',
icon: 'user',
noCache: true,
permissions: ['role.edit', 'role.create']
noCache: true
}
}
]
Expand Down
3 changes: 2 additions & 1 deletion packages/system-client/src/router/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ export const constantRoutes = [
path: '/',
component: Layout,
redirect: '/applications',
hidden: true,
children: [
{
path: 'applications',
component: () => import('@/views/application/index'),
name: 'Application',
meta: { title: '主页', icon: 'dashboard', affix: true, noCache: true }
meta: { title: '我的应用', icon: 'dashboard', noCache: true }
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/system-client/src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Vue from 'vue'
import Router from 'vue-router'
import { constantRoutes } from './constants'

Vue.use(Router)

export { asyncRoutes } from './async'
export { constantRoutes } from './constants'
import { constantRoutes } from './constants'

/**
* Note: sub-menu only appear when route children.length >= 1
Expand Down

0 comments on commit 0f7f74d

Please sign in to comment.