|
6 | 6 | :show-filter="false" |
7 | 7 | node-key="id" |
8 | 8 | wrap |
9 | | - :default-expanded-keys="[expandeArr]" |
| 9 | + :default-expanded-keys="expandeArr" |
10 | 10 | @current-change="currentChange" |
11 | 11 | > |
12 | 12 | <template #default="slotScope"> |
|
22 | 22 | </template> |
23 | 23 |
|
24 | 24 | <script lang="ts" setup> |
25 | | - import { computed, watch, ref } from 'vue'; |
| 25 | + import { computed, watch, ref, onMounted } from 'vue'; |
26 | 26 | import { RouteRecordNormalized } from 'vue-router'; |
27 | 27 | import { |
28 | 28 | IconDownloadCloud, |
|
195 | 195 | const appRoute = computed(() => { |
196 | 196 | return router |
197 | 197 | .getRoutes() |
198 | | - .find((el) => el.name === 'root') as RouteRecordNormalized; |
| 198 | + .find((el: { name: string; }) => el.name === 'root') as RouteRecordNormalized; |
199 | 199 | }); |
200 | 200 | const copyRouter = JSON.parse(JSON.stringify(appRoute.value.children)); |
201 | 201 | copyRouter.sort((a: RouteRecordNormalized, b: RouteRecordNormalized) => { |
|
220 | 220 |
|
221 | 221 | watch( |
222 | 222 | role, |
223 | | - (newValue, oldValue) => { |
| 223 | + (newValue: string) => { |
224 | 224 | if (newValue === 'admin') { |
225 | 225 | treeData.value = copyRouter; |
226 | 226 | } else { |
|
235 | 235 | /** |
236 | 236 | * 监听路由变化高亮当前菜单 |
237 | 237 | */ |
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 | + }); |
253 | 251 | const currentChange = (data: any) => { |
254 | 252 | const filter = [ |
255 | 253 | 'Exception', |
|
318 | 316 | } |
319 | 317 | } |
320 | 318 |
|
321 | | - :deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children |
| 319 | + :deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children |
322 | 320 | .tiny-tree-node__wrapper .is-current .tiny-tree-node__content .tree-node-name) { |
323 | 321 | border-left: 2px solid var(--ti-tree-menu-square-left-border-color, '#fff') !important; |
324 | 322 | } |
325 | 323 |
|
326 | | - :deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children |
| 324 | + :deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children |
327 | 325 | .tiny-tree-node__wrapper .is-current .tiny-tree-node__content .tiny-tree-node__content-right) { |
328 | 326 | background-color: var(--ti-tree-menu-node-hover-bg-color) !important; |
329 | 327 | } |
330 | 328 |
|
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 |
333 | 331 | .tiny-tree-node__content-box) { |
334 | 332 | background-color: var(--ti-tree-menu-node-hover-bg-color) !important; |
335 | 333 | } |
336 | 334 |
|
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 |
339 | 337 | .tiny-tree-node__content-box:before) { |
340 | 338 | display: none !important; |
341 | 339 | } |
342 | 340 |
|
343 | | - :deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children |
| 341 | + :deep(.tiny-tree-node__wrapper > .is-expanded > .tiny-tree-node__children |
344 | 342 | .tiny-tree-node__wrapper .is-current .tiny-tree-node__content .tiny-tree-node__content-left:before) { |
345 | 343 | display: none !important; |
346 | 344 | } |
|
357 | 355 | background-color: var(--ti-tree-node-content-hover-bg-color) !important; |
358 | 356 | } |
359 | 357 |
|
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 |
361 | 359 | > .tiny-tree-node__content-left .tiny-tree-node__content-box .tree-node-name) { |
362 | 360 | padding: 0 8px !important; |
363 | 361 | } |
|
0 commit comments