2021-11-19 14:53:40 +08:00
|
|
|
|
import store from '@/store'
|
2025-04-27 10:05:55 +08:00
|
|
|
|
import router from '@/router'
|
2021-11-19 14:53:40 +08:00
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
// 刷新当前tab页签
|
|
|
|
|
|
refreshPage(obj) {
|
2025-04-27 10:05:55 +08:00
|
|
|
|
const { path, query, matched } = router.currentRoute
|
2021-11-19 14:53:40 +08:00
|
|
|
|
if (obj === undefined) {
|
|
|
|
|
|
matched.forEach((m) => {
|
|
|
|
|
|
if (m.components && m.components.default && m.components.default.name) {
|
|
|
|
|
|
if (!['Layout', 'ParentView'].includes(m.components.default.name)) {
|
2025-04-27 10:05:55 +08:00
|
|
|
|
obj = { name: m.components.default.name, path: path, query: query }
|
2021-11-19 14:53:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-27 10:05:55 +08:00
|
|
|
|
})
|
2021-11-19 14:53:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
return store.dispatch('tagsView/delCachedView', obj).then(() => {
|
2022-01-18 11:29:31 +08:00
|
|
|
|
const { path, query } = obj
|
2021-11-19 14:53:40 +08:00
|
|
|
|
router.replace({
|
2022-01-18 11:29:31 +08:00
|
|
|
|
path: '/redirect' + path,
|
|
|
|
|
|
query: query
|
2021-11-19 14:53:40 +08:00
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
// 关闭当前tab页签,打开新页签
|
|
|
|
|
|
closeOpenPage(obj) {
|
2025-04-27 10:05:55 +08:00
|
|
|
|
store.dispatch("tagsView/delView", router.currentRoute)
|
2021-11-19 14:53:40 +08:00
|
|
|
|
if (obj !== undefined) {
|
2025-04-27 10:05:55 +08:00
|
|
|
|
return router.push(obj)
|
2021-11-19 14:53:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// 关闭指定tab页签
|
|
|
|
|
|
closePage(obj) {
|
|
|
|
|
|
if (obj === undefined) {
|
2023-03-10 18:04:56 +08:00
|
|
|
|
return store.dispatch('tagsView/delView', router.currentRoute).then(({ visitedViews }) => {
|
|
|
|
|
|
const latestView = visitedViews.slice(-1)[0]
|
|
|
|
|
|
if (latestView) {
|
2023-11-29 12:38:45 +08:00
|
|
|
|
return router.push(latestView.fullPath)
|
2023-03-10 18:04:56 +08:00
|
|
|
|
}
|
2025-04-27 10:05:55 +08:00
|
|
|
|
return router.push('/')
|
|
|
|
|
|
})
|
2021-11-19 14:53:40 +08:00
|
|
|
|
}
|
2025-04-27 10:05:55 +08:00
|
|
|
|
return store.dispatch('tagsView/delView', obj)
|
2021-11-19 14:53:40 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 关闭所有tab页签
|
|
|
|
|
|
closeAllPage() {
|
2025-04-27 10:05:55 +08:00
|
|
|
|
return store.dispatch('tagsView/delAllViews')
|
2021-11-19 14:53:40 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 关闭左侧tab页签
|
|
|
|
|
|
closeLeftPage(obj) {
|
2025-04-27 10:05:55 +08:00
|
|
|
|
return store.dispatch('tagsView/delLeftTags', obj || router.currentRoute)
|
2021-11-19 14:53:40 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 关闭右侧tab页签
|
|
|
|
|
|
closeRightPage(obj) {
|
2025-04-27 10:05:55 +08:00
|
|
|
|
return store.dispatch('tagsView/delRightTags', obj || router.currentRoute)
|
2021-11-19 14:53:40 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 关闭其他tab页签
|
|
|
|
|
|
closeOtherPage(obj) {
|
2025-04-27 10:05:55 +08:00
|
|
|
|
return store.dispatch('tagsView/delOthersViews', obj || router.currentRoute)
|
2021-11-19 14:53:40 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 添加tab页签
|
2022-04-08 15:42:10 +08:00
|
|
|
|
openPage(title, url, params) {
|
2023-11-30 09:37:36 +08:00
|
|
|
|
const obj = { path: url, meta: { title: title } }
|
2025-04-27 10:05:55 +08:00
|
|
|
|
store.dispatch('tagsView/addView', obj)
|
|
|
|
|
|
return router.push({ path: url, query: params })
|
2021-11-19 14:53:40 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 修改tab页签
|
|
|
|
|
|
updatePage(obj) {
|
2025-04-27 10:05:55 +08:00
|
|
|
|
return store.dispatch('tagsView/updateVisitedView', obj)
|
2021-11-19 14:53:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|