tab.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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(({ lastPath }) => {
  35. return router.push(lastPath || '/');
  36. });
  37. }
  38. if (typeof obj === "function") {
  39. return store.dispatch('tagsView/delView', router.currentRoute).then(obj);
  40. }
  41. return store.dispatch('tagsView/delView', obj);
  42. },
  43. // 关闭所有tab页签
  44. closeAllPage() {
  45. return store.dispatch('tagsView/delAllViews');
  46. },
  47. // 关闭左侧tab页签
  48. closeLeftPage(obj) {
  49. return store.dispatch('tagsView/delLeftTags', obj || router.currentRoute);
  50. },
  51. // 关闭右侧tab页签
  52. closeRightPage(obj) {
  53. return store.dispatch('tagsView/delRightTags', obj || router.currentRoute);
  54. },
  55. // 关闭其他tab页签
  56. closeOtherPage(obj) {
  57. return store.dispatch('tagsView/delOthersViews', obj || router.currentRoute);
  58. },
  59. // 添加tab页签
  60. openPage(title, url, params) {
  61. const obj = { path: url, meta: { title: title } }
  62. store.dispatch('tagsView/addView', obj);
  63. return router.push({ path: url, query: params });
  64. },
  65. // 修改tab页签
  66. updatePage(obj) {
  67. return store.dispatch('tagsView/updateVisitedView', obj);
  68. }
  69. }