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