tab.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import store from '@/store'
  2. import router from '@/router'
  3. export default {
  4. // 刷新当前tab页签
  5. refreshPage(obj) {
  6. const { path, query, matched } = router.currentRoute
  7. if (obj === undefined) {
  8. matched.forEach((m) => {
  9. if (m.components && m.components.default && m.components.default.name) {
  10. if (!['Layout', 'ParentView'].includes(m.components.default.name)) {
  11. obj = { name: m.components.default.name, path: path, query: query }
  12. }
  13. }
  14. })
  15. }
  16. return store.dispatch('tagsView/delCachedView', obj).then(() => {
  17. const { path, query } = obj
  18. router.replace({
  19. path: '/redirect' + path,
  20. query: query
  21. })
  22. })
  23. },
  24. // 关闭当前tab页签,打开新页签
  25. closeOpenPage(obj) {
  26. store.dispatch("tagsView/delView", router.currentRoute)
  27. if (obj !== undefined) {
  28. return router.push(obj)
  29. }
  30. },
  31. // 关闭指定tab页签
  32. closePage(obj) {
  33. if (obj === undefined) {
  34. return store.dispatch('tagsView/delView', router.currentRoute).then(({ visitedViews }) => {
  35. const latestView = visitedViews.slice(-1)[0]
  36. if (latestView) {
  37. return router.push(latestView.fullPath)
  38. }
  39. return router.push('/')
  40. })
  41. }
  42. return store.dispatch('tagsView/delView', obj)
  43. },
  44. // 关闭所有tab页签
  45. closeAllPage() {
  46. return store.dispatch('tagsView/delAllViews')
  47. },
  48. // 关闭左侧tab页签
  49. closeLeftPage(obj) {
  50. return store.dispatch('tagsView/delLeftTags', obj || router.currentRoute)
  51. },
  52. // 关闭右侧tab页签
  53. closeRightPage(obj) {
  54. return store.dispatch('tagsView/delRightTags', obj || router.currentRoute)
  55. },
  56. // 关闭其他tab页签
  57. closeOtherPage(obj) {
  58. return store.dispatch('tagsView/delOthersViews', obj || router.currentRoute)
  59. },
  60. // 添加tab页签
  61. openPage(title, url, params) {
  62. const obj = { path: url, meta: { title: title } }
  63. store.dispatch('tagsView/addView', obj)
  64. return router.push({ path: url, query: params })
  65. },
  66. // 修改tab页签
  67. updatePage(obj) {
  68. return store.dispatch('tagsView/updateVisitedView', obj)
  69. }
  70. }