|
1 | 1 | <script setup lang="ts">
|
2 | 2 | import { Drawer, DrawerContent } from "@progress/kendo-vue-layout";
|
3 | 3 | import { useLocalStorage } from "@vueuse/core";
|
4 |
| -import { useRouter } from "vue-router"; |
| 4 | +import { useRouter, useRoute } from "vue-router"; |
5 | 5 |
|
6 | 6 | import { computed, ref } from "vue";
|
7 | 7 |
|
8 | 8 | const router = useRouter();
|
| 9 | +const route = useRoute(); |
9 | 10 | const selectedId = ref(0);
|
10 | 11 |
|
11 | 12 | const expanded = useLocalStorage("vue-forge-drawer-expanded", true);
|
12 | 13 | const expandedIcon = computed(() =>
|
13 | 14 | expanded.value ? "k-i-arrow-chevron-left" : "k-i-arrow-chevron-right"
|
14 | 15 | );
|
15 |
| -const items = computed(() => [ |
16 |
| - { |
17 |
| - text: "Boards", |
18 |
| - icon: "k-i-set-column-position", |
19 |
| - selected: true, |
20 |
| - data: { |
21 |
| - path: "/", |
| 16 | +const items = computed(() => |
| 17 | + [ |
| 18 | + { |
| 19 | + text: "Boards", |
| 20 | + icon: "k-i-set-column-position", |
| 21 | + data: { |
| 22 | + path: "/boards", |
| 23 | + }, |
22 | 24 | },
|
23 |
| - }, |
24 |
| - { |
25 |
| - text: "Templates", |
26 |
| - icon: "k-i-border-left", |
27 |
| - data: { |
28 |
| - path: "/templates", |
| 25 | + { |
| 26 | + text: "Templates", |
| 27 | + icon: "k-i-border-left", |
| 28 | + data: { |
| 29 | + path: "/templates", |
| 30 | + }, |
29 | 31 | },
|
30 |
| - }, |
31 |
| - { |
32 |
| - text: "Settings", |
33 |
| - icon: "k-i-gear", |
34 |
| - data: { |
35 |
| - path: "/settings", |
| 32 | + { |
| 33 | + text: "Settings", |
| 34 | + icon: "k-i-gear", |
| 35 | + data: { |
| 36 | + path: "/settings", |
| 37 | + }, |
36 | 38 | },
|
37 |
| - }, |
38 |
| - { |
39 |
| - text: "Collapse", |
40 |
| - icon: expandedIcon.value, |
41 |
| - data: { |
42 |
| - action: () => (expanded.value = !expanded.value), |
| 39 | + { |
| 40 | + text: "Collapse", |
| 41 | + icon: expandedIcon.value, |
| 42 | + data: { |
| 43 | + action: () => (expanded.value = !expanded.value), |
| 44 | + }, |
43 | 45 | },
|
44 |
| - }, |
45 |
| -]); |
| 46 | + ].map((item, index) => ({ |
| 47 | + ...item, |
| 48 | + selected: route.path === item.data.path, |
| 49 | + })) |
| 50 | +); |
46 | 51 |
|
47 | 52 | function onSelect({ itemIndex }: { itemIndex: number }) {
|
48 | 53 | const item = items.value[itemIndex];
|
49 | 54 | if (!item) return;
|
| 55 | + selectedId.value = itemIndex; |
50 | 56 | if (item.data.path) router.push(item.data.path);
|
51 | 57 | if (typeof item.data.action === "function") item.data.action();
|
52 | 58 | }
|
|
0 commit comments