1
0
forked from ruoyi/RuoYi-Vue
Files
RuoYi-Vue/ruoyi-ui/src/plugins/tab.js

72 lines
2.2 KiB
JavaScript
Raw Normal View History

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(() => {
const { path, query } = obj
2021-11-19 14:53:40 +08:00
router.replace({
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) {
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)
}
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
}
}