fix: reset current dashboard due to pages forwarding (#34)

This commit is contained in:
Fine0830 2022-03-23 13:28:47 +08:00 committed by GitHub
parent 049f46a4cf
commit 93161b6ec9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 86 additions and 141 deletions

View File

@ -27,17 +27,24 @@ export const routesInfra: Array<RouteRecordRaw> = [
exact: true, exact: true,
hasGroup: true, hasGroup: true,
}, },
redirect: "/infrastructure", redirect: "/linux",
component: Layout, component: Layout,
children: [ children: [
{ {
path: "/infrastructure", path: "/linux",
name: "Linux", name: "Linux",
meta: { meta: {
title: "linux", title: "linux",
}, },
component: () => import("@/views/Layer.vue"), component: () => import("@/views/Layer.vue"),
// component: () => import("@/views/infrastructure/Infrastructure.vue"), },
{
path: "/kubernetes",
name: "Kubernetes",
meta: {
title: "kubernetes",
},
component: () => import("@/views/Layer.vue"),
}, },
// { // {
// path: "/infrastructure/vm", // path: "/infrastructure/vm",

View File

@ -14,101 +14,61 @@ See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<Edit v-if="dashboardStore.currentDashboard" /> <Edit v-if="dashboardStore.currentDashboard" />
<div class="no-root" v-else>{{ t("noRoot") }} {{ layer }}</div> <div v-else class="no-root">
{{ t("noRoot") }} {{ dashboardStore.layerId }}
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, watch } from "vue"; import { ref } from "vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import { useI18n } from "vue-i18n";
import { EntityType } from "./dashboard/data"; import { EntityType } from "./dashboard/data";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { useAppStoreWithOut } from "@/store/modules/app";
import Edit from "./dashboard/Edit.vue"; import Edit from "./dashboard/Edit.vue";
import { useI18n } from "vue-i18n";
import { useAppStoreWithOut } from "@/store/modules/app";
const { t } = useI18n();
const route = useRoute(); const route = useRoute();
const dashboardStore = useDashboardStore(); const { t } = useI18n();
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const routeNames = [ const dashboardStore = useDashboardStore();
"GeneralServices", const routesMap: { [key: string]: string } = {
"Database", GeneralServices: "GENERAL",
"MeshServices", Database: "VIRTUAL_DATABASE",
"ControlPanel", MESH: "MESH",
"DataPanel", ControlPanel: "MESH_CP",
"Linux", DataPanel: "MESH_DP",
"SkyWalkingServer", Linux: "OS_LINUX",
"Satellite", SkyWalkingServer: "SO11Y_OAP",
"Functions", Satellite: "SO11Y_SATELLITE",
"Browser", Functions: "FAAS",
]; Browser: "BROWSER",
Kubernetes: "K8S",
};
const layer = ref<string>("GENERAL"); const layer = ref<string>("GENERAL");
getDashboard(); getDashboard();
async function getDashboard() { async function getDashboard() {
setLayer(String(route.name)); layer.value = routesMap[String(route.name)];
dashboardStore.setLayer(layer.value); dashboardStore.setLayer(layer.value);
dashboardStore.setEntity(EntityType[0].value); dashboardStore.setEntity(EntityType[1].value);
dashboardStore.setMode(false); dashboardStore.setMode(false);
dashboardStore.setCurrentDashboard(null);
await dashboardStore.setDashboards(); await dashboardStore.setDashboards();
const index = dashboardStore.dashboards.findIndex( const index = dashboardStore.dashboards.findIndex(
(d: { name: string; isRoot: boolean; layer: string; entity: string }) => (d: { name: string; isRoot: boolean; layer: string; entity: string }) =>
d.layer === layer.value && d.entity === EntityType[1].value && d.isRoot d.layer === dashboardStore.layerId &&
d.entity === EntityType[1].value &&
d.isRoot
); );
if (index < 0) { if (index < 0) {
appStore.setPageTitle(dashboardStore.layer);
dashboardStore.setCurrentDashboard(null);
return; return;
} }
const d = dashboardStore.dashboards[index]; const item = dashboardStore.dashboards[index];
dashboardStore.setCurrentDashboard(d); dashboardStore.setCurrentDashboard(item);
appStore.setPageTitle(d.name);
} }
function setLayer(n: string) {
switch (n) {
case routeNames[0]:
layer.value = "GENERAL";
break;
case routeNames[1]:
layer.value = "VIRTUAL_DATABASE";
break;
case routeNames[2]:
layer.value = "MESH";
break;
case routeNames[3]:
layer.value = "MESH_CP";
break;
case routeNames[4]:
layer.value = "MESH_DP";
break;
case routeNames[5]:
layer.value = "OS_LINUX";
break;
case routeNames[6]:
layer.value = "SO11Y_OAP";
break;
case routeNames[7]:
layer.value = "SO11Y_SATELLITE";
break;
case routeNames[8]:
layer.value = "FAAS";
break;
case routeNames[9]:
layer.value = "BROWSER";
break;
default:
layer.value = "GENERAL";
break;
}
}
watch(
() => route.name,
(name: unknown) => {
if (!name) {
return;
}
getDashboard();
}
);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.no-root { .no-root {
@ -117,8 +77,4 @@ watch(
text-align: center; text-align: center;
color: #888; color: #888;
} }
.layer {
height: 100%;
}
</style> </style>

View File

@ -13,9 +13,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<Tool /> <Tool v-if="dashboardStore.currentDashboard" />
<div <div
class="ds-main" class="ds-main"
v-if="dashboardStore.currentDashboard"
@click="handleClick" @click="handleClick"
:style="{ height: dashboardStore.editMode ? 'calc(100% - 45px)' : '100%' }" :style="{ height: dashboardStore.editMode ? 'calc(100% - 45px)' : '100%' }"
> >
@ -54,6 +55,9 @@ async function setTemplate() {
await dashboardStore.setDashboards(); await dashboardStore.setDashboards();
if (!p.entity) { if (!p.entity) {
if (!dashboardStore.currentDashboard) {
return;
}
const { layer, entity, name } = dashboardStore.currentDashboard; const { layer, entity, name } = dashboardStore.currentDashboard;
layoutKey.value = `${layer}_${entity}_${name}`; layoutKey.value = `${layer}_${entity}_${name}`;
} }
@ -63,17 +67,17 @@ async function setTemplate() {
const layout: any = c.configuration || {}; const layout: any = c.configuration || {};
dashboardStore.setLayout(layout.children || []); dashboardStore.setLayout(layout.children || []);
appStore.setPageTitle(layout.name); appStore.setPageTitle(layout.name);
if (p.entity) {
if (!dashboardStore.currentDashboard) {
dashboardStore.setCurrentDashboard({ dashboardStore.setCurrentDashboard({
layer: p.layerId, layer: p.layerId,
entity: p.entity, entity: p.entity,
name: String(p.name).split("-").join(" "), name: p.name,
id: c.id, id: c.id,
isRoot: layout.isRoot, isRoot: layout.isRoot,
}); });
} }
} }
function handleClick(e: any) { function handleClick(e: any) {
e.stopPropagation(); e.stopPropagation();
if (e.target.className === "ds-main") { if (e.target.className === "ds-main") {

View File

@ -167,8 +167,6 @@ function clickEndpoint(scope: any) {
ElMessage.error("No this dashboard"); ElMessage.error("No this dashboard");
return; return;
} }
dashboardStore.setEntity(EntityType[2].value);
dashboardStore.setCurrentDashboard(d);
router.push( router.push(
`/dashboard/${d.layer}/${d.entity}/${selectorStore.currentService.id}/${scope.row.id}/${d.name}` `/dashboard/${d.layer}/${d.entity}/${selectorStore.currentService.id}/${scope.row.id}/${d.name}`
); );

View File

@ -168,24 +168,16 @@ function clickInstance(scope: any) {
layer: dashboardStore.layerId, layer: dashboardStore.layerId,
entity: EntityType[3].value, entity: EntityType[3].value,
}); });
if (!d) {
ElMessage.error("No this dashboard");
return;
}
dashboardStore.setCurrentDashboard(d);
dashboardStore.setEntity(d.entity);
router.push( router.push(
`/dashboard/${d.layer}/${d.entity}/${selectorStore.currentService.id}/${scope.row.id}/${d.name}` `/dashboard/${d.layer}/${d.entity}/${selectorStore.currentService.id}/${
scope.row.id
}/${d.name.split(" ").join("-")}`
); );
} }
function changePage(pageIndex: number) { function changePage(pageIndex: number) {
instances.value = searchInstances.value.splice( instances.value = searchInstances.value.splice(pageIndex - 1, pageSize);
(pageIndex - 1 || 0) * pageSize,
pageSize * (pageIndex || 1)
);
} }
function searchList() { function searchList() {
searchInstances.value = selectorStore.pods.filter((d: { label: string }) => searchInstances.value = selectorStore.pods.filter((d: { label: string }) =>
d.label.includes(searchText.value) d.label.includes(searchText.value)
@ -201,12 +193,6 @@ watch(
} }
} }
); );
watch(
() => [selectorStore.currentService],
() => {
queryInstance();
}
);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "./style.scss"; @import "./style.scss";

