tab.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import store from '@/store'
  2. import router from '@/router';
  3. export default {
  4. // 刷新当前tab页签
  5. refreshPage(obj) {
  6. const { path, 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 };
  12. }
  13. }
  14. });
  15. }
  16. return store.dispatch('tagsView/delCachedView', obj).then(() => {
  17. const { path } = obj
  18. router.replace({
  19. path: '/redirect' + path
  20. })
  21. })
  22. },
  23. // 关闭当前tab页签,打开新页签
  24. closeOpenPage(obj) {
  25. store.dispatch("tagsView/delView", router.currentRoute);
  26. if (obj !== undefined) {
  27. return router.push(obj);
  28. }
  29. },
  30. // 关闭指定tab页签
  31. closePage(obj) {
  32. if (obj === undefined) {
  33. return store.dispatch('tagsView/delView', router.currentRoute).then(({ lastPath }) => {
  34. return router.push(lastPath || '/');
  35. });
  36. }
  37. return store.dispatch('tagsView/delView', obj);
  38. },
  39. // 关闭所有tab页签
  40. closeAllPage() {
  41. return store.dispatch('tagsView/delAllViews');
  42. },
  43. // 关闭左侧tab页签
  44. closeLeftPage(obj) {
  45. return store.dispatch('tagsView/delLeftTags', obj || router.currentRoute);
  46. },
  47. // 关闭右侧tab页签
  48. closeRightPage(obj) {
  49. return store.dispatch('tagsView/delRightTags', obj || router.currentRoute);
  50. },
  51. // 关闭其他tab页签
  52. closeOtherPage(obj) {
  53. return store.dispatch('tagsView/delOthersViews', obj || router.currentRoute);
  54. },
  55. // 添加tab页签
  56. addPage(title, url) {
  57. var obj = { path: url, meta: { title: title } }
  58. store.dispatch('tagsView/addView', obj);
  59. return router.push(url);
  60. },
  61. // 修改tab页签
  62. updatePage(obj) {
  63. return store.dispatch('tagsView/updateVisitedView', obj);
  64. }
  65. }