Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit 6fdfca3

Browse files
xxholly32xiangxiaowebfansplz
authored
feat: show route meta info in pages tab (#178)
Co-authored-by: xiangxiao <xiangxiao3@hikvision.com.cn> Co-authored-by: webfansplz <308241863@qq.com>
1 parent c941ff4 commit 6fdfca3

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<script setup lang="ts">
2+
import JsonEditorVue from 'json-editor-vue'
3+
import 'vanilla-jsoneditor/themes/jse-theme-dark.css'
4+
import type { RouteMeta } from 'vue-router'
5+
6+
const props = defineProps<{
7+
meta: RouteMeta
8+
}>()
9+
const colorMode = useColorMode()
10+
const meta = computed(() => props.meta)
11+
</script>
12+
13+
<template>
14+
<div h-full select-none overflow-scroll p-2 class="no-scrollbar">
15+
<JsonEditorVue
16+
v-model="meta" h-full class="json-editor-vue" :class="[
17+
colorMode === 'dark' ? 'jse-theme-dark' : '',
18+
]" :main-menu-bar="false" :navigation-bar="false" :status-bar="false" :read-only="true" :indentation="2"
19+
:tab-size="2"
20+
/>
21+
</div>
22+
</template>

packages/client/components/RoutesTable.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import type { RouteRecordNormalized } from 'vue-router'
2+
import type { RouteMeta, RouteRecordNormalized } from 'vue-router'
33
44
const props = defineProps<{
55
pages: RouteRecordNormalized[]
@@ -9,11 +9,17 @@ const props = defineProps<{
99
1010
defineEmits<{
1111
(e: 'navigate', path: string): void
12+
(e: 'selectMeta', meta: RouteMeta): void
1213
}>()
1314
1415
const sorted = computed(() => {
1516
return [...props.pages].sort((a, b) => a.path.localeCompare(b.path))
1617
})
18+
19+
function metaToString(meta: RouteMeta, num: number = 0) {
20+
const metaStr = JSON.stringify(meta, null, num)
21+
return metaStr === '{}' ? '-' : metaStr
22+
}
1723
</script>
1824

1925
<template>
@@ -28,6 +34,9 @@ const sorted = computed(() => {
2834
<th text-left>
2935
Name
3036
</th>
37+
<th text-left>
38+
Route Meta
39+
</th>
3140
</tr>
3241
</thead>
3342
<tbody>
@@ -53,13 +62,17 @@ const sorted = computed(() => {
5362
<RoutePathItem
5463
:route="item"
5564
:class="matched.find(m => m.path === item.path) ? 'text-primary' : matchedPending.find(m => m.name === item.name) ? 'text-teal' : ''"
65+
hover="text-primary"
5666
@navigate="(path:string) => $emit('navigate', path)"
5767
/>
5868
</div>
5969
</td>
6070
<td w-30 ws-nowrap pr-1 text-left text-sm font-mono op50>
6171
{{ item.name ?? '-' }}
6272
</td>
73+
<td w-50 ws-nowrap pr-1 text-left text-sm font-mono op50 hover="text-primary op100">
74+
<span inline-block w-50 cursor-pointer overflow-hidden text-ellipsis :title="metaToString(item.meta, 2)" @click="() => $emit('selectMeta', item.meta)">{{ metaToString(item.meta) }}</span>
75+
</td>
6376
</tr>
6477
</tbody>
6578
</table>

packages/client/pages/pages.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup lang="ts">
2+
import type { RouteMeta } from 'vue-router'
23
import { currentRoute, router, routes } from '~/logic/app'
34
45
const routeInput = ref('')
@@ -25,6 +26,8 @@ function navigateToRoute(path: string) {
2526
router.value?.push(path)
2627
routeInput.value = path
2728
}
29+
30+
const selectedMeta = ref<RouteMeta>()
2831
</script>
2932

3033
<template>
@@ -68,7 +71,15 @@ function navigateToRoute(path: string) {
6871
:matched="currentRoute?.matched ?? []"
6972
:matched-pending="routeInputMatched"
7073
@navigate="navigateToRoute"
74+
@select-meta="(meta: RouteMeta) => selectedMeta = meta"
7175
/>
76+
<DrawerRight
77+
:model-value="!!selectedMeta"
78+
auto-close w-120
79+
@close="selectedMeta = undefined"
80+
>
81+
<RouteMetaDetail v-if="!!selectedMeta" :meta="selectedMeta" />
82+
</DrawerRight>
7283
</VDSectionBlock>
7384
</div>
7485
</template>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy