updated plugin framework: allow adding views

This commit is contained in:
Marvin Zhang
2021-09-01 16:14:44 +08:00
parent 78cb4ba616
commit 04667ac8a7
2 changed files with 22 additions and 4 deletions

View File

@@ -17,7 +17,7 @@ export const routes: Array<RouteRecordRaw> = [
...login,
{
path: '/',
name: '',
name: 'Root',
component: () => import('@/layouts/BasicLayout.vue'),
children: [
...home,

View File

@@ -41,7 +41,10 @@ const initPluginSidebarMenuItems = (store: Store<RootStoreState>) => {
};
const addPluginRouteTab = (store: Store<RootStoreState>, p: Plugin, pc: PluginUIComponent) => {
// current routes paths
const routesPaths = router.getRoutes().map(r => r.path);
// iterate parent paths
pc.parent_paths?.forEach(parentPath => {
// plugin route path
const pluginPath = `${parentPath}/${pc.path}`;
@@ -73,8 +76,22 @@ const addPluginRouteTab = (store: Store<RootStoreState>, p: Plugin, pc: PluginUI
});
};
const addPluginRouteView = (store: Store<RootStoreState>, pc: PluginUIComponent) => {
// TODO: implement
const addPluginRouteView = (p: Plugin, pc: PluginUIComponent) => {
// current routes paths
const routesPaths = router.getRoutes().map(r => r.path);
// plugin route path
const pluginPath = pc.path;
// skip if plugin route already added
if (routesPaths.includes(pluginPath as string)) return;
// add route
router.addRoute('Root', {
name: pc.name,
path: pc.path as string,
component: () => loadModule(`${PLUGIN_PROXY_ENDPOINT}/${p.name}/${pc.src}`)
});
};
const initPluginRoutes = (store: Store<RootStoreState>) => {
@@ -91,7 +108,7 @@ const initPluginRoutes = (store: Store<RootStoreState>) => {
switch (pc.type) {
case PLUGIN_UI_COMPONENT_TYPE_VIEW:
addPluginRouteView(store, pc);
addPluginRouteView(p, pc);
break;
case PLUGIN_UI_COMPONENT_TYPE_TAB:
addPluginRouteTab(store, p, pc);
@@ -99,6 +116,7 @@ const initPluginRoutes = (store: Store<RootStoreState>) => {
}
});
});
console.debug(router.getRoutes());
};
export const initPlugins = async (store: Store<RootStoreState>) => {