Skip to content

Commit

Permalink
fix plugin some problem
Browse files Browse the repository at this point in the history
  • Loading branch information
northseadl committed Oct 25, 2023
1 parent 543eb7f commit 28b2c58
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/router/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function loadPluginRoutes(router: any) {
setTimeout(() => {
router.removeRoute(pluginRoute.name as string);
router.addRoute(pluginRoute);
}, 2000);
}, 1000);
};
// find from session storage
const cacheRoutes = sessionStorage.getItem('plugin-routes');
Expand Down
6 changes: 4 additions & 2 deletions src/utils/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function CreateWujieComponent(option: Option) {
},
template: `
<div class="container">
<WujieVue3 v-bind="option" />
<WujieVue3 v-bind="option"/>
</div>
`,
});
Expand All @@ -38,8 +38,10 @@ export function BuildPluginRoutes(
key: route.name,
name: route.name,
url: `${pluginEndpoint}${route.path}`,
alive: true,
sync: true
});
route.path = `/plugin${route.path}`;
route.path = `/powerx-plugins${route.path}`;
return route as AppRouteRecordRaw;
});
}
43 changes: 39 additions & 4 deletions src/views/not-found/index.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
<template>
<div class="content">
<a-result class="result" status="404" :subtitle="'not found'"> </a-result>
<div class="operation-row">
<a-button key="back" type="primary" @click="back"> back </a-button>
<div v-if="state.isPlugin">
<span v-if="!state.loading">未找到插件</span>
</div>
<div v-else>
<a-result class="result" status="404" :subtitle="'not found'"> </a-result>
<div class="operation-row">
<a-button key="back" type="primary" @click="back"> back </a-button>
</div>
</div>
</div>
</template>

<script lang="ts" setup>
import { useRouter } from 'vue-router';
import { useRouter, useRoute } from 'vue-router';
import { reactive, watchEffect } from 'vue'
const router = useRouter();
const route = useRoute();
const state = reactive({
isPlugin: false,
loading: false
})
watchEffect(() => {
if (route.path.startsWith('/powerx-plugins')) {
state.isPlugin = true;
state.loading = true;
const pathSegments = route.path.split('/').slice(0, 3);
const newPath = pathSegments.join('/');
let retryCount = 0;
const interval = setInterval(() => {
const pluginRoute = router.getRoutes().find((r) => r.path === newPath);
if (pluginRoute) {
clearInterval(interval);
router.push({ name: pluginRoute.name });
} else {
retryCount += 1;
if (retryCount >= 5) {
clearInterval(interval);
}
}
}, 500);
}
});
const back = () => {
// warning: Go to the node that has the permission
router.push({ name: 'Home' });
Expand Down

0 comments on commit 28b2c58

Please sign in to comment.