mirror of
https://github.com/fantastic-admin/basic.git
synced 2026-10-06 14:53:50 +08:00
扩展路由 close 函数,并移除 useTabbar 中 close 函数
This commit is contained in:
@@ -55,8 +55,30 @@ function extendReplace(router: Router) {
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'vue-router' {
|
||||
interface Router {
|
||||
/**
|
||||
* 本方法为框架扩展语法,等同于 `push` 方法,并且同时会关闭当前标签页
|
||||
*/
|
||||
close: (to: RouteLocationRaw) => Promise<NavigationFailure | void | undefined>
|
||||
}
|
||||
}
|
||||
|
||||
function extendClose(router: Router) {
|
||||
router.close = function (to: RouteLocationRaw) {
|
||||
const settingsStore = useSettingsStore(pinia)
|
||||
if (settingsStore.settings.tabbar.enable) {
|
||||
const tabId = getId(router)
|
||||
const tabbarStore = useTabbarStore(pinia)
|
||||
tabbarStore.remove(tabId)
|
||||
}
|
||||
return router.push(to)
|
||||
}
|
||||
}
|
||||
|
||||
export default function setupExtensions(router: Router) {
|
||||
extendPush(router)
|
||||
extendGo(router)
|
||||
extendReplace(router)
|
||||
extendClose(router)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { RouteLocationRaw } from 'vue-router'
|
||||
import { toast } from 'vue-sonner'
|
||||
|
||||
export default function useTabbar() {
|
||||
@@ -11,13 +10,6 @@ export default function useTabbar() {
|
||||
return route.fullPath
|
||||
}
|
||||
|
||||
function close(to: RouteLocationRaw) {
|
||||
const tabId = getId()
|
||||
router.push(to).then(() => {
|
||||
tabbarStore.remove(tabId)
|
||||
})
|
||||
}
|
||||
|
||||
function closeById(tabId = getId()) {
|
||||
if (checkClose(tabId, false)) {
|
||||
const activedTabId = getId()
|
||||
@@ -25,10 +17,10 @@ export default function useTabbar() {
|
||||
if (tabId === activedTabId) {
|
||||
const index = tabbarStore.list.findIndex(item => item.tabId === tabId)
|
||||
if (index > 0) {
|
||||
close(tabbarStore.list[index - 1].fullPath)
|
||||
router.close(tabbarStore.list[index - 1].fullPath)
|
||||
}
|
||||
else {
|
||||
close(tabbarStore.list[index + 1].fullPath)
|
||||
router.close(tabbarStore.list[index + 1].fullPath)
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -12,7 +12,7 @@ function open() {
|
||||
router.push(settingsStore.settings.home.fullPath)
|
||||
}
|
||||
function close() {
|
||||
tabbar.close(settingsStore.settings.home.fullPath)
|
||||
router.close(settingsStore.settings.home.fullPath)
|
||||
}
|
||||
function closeById() {
|
||||
tabbar.closeById()
|
||||
|
||||
Reference in New Issue
Block a user