11<script setup lang="ts">
2- import type { RouteLocationRaw } from ' vue-router'
2+ import type { RouteLocationRaw , RouteRecordNameGeneric } from ' vue-router'
33import { onBeforeRouteUpdate } from ' vue-router'
44
55const { logout } = useStore (' user' )
@@ -25,22 +25,24 @@ const breadcrumbArr = computed(() => {
2525
2626// 更新头部tabs
2727onBeforeRouteUpdate ((to , _from , next ) => {
28- const tab = { title: to .meta .title , name: to .path }
28+ const tab = { title: to .meta .title , name: to .name }
2929 addTab (tab )
3030 next ()
3131})
3232
3333// 切换tabs
3434function tabClick(val : number | string = 0 , delay = true ) {
35- let path : RouteLocationRaw
35+ let name : RouteRecordNameGeneric
3636 if (typeof val === ' number' ) {
37- path = tabs .value [val ].name
37+ name = tabs .value [val ].name
3838 } else {
39- path = val
39+ name = val
4040 }
4141 setTimeout (
4242 () => {
43- router .push (path )
43+ router .push ({
44+ name ,
45+ })
4446 },
4547 delay ? 200 : 0 ,
4648 )
@@ -63,7 +65,7 @@ function closeMenu() {
6365function tabRemove(name : string = clickName ) {
6466 const index = tabs .value .findIndex ((i : App .Tab ) => i .name === name )
6567 removeTab (name )
66- if (route .path === name ) {
68+ if (route .name === name ) {
6769 const nextTabIndex = index > tabs .value .length - 1 ? tabs .value .length - 1 : index
6870 tabClick (nextTabIndex )
6971 }
@@ -74,7 +76,7 @@ function tabRemoveOther() {
7476}
7577function tabRemoveRight() {
7678 removeRightTab (clickName )
77- if (tabs .value .every ((i : App .Tab ) => i .name !== route .path )) {
79+ if (tabs .value .every ((i : App .Tab ) => i .name !== route .name )) {
7880 tabClick (clickName )
7981 }
8082}
@@ -138,15 +140,15 @@ function dragenter(e: { preventDefault: () => void }, index: number) {
138140 v-for =" (item, index) in tabs"
139141 :key =" item.name"
140142 class =" tab-item"
141- :class =" { 'tab-active': item.name === route.path }"
143+ :class =" { 'tab-active': item.name === route.name }"
142144 draggable =" true"
143145 @click =" tabClick(item.name, false)"
144146 @contextmenu.prevent =" rightClick($event, item.name)"
145147 @dragenter =" dragenter($event, index)"
146148 @dragover =" dragover($event)"
147149 @dragstart =" dragstart(index)"
148150 >
149- <div v-show =" item.name === route.path " class =" circle" />
151+ <div v-show =" item.name === route.name " class =" circle" />
150152 <div class =" content" >
151153 {{ item.title }}
152154 </div >
0 commit comments