-
-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathindex.vue
91 lines (81 loc) · 2.22 KB
/
index.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<script setup lang="ts">
import { computed, onUnmounted, ref, watch } from 'vue'
import { onRpcConnected, rpc } from '@vue/devtools-core'
import About from './components/About.vue'
import State from './components/state/Index.vue'
import Timeline from './components/timeline/Index.vue'
import AppConnecting from '~/components/basic/AppConnecting.vue'
import { VirtualRoute, registerVirtualRouter } from '~/composables/virtual-router'
import { createCustomInspectorStateContext } from '~/composables/custom-inspector-state'
const props = defineProps<{
id: string
savedSelectedId?: string
}>()
const emit = defineEmits(['loadError', 'onSelectId'])
const inspectorState = createCustomInspectorStateContext()
const loading = ref(false)
const routes = computed(() => {
return [
{
path: '/state',
name: 'State',
component: State,
icon: 'i-carbon-tree-view-alt',
},
inspectorState.value.timelineLayerIds?.length && ({
path: '/timeline',
name: 'Timeline',
component: Timeline,
icon: 'i-mdi:timeline-clock-outline',
}),
{
path: '/about',
name: 'About',
component: About,
},
].filter(Boolean) as VirtualRoute[]
})
const { VirtualRouterView, restoreRouter } = registerVirtualRouter(routes, {
defaultRoutePath: '/state',
})
function getInspectorInfo() {
loading.value = true
onRpcConnected(() => {
rpc.value.getInspectorInfo(props.id).then((payload) => {
if (!payload) {
emit('loadError')
return
}
const state = {
homepage: payload?.homepage,
id: payload?.id,
label: payload?.label,
logo: payload?.logo,
timelineLayerIds: payload?.timelineLayers.map(item => item.id),
}
inspectorState.value = state
restoreRouter()
loading.value = false
})
})
}
watch(() => props.id, () => {
getInspectorInfo()
}, {
immediate: true,
})
onUnmounted(() => {
rpc.value.unhighlight()
})
function handleSelectId(id: string) {
emit('onSelectId', id)
}
</script>
<template>
<div h-full w-full>
<div v-if="loading">
<AppConnecting />
</div>
<VirtualRouterView v-else :saved-selected-id="savedSelectedId" @on-select-id="handleSelectId" />
</div>
</template>