feat: set tools for sankey topology

This commit is contained in:
Qiuxia Fan 2022-02-16 15:37:48 +08:00
parent 4ba120cad3
commit bc87567f14
2 changed files with 91 additions and 43 deletions

View File

@ -55,7 +55,13 @@ limitations under the License. -->
/> />
</div> </div>
<div class="selectors-item" v-if="states.key === 4"> <div class="selectors-item" v-if="states.key === 4">
<span class="label">$DestinationServiceInstance</span> <span class="label">
{{
dashboardStore.entity === "EndpointRelation"
? "$DestinationEndpoint"
: "$DestinationServiceInstance"
}}</span
>
<Selector <Selector
v-model="states.currentDestPod" v-model="states.currentDestPod"
:options="selectorStore.destPods" :options="selectorStore.destPods"
@ -145,8 +151,6 @@ async function setSelector() {
) { ) {
await selectorStore.getService(String(params.serviceId)); await selectorStore.getService(String(params.serviceId));
states.currentService = selectorStore.currentService.value; states.currentService = selectorStore.currentService.value;
await selectorStore.getService(String(params.destServiceId), true);
states.currentDestService = selectorStore.currentDestService.value;
const e = String(params.entity).split("Relation")[0]; const e = String(params.entity).split("Relation")[0];
await fetchPods(e, selectorStore.currentService.id, false); await fetchPods(e, selectorStore.currentService.id, false);
if (!(selectorStore.pods.length && selectorStore.pods[0])) { if (!(selectorStore.pods.length && selectorStore.pods[0])) {

View File

@ -27,6 +27,13 @@ limitations under the License. -->
<span class="switch-icon ml-5" title="Settings"> <span class="switch-icon ml-5" title="Settings">
<Icon @click="setConfig" size="middle" iconName="settings" /> <Icon @click="setConfig" size="middle" iconName="settings" />
</span> </span>
<span class="switch-icon ml-5" title="Back to overview topology">
<Icon
@click="backToTopology"
size="middle"
iconName="keyboard_backspace"
/>
</span>
<div class="settings" v-show="showSettings"> <div class="settings" v-show="showSettings">
<Settings @update="updateConfig" /> <Settings @update="updateConfig" />
</div> </div>
@ -46,9 +53,16 @@ limitations under the License. -->
left: operationsPos.x + 'px', left: operationsPos.x + 'px',
}" }"
> >
<span v-for="(item, index) of items" :key="index" @click="item.func"> <i v-for="(item, index) of items" :key="index" @click="item.func">
{{ item.title }} <span
</span> v-if="
['alarm', 'inspect'].includes(item.id) ||
(item.id === 'dashboard' && settings.nodeDashboard)
"
>
{{ item.title }}
</span>
</i>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -73,55 +87,64 @@ const height = ref<number>(document.body.clientHeight - 150);
const width = ref<number>(document.body.clientWidth - 40); const width = ref<number>(document.body.clientWidth - 40);
const showSettings = ref<boolean>(false); const showSettings = ref<boolean>(false);
const depth = ref<string>("2"); const depth = ref<string>("2");
const showTool = ref<boolean>(false); const depthList = ["1", "2", "3", "4", "5"].map((item: string) => ({
const depthList = [1, 2, 3, 4, 5].map((item: number) => ({ value: item,
value: String(item), label: item,
label: String(item),
})); }));
const settings = ref<any>({}); const settings = ref<any>({});
const items = ref([
{ id: "inspect", title: "Inspect", func: inspect },
{ id: "alarm", title: "Alarm", func: goAlarm },
]);
const operationsPos = reactive<{ x: number; y: number }>({ x: NaN, y: NaN }); const operationsPos = reactive<{ x: number; y: number }>({ x: NaN, y: NaN });
const items = [
{ id: "inspect", title: "Inspect", func: inspect },
{ id: "dashboard", title: "View Dashboard", func: goDashboard },
{ id: "alarm", title: "View Alarm", func: goAlarm },
];
onMounted(async () => { onMounted(async () => {
loadTopology(selectorStore.currentPod.id);
});
async function loadTopology(id: string) {
loading.value = true; loading.value = true;
const resp = await getTopology(); const resp = await getTopology(id);
loading.value = false; loading.value = false;
if (resp && resp.errors) { if (resp && resp.errors) {
ElMessage.error(resp.errors); ElMessage.error(resp.errors);
} }
}); }
function inspect() { function inspect() {
console.log(settings.value); const id = topologyStore.node.id;
topologyStore.setNode(null);
topologyStore.setLink(null);
loadTopology(id);
} }
function goAlarm() { function goAlarm() {
console.log(settings.value); const path = `/alarm`;
const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank");
topologyStore.setNode(null);
} }
function goDashboard() { function goDashboard() {
console.log(settings.value); const path = `/dashboard/${dashboardStore.layerId}/${dashboardStore.entity}/${topologyStore.node.serviceId}/${topologyStore.node.id}/${settings.value.nodeDashboard}`;
const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank");
topologyStore.setNode(null);
} }
function setConfig() { function setConfig() {
topologyStore.setNode(null);
showSettings.value = !showSettings.value; showSettings.value = !showSettings.value;
} }
function updateConfig(config: any) { function updateConfig(config: any) {
items.value = [
{ id: "inspect", title: "Inspect", func: inspect },
{ id: "alarm", title: "Alarm", func: goAlarm },
];
settings.value = config; settings.value = config;
if (config.nodeDashboard) { }
items.value.push({
id: "dashboard", function backToTopology() {
title: "Dashboard", loadTopology(selectorStore.currentPod.id);
func: goDashboard, topologyStore.setNode(null);
});
}
} }
function selectNodeLink(d: any) { function selectNodeLink(d: any) {
@ -131,7 +154,6 @@ function selectNodeLink(d: any) {
if (!settings.value.linkDashboard) { if (!settings.value.linkDashboard) {
return; return;
} }
console.log(d.data);
const { sourceObj, targetObj } = d.data; const { sourceObj, targetObj } = d.data;
const entity = const entity =
dashboardStore.entity === EntityType[2].value dashboardStore.entity === EntityType[2].value
@ -140,29 +162,25 @@ function selectNodeLink(d: any) {
const path = `/dashboard/${dashboardStore.layerId}/${entity}/${sourceObj.serviceId}/${sourceObj.id}/${targetObj.serviceId}/${targetObj.id}/${settings.value.linkDashboard}`; const path = `/dashboard/${dashboardStore.layerId}/${entity}/${sourceObj.serviceId}/${sourceObj.id}/${targetObj.serviceId}/${targetObj.id}/${settings.value.linkDashboard}`;
const routeUrl = router.resolve({ path }); const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank"); window.open(routeUrl.href, "_blank");
} else { return;
topologyStore.setNode(d.data);
topologyStore.setLink(null);
showTool.value = true;
} }
topologyStore.setNode(d.data);
topologyStore.setLink(null);
operationsPos.x = d.event.event.clientX;
operationsPos.y = d.event.event.clientY;
} }
async function changeDepth(opt: Option[]) { async function changeDepth(opt: Option[]) {
depth.value = opt[0].value; depth.value = opt[0].value;
loading.value = true; loadTopology(selectorStore.currentPod.id);
const resp = await getTopology();
loading.value = false;
if (resp && resp.errors) {
ElMessage.error(resp.errors);
}
} }
async function getTopology() { async function getTopology(id: string) {
let resp; let resp;
switch (dashboardStore.entity) { switch (dashboardStore.entity) {
case EntityType[2].value: case EntityType[2].value:
resp = await topologyStore.updateEndpointTopology( resp = await topologyStore.updateEndpointTopology(
[selectorStore.currentPod.id], [id],
Number(depth.value) Number(depth.value)
); );
break; break;
@ -218,4 +236,30 @@ async function getTopology() {
display: inline-block; display: inline-block;
margin-right: 5px; margin-right: 5px;
} }
.operations-list {
position: absolute;
padding: 10px;
color: #333;
cursor: pointer;
background-color: #fff;
border-radius: 3px;
span {
display: block;
height: 30px;
width: 100px;
line-height: 30px;
text-align: center;
}
span:hover {
color: #409eff;
background-color: #eee;
}
i {
font-style: normal;
}
}
</style> </style>