tab.js 2.0 KB

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