View File

@ -183,8 +183,6 @@ function clickService(scope: any) {
ElMessage.error("No this dashboard"); ElMessage.error("No this dashboard");
return; return;
} }
dashboardStore.setCurrentDashboard(d);
dashboardStore.setEntity(d.entity);
const path = `/dashboard/${d.layer}/${d.entity}/${scope.row.id}/${d.name}`; const path = `/dashboard/${d.layer}/${d.entity}/${scope.row.id}/${d.name}`;
router.push(path); router.push(path);

View File

@ -53,9 +53,9 @@ export default defineComponent({
const { t } = useI18n(); const { t } = useI18n();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const selectorStore = useSelectorStore(); const selectorStore = useSelectorStore();
function layoutUpdatedEvent(newLayout: LayoutConfig[]) { // function layoutUpdatedEvent(newLayout: LayoutConfig[]) {
dashboardStore.setLayout(newLayout); // dashboardStore.setLayout(newLayout);
} // }
function clickGrid(item: LayoutConfig) { function clickGrid(item: LayoutConfig) {
dashboardStore.activeGridItem(item.i); dashboardStore.activeGridItem(item.i);
dashboardStore.selectWidget(item); dashboardStore.selectWidget(item);
@ -64,10 +64,10 @@ export default defineComponent({
dashboardStore.setLayout([]); dashboardStore.setLayout([]);
selectorStore.setCurrentService(null); selectorStore.setCurrentService(null);
selectorStore.setCurrentPod(null); selectorStore.setCurrentPod(null);
dashboardStore.setEntity("");
}); });
return { return {
dashboardStore, dashboardStore,
layoutUpdatedEvent,
clickGrid, clickGrid,
t, t,
}; };

View File

@ -125,7 +125,6 @@ const dashboardStore = useDashboardStore();
const selectorStore = useSelectorStore(); const selectorStore = useSelectorStore();
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const params = useRoute().params; const params = useRoute().params;
const type = EntityType.filter((d: Option) => d.value === params.entity)[0];
const toolIcons = ref<{ name: string; content: string; id: string }[]>( const toolIcons = ref<{ name: string; content: string; id: string }[]>(
EndpointRelationTools EndpointRelationTools
); );
@ -140,19 +139,16 @@ const states = reactive<{
}>({ }>({
destService: "", destService: "",
destPod: "", destPod: "",
key: (type && type.key) || 0, key: 0,
currentService: "", currentService: "",
currentPod: "", currentPod: "",
currentDestService: "", currentDestService: "",
currentDestPod: "", currentDestPod: "",
}); });
const applyDashboard = useThrottleFn(dashboardStore.saveDashboard, 3000); const applyDashboard = useThrottleFn(dashboardStore.saveDashboard, 3000);
if (params.layerId) {
dashboardStore.setLayer(params.layerId);
dashboardStore.setEntity(params.entity);
}
appStore.setEventStack([initSelector]);
setCurrentDashboard();
appStore.setEventStack([initSelector]);
initSelector(); initSelector();
function initSelector() { function initSelector() {
@ -164,6 +160,17 @@ function initSelector() {
} }
} }
function setCurrentDashboard() {
if (params.layerId) {
dashboardStore.setLayer(params.layerId);
dashboardStore.setEntity(params.entity);
}
const type = EntityType.filter(
(d: Option) => d.value === dashboardStore.entity
)[0];
states.key = (type && type.key) || 0;
}
async function setSelector() { async function setSelector() {
if ( if (
[ [
@ -199,7 +206,8 @@ async function setSelector() {
} }
selectorStore.setCurrentService(currentService); selectorStore.setCurrentService(currentService);
selectorStore.setCurrentDestService(currentDestService); selectorStore.setCurrentDestService(currentDestService);
states.currentService = selectorStore.currentService.value; states.currentService =
selectorStore.currentService && selectorStore.currentService.value;
states.currentDestService = states.currentDestService =
selectorStore.currentDestService && selectorStore.currentDestService.value; selectorStore.currentDestService && selectorStore.currentDestService.value;
} }
@ -265,14 +273,20 @@ async function getServices() {
selectorStore.setCurrentDestService( selectorStore.setCurrentDestService(
selectorStore.services.length ? selectorStore.services[1] : null selectorStore.services.length ? selectorStore.services[1] : null
); );
if (!selectorStore.currentService) {
return;
}
states.currentService = selectorStore.currentService.value; states.currentService = selectorStore.currentService.value;
states.currentDestService = selectorStore.currentDestService.value;
const e = dashboardStore.entity.split("Relation")[0]; const e = dashboardStore.entity.split("Relation")[0];
if ( if (
[EntityType[2].value, EntityType[3].value].includes(dashboardStore.entity) [EntityType[2].value, EntityType[3].value].includes(dashboardStore.entity)
) { ) {
fetchPods(e, selectorStore.currentService.id, true); fetchPods(e, selectorStore.currentService.id, true);
} }
if (!selectorStore.currentDestService) {
return;
}
states.currentDestService = selectorStore.currentDestService.value;
if ( if (
[EntityType[5].value, EntityType[6].value].includes(dashboardStore.entity) [EntityType[5].value, EntityType[6].value].includes(dashboardStore.entity)
) { ) {

View File

@ -387,42 +387,21 @@ async function handleInspect() {
update(); update();
} }
function handleGoEndpoint(name: string) { function handleGoEndpoint(name: string) {
const origin = dashboardStore.entity; const path = `/dashboard/${dashboardStore.layerId}/${EntityType[2].value}/${topologyStore.node.id}/${name}`;
const p = getDashboard({
name,
layer: dashboardStore.layerId,
entity: EntityType[2].value,
});
dashboardStore.setEntity(p.entity);
const path = `/dashboard/${p.layer}/Endpoint/${topologyStore.node.id}/${name}`;
const routeUrl = router.resolve({ path }); const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank"); window.open(routeUrl.href, "_blank");
dashboardStore.setEntity(origin); dashboardStore.setEntity(origin);
} }
function handleGoInstance(name: string) { function handleGoInstance(name: string) {
const origin = dashboardStore.entity; const path = `/dashboard/${dashboardStore.layerId}/${EntityType[3].value}/${topologyStore.node.id}/${name}`;
const p = getDashboard({
name,
layer: dashboardStore.layerId,
entity: EntityType[3].value,
});
dashboardStore.setEntity(p.entity);
const path = `/dashboard/${p.layer}/ServiceInstance/${topologyStore.node.id}/${name}`;
const routeUrl = router.resolve({ path }); const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank"); window.open(routeUrl.href, "_blank");
dashboardStore.setEntity(origin); dashboardStore.setEntity(origin);
} }
function handleGoDashboard(name: string) { function handleGoDashboard(name: string) {
const origin = dashboardStore.entity; const path = `/dashboard/${dashboardStore.layerId}/${EntityType[0].value}/${topologyStore.node.id}/${name}`;
const p = getDashboard({
name,
layer: dashboardStore.layerId,
entity: EntityType[0].value,
});
dashboardStore.setEntity(p.entity);
const path = `/dashboard/${p.layer}/Service/${topologyStore.node.id}/${name}`;
const routeUrl = router.resolve({ path }); const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank"); window.open(routeUrl.href, "_blank");
@ -482,6 +461,9 @@ function setNodeTools(nodeDashboard: any) {
{ id: "inspect", title: "Inspect", func: handleInspect }, { id: "inspect", title: "Inspect", func: handleInspect },
{ id: "alarm", title: "Alarm", func: handleGoAlarm }, { id: "alarm", title: "Alarm", func: handleGoAlarm },
]; ];
if (!(nodeDashboard && nodeDashboard.length)) {
return;
}
for (const item of nodeDashboard) { for (const item of nodeDashboard) {
if (item.scope === EntityType[0].value) { if (item.scope === EntityType[0].value) {
items.value.push({ items.value.push({