Skip to content

Commit 8e977c6

Browse files
authored
fix(toolkits): close issue 131 (#132)
* fix(toolkits): close issue 131 * style: remove unused variable
1 parent 1655b59 commit 8e977c6

File tree

1 file changed

+25
-27
lines changed
  • packages/toolkits/pro/template/tinyvue/src/components/menu

1 file changed

+25
-27
lines changed

packages/toolkits/pro/template/tinyvue/src/components/menu/index.vue

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
:show-filter="false"
77
node-key="id"
88
wrap
9-
:default-expanded-keys="[expandeArr]"
9+
:default-expanded-keys="expandeArr"
1010
@current-change="currentChange"
1111
>
1212
<template #default="slotScope">
@@ -22,7 +22,7 @@
2222
</template>
2323

2424
<script lang="ts" setup>
25-
import { computed, watch, ref } from 'vue';
25+
import { computed, watch, ref, onMounted } from 'vue';
2626
import { RouteRecordNormalized } from 'vue-router';
2727
import {
2828
IconDownloadCloud,
@@ -195,7 +195,7 @@
195195
const appRoute = computed(() => {
196196
return router
197197
.getRoutes()
198-
.find((el) => el.name === 'root') as RouteRecordNormalized;
198+
.find((el: { name: string; }) => el.name === 'root') as RouteRecordNormalized;
199199
});
200200
const copyRouter = JSON.parse(JSON.stringify(appRoute.value.children));
201201
copyRouter.sort((a: RouteRecordNormalized, b: RouteRecordNormalized) => {
@@ -220,7 +220,7 @@
220220
221221
watch(
222222
role,
223-
(newValue, oldValue) => {
223+
(newValue: string) => {
224224
if (newValue === 'admin') {
225225
treeData.value = copyRouter;
226226
} else {
@@ -235,21 +235,19 @@
235235
/**
236236
* 监听路由变化高亮当前菜单
237237
*/
238-
watch(
239-
() => router.currentRoute.value.path,
240-
(newValue) => {
241-
let data = newValue.split('/');
242-
let result = data[data.length - 1];
243-
const characters = [...result];
244-
characters[0] = characters[0]?.toUpperCase();
245-
expandeArr.value = characters.join('');
246-
setTimeout(() => {
247-
tree.value.$refs.tree.setCurrentNode({ id: expandeArr.value });
248-
}, 0);
249-
},
250-
{ immediate: true }
251-
);
252-
238+
onMounted(() => {
239+
watch(
240+
() => router.currentRoute.value.path,
241+
(newValue: string) => {
242+
const menuKey = newValue
243+
.replace(/^.*\//, '')
244+
.replace(/^[a-z]/, (s: string) => s.toUpperCase());
245+
expandeArr.value = [menuKey];
246+
tree.value.setCurrentKey(menuKey);
247+
},
248+
{ immediate: true },
249+
);
250+
});
253251
const currentChange = (data: any) => {
254252
const filter = [
255253
'Exception',
@@ -318,29 +316,29 @@
318316
}
319317
}
320318
321-
:deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children
319+
:deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children
322320
.tiny-tree-node__wrapper .is-current .tiny-tree-node__content .tree-node-name) {
323321
border-left: 2px solid var(--ti-tree-menu-square-left-border-color, '#fff') !important;
324322
}
325323
326-
:deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children
324+
:deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children
327325
.tiny-tree-node__wrapper .is-current .tiny-tree-node__content .tiny-tree-node__content-right) {
328326
background-color: var(--ti-tree-menu-node-hover-bg-color) !important;
329327
}
330328
331-
:deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children
332-
.tiny-tree-node__wrapper .is-current .tiny-tree-node__content .tiny-tree-node__content-left
329+
:deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children
330+
.tiny-tree-node__wrapper .is-current .tiny-tree-node__content .tiny-tree-node__content-left
333331
.tiny-tree-node__content-box) {
334332
background-color: var(--ti-tree-menu-node-hover-bg-color) !important;
335333
}
336334
337-
:deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children
338-
.tiny-tree-node__wrapper .is-current .tiny-tree-node__content .tiny-tree-node__content-left
335+
:deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children
336+
.tiny-tree-node__wrapper .is-current .tiny-tree-node__content .tiny-tree-node__content-left
339337
.tiny-tree-node__content-box:before) {
340338
display: none !important;
341339
}
342340
343-
:deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children
341+
:deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children
344342
.tiny-tree-node__wrapper .is-current .tiny-tree-node__content .tiny-tree-node__content-left:before) {
345343
display: none !important;
346344
}
@@ -357,7 +355,7 @@
357355
background-color: var(--ti-tree-node-content-hover-bg-color) !important;
358356
}
359357
360-
:deep(.tiny-tree-menu__wrap > .tiny-tree-node__wrapper > .is-root > .tiny-tree-node__content
358+
:deep(.tiny-tree-menu__wrap > .tiny-tree-node__wrapper > .is-root > .tiny-tree-node__content
361359
> .tiny-tree-node__content-left .tiny-tree-node__content-box .tree-node-name) {
362360
padding: 0 8px !important;
363361
}

0 commit comments

Comments
 (0)