File tree Expand file tree Collapse file tree 2 files changed +24
-10
lines changed
Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -55,8 +55,30 @@ function extendReplace(router: Router) {
5555 }
5656}
5757
58+ declare module 'vue-router' {
59+ interface Router {
60+ /**
61+ * 本方法为框架扩展语法,等同于 `push` 方法,并且同时会关闭当前标签页
62+ */
63+ close : ( to : RouteLocationRaw ) => Promise < NavigationFailure | void | undefined >
64+ }
65+ }
66+
67+ function extendClose ( router : Router ) {
68+ router . close = function ( to : RouteLocationRaw ) {
69+ const settingsStore = useSettingsStore ( pinia )
70+ if ( settingsStore . settings . tabbar . enable ) {
71+ const tabId = getId ( router )
72+ const tabbarStore = useTabbarStore ( pinia )
73+ tabbarStore . remove ( tabId )
74+ }
75+ return router . push ( to )
76+ }
77+ }
78+
5879export default function setupExtensions ( router : Router ) {
5980 extendPush ( router )
6081 extendGo ( router )
6182 extendReplace ( router )
83+ extendClose ( router )
6284}
Original file line number Diff line number Diff line change 1- import type { RouteLocationRaw } from 'vue-router'
21import { toast } from 'vue-sonner'
32
43export default function useTabbar ( ) {
@@ -11,24 +10,17 @@ export default function useTabbar() {
1110 return route . fullPath
1211 }
1312
14- function close ( to : RouteLocationRaw ) {
15- const tabId = getId ( )
16- router . push ( to ) . then ( ( ) => {
17- tabbarStore . remove ( tabId )
18- } )
19- }
20-
2113 function closeById ( tabId = getId ( ) ) {
2214 if ( checkClose ( tabId , false ) ) {
2315 const activedTabId = getId ( )
2416 // 如果关闭的标签正好是当前路由
2517 if ( tabId === activedTabId ) {
2618 const index = tabbarStore . list . findIndex ( item => item . tabId === tabId )
2719 if ( index > 0 ) {
28- close ( tabbarStore . list [ index - 1 ] . fullPath )
20+ router . close ( tabbarStore . list [ index - 1 ] . fullPath )
2921 }
3022 else {
31- close ( tabbarStore . list [ index + 1 ] . fullPath )
23+ router . close ( tabbarStore . list [ index + 1 ] . fullPath )
3224 }
3325 }
3426 else {
You can’t perform that action at this time.
0 commit comments