Skip to content

Commit ac59853

Browse files
committedMar 20, 2024
feat(applet): show name on pinia panel nav
1 parent c386c66 commit ac59853

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed
 

‎packages/applet/src/composables/virtual-router.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { Component, InjectionKey, Ref } from 'vue'
22
import { computed, defineComponent, h, inject, provide, ref } from 'vue'
33

44
const VirtualRouteKey: InjectionKey<Ref<{ path: string }>> = Symbol('VirtualRouteKey')
5-
const VirtualRoutesKey: InjectionKey<{ path: string, component: Component, icon?: string }[]> = Symbol('VirtualRoutesKey')
5+
const VirtualRoutesKey: InjectionKey<{ path: string, component: Component, icon?: string, name?: string }[]> = Symbol('VirtualRoutesKey')
66

7-
export function registerVirtualRouter(routes: { path: string, component: Component, icon?: string }[]) {
7+
export function registerVirtualRouter(routes: { path: string, component: Component, icon?: string, name?: string }[]) {
88
const route = ref<{ path: string, icon?: string }>({
99
path: '/',
1010
})
@@ -38,8 +38,11 @@ export function useVirtualRouter() {
3838
}
3939

4040
export function useVirtualRoute() {
41-
const route = inject(VirtualRoutesKey)!
41+
const routes = inject(VirtualRoutesKey)!
42+
const route = inject(VirtualRouteKey)!
43+
4244
return {
43-
routes: route,
45+
routes,
46+
currentRoute: route,
4447
}
4548
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { useVirtualRoute, useVirtualRouter } from '~/composables/virtual-router'
33
4-
const { routes } = useVirtualRoute()
4+
const { routes, currentRoute } = useVirtualRoute()
55
const router = useVirtualRouter()
66
</script>
77

@@ -10,10 +10,13 @@ const router = useVirtualRouter()
1010
<li
1111
v-for="(item, index) in routes"
1212
:key="index"
13-
cursor-pointer op70 hover:op100
13+
cursor-pointer hover:op100
14+
:style="{
15+
opacity: currentRoute.path === item.path ? 1 : 0.7,
16+
}"
1417
@click="router.push(item.path)"
1518
>
16-
<i :class="item.icon" />
19+
{{ item.name }}
1720
</li>
1821
</ul>
1922
</template>

‎packages/applet/src/pinia/index.vue

+3
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@ createDevToolsConnectStateContext()
1212
const { VirtualRouterView } = registerVirtualRouter([
1313
{
1414
path: '/',
15+
name: 'Home',
1516
component: Home,
1617
icon: 'i-logos-pinia',
1718
},
1819
{
1920
path: '/store',
21+
name: 'Store',
2022
component: Store,
2123
icon: 'i-carbon-tree-view-alt',
2224
},
2325
{
2426
path: '/timeline',
27+
name: 'Timeline',
2528
component: Timeline,
2629
icon: 'i-mdi:timeline-clock-outline',
2730
},

0 commit comments

Comments
 (0)
Please sign in to comment.