From 8e0415a8fea1193bd166301d3bd98d03735baa0b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 17 Feb 2022 15:21:46 +0800 Subject: [PATCH] =?UTF-8?q?v3.8.0=20=E6=96=B0=E5=A2=9Etab=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=AE=80=E5=8C=96=E9=A1=B5=E7=AD=BE=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin/src/plugins/index.js | 3 + yudao-ui-admin/src/plugins/tab.js | 67 +++++++++++++++++++ yudao-ui-admin/src/store/modules/tagsView.js | 2 +- .../src/views/bpm/form/formEditor.vue | 3 +- .../src/views/bpm/model/modelEditor.vue | 3 +- .../src/views/bpm/oa/leave/create.vue | 3 +- .../src/views/bpm/processInstance/create.vue | 2 +- .../src/views/bpm/processInstance/detail.vue | 2 +- .../views/system/user/profile/resetPwd.vue | 3 +- .../views/system/user/profile/userInfo.vue | 3 +- .../views/system/user/profile/userSocial.vue | 3 +- .../src/views/tool/codegen/editTable.vue | 6 +- 12 files changed, 83 insertions(+), 17 deletions(-) create mode 100644 yudao-ui-admin/src/plugins/tab.js diff --git a/yudao-ui-admin/src/plugins/index.js b/yudao-ui-admin/src/plugins/index.js index d1cb4dbb4..d000f2dfa 100644 --- a/yudao-ui-admin/src/plugins/index.js +++ b/yudao-ui-admin/src/plugins/index.js @@ -1,3 +1,4 @@ +import tab from './tab' import auth from './auth' import cache from './cache' import modal from './modal' @@ -5,6 +6,8 @@ import download from './download' export default { install(Vue) { + // 页签操作 + Vue.prototype.$tab = tab // 认证对象 Vue.prototype.$auth = auth // 缓存对象 diff --git a/yudao-ui-admin/src/plugins/tab.js b/yudao-ui-admin/src/plugins/tab.js new file mode 100644 index 000000000..f5d7a3e0f --- /dev/null +++ b/yudao-ui-admin/src/plugins/tab.js @@ -0,0 +1,67 @@ +import store from '@/store' +import router from '@/router'; + +export default { + // 刷新当前tab页签 + refreshPage(obj) { + const { path, query, matched } = router.currentRoute; + if (obj === undefined) { + matched.forEach((m) => { + if (m.components && m.components.default && m.components.default.name) { + if (!['Layout', 'ParentView'].includes(m.components.default.name)) { + obj = { name: m.components.default.name, path: path, query: query }; + } + } + }); + } + return store.dispatch('tagsView/delCachedView', obj).then(() => { + const { path, query } = obj + router.replace({ + path: '/redirect' + path, + query: query + }) + }) + }, + // 关闭当前tab页签,打开新页签 + closeOpenPage(obj) { + store.dispatch("tagsView/delView", router.currentRoute); + if (obj !== undefined) { + return router.push(obj); + } + }, + // 关闭指定tab页签 + closePage(obj) { + if (obj === undefined) { + return store.dispatch('tagsView/delView', router.currentRoute).then(({ lastPath }) => { + return router.push(lastPath || '/'); + }); + } + return store.dispatch('tagsView/delView', obj); + }, + // 关闭所有tab页签 + closeAllPage() { + return store.dispatch('tagsView/delAllViews'); + }, + // 关闭左侧tab页签 + closeLeftPage(obj) { + return store.dispatch('tagsView/delLeftTags', obj || router.currentRoute); + }, + // 关闭右侧tab页签 + closeRightPage(obj) { + return store.dispatch('tagsView/delRightTags', obj || router.currentRoute); + }, + // 关闭其他tab页签 + closeOtherPage(obj) { + return store.dispatch('tagsView/delOthersViews', obj || router.currentRoute); + }, + // 添加tab页签 + openPage(title, url) { + var obj = { path: url, meta: { title: title } } + store.dispatch('tagsView/addView', obj); + return router.push(url); + }, + // 修改tab页签 + updatePage(obj) { + return store.dispatch('tagsView/updateVisitedView', obj); + } +} diff --git a/yudao-ui-admin/src/store/modules/tagsView.js b/yudao-ui-admin/src/store/modules/tagsView.js index 68bb81d42..5e8f7ff3d 100644 --- a/yudao-ui-admin/src/store/modules/tagsView.js +++ b/yudao-ui-admin/src/store/modules/tagsView.js @@ -14,7 +14,7 @@ const mutations = { }, ADD_CACHED_VIEW: (state, view) => { if (state.cachedViews.includes(view.name)) return - if (!view.meta.noCache) { + if (view.meta && !view.meta.noCache) { state.cachedViews.push(view.name) } }, diff --git a/yudao-ui-admin/src/views/bpm/form/formEditor.vue b/yudao-ui-admin/src/views/bpm/form/formEditor.vue index 2afcd57fb..913ad5db2 100644 --- a/yudao-ui-admin/src/views/bpm/form/formEditor.vue +++ b/yudao-ui-admin/src/views/bpm/form/formEditor.vue @@ -449,8 +449,7 @@ export default { }, /** 关闭按钮 */ close() { - this.$store.dispatch("tagsView/delView", this.$route); - this.$router.push({ path: "/bpm/manager/form", query: { t: Date.now()}}) + this.$tab.closeOpenPage({ path: "/bpm/manager/form" }); }, encodeFields() { const fields = [] diff --git a/yudao-ui-admin/src/views/bpm/model/modelEditor.vue b/yudao-ui-admin/src/views/bpm/model/modelEditor.vue index c9b421a34..f6b8183ff 100644 --- a/yudao-ui-admin/src/views/bpm/model/modelEditor.vue +++ b/yudao-ui-admin/src/views/bpm/model/modelEditor.vue @@ -111,8 +111,7 @@ export default { }, /** 关闭按钮 */ close() { - this.$store.dispatch("tagsView/delView", this.$route); - this.$router.push({ path: "/bpm/manager/model", query: { t: Date.now()}}) + this.$tab.closeOpenPage({ path: "/bpm/manager/model" }); }, } }; diff --git a/yudao-ui-admin/src/views/bpm/oa/leave/create.vue b/yudao-ui-admin/src/views/bpm/oa/leave/create.vue index 4dfca8b4f..14b6ed566 100644 --- a/yudao-ui-admin/src/views/bpm/oa/leave/create.vue +++ b/yudao-ui-admin/src/views/bpm/oa/leave/create.vue @@ -66,8 +66,7 @@ export default { // 添加的提交 createLeave(this.form).then(response => { this.$modal.msgSuccess("发起成功"); - this.$store.dispatch("tagsView/delView", this.$route); - this.$router.push({ path: "/bpm/oa/leave"}); + this.$tab.closeOpenPage({ path: "/bpm/oa/leave" }); }); }); } diff --git a/yudao-ui-admin/src/views/bpm/processInstance/create.vue b/yudao-ui-admin/src/views/bpm/processInstance/create.vue index 3eeb29bc3..0e9482d47 100644 --- a/yudao-ui-admin/src/views/bpm/processInstance/create.vue +++ b/yudao-ui-admin/src/views/bpm/processInstance/create.vue @@ -146,7 +146,7 @@ export default { }).then(response => { this.$modal.msgSuccess("发起流程成功"); // 关闭当前窗口 - this.$store.dispatch("tagsView/delView", this.$route); + this.$tab.closeOpenPage(); this.$router.go(-1); }).catch(() => { conf.disabled = false; // 表单开启 diff --git a/yudao-ui-admin/src/views/bpm/processInstance/detail.vue b/yudao-ui-admin/src/views/bpm/processInstance/detail.vue index b989f1216..f5d4992c2 100644 --- a/yudao-ui-admin/src/views/bpm/processInstance/detail.vue +++ b/yudao-ui-admin/src/views/bpm/processInstance/detail.vue @@ -302,7 +302,7 @@ export default { }).then(response => { this.$modal.msgSuccess("发起流程成功"); // 关闭当前窗口 - this.$store.dispatch("tagsView/delView", this.$route); + this.$tab.closeOpenPage(); this.$router.go(-1); }).catch(() => { conf.disabled = false; // 表单开启 diff --git a/yudao-ui-admin/src/views/system/user/profile/resetPwd.vue b/yudao-ui-admin/src/views/system/user/profile/resetPwd.vue index 5870ff1cd..d769868dd 100644 --- a/yudao-ui-admin/src/views/system/user/profile/resetPwd.vue +++ b/yudao-ui-admin/src/views/system/user/profile/resetPwd.vue @@ -64,8 +64,7 @@ export default { }); }, close() { - this.$store.dispatch("tagsView/delView", this.$route); - this.$router.push({ path: "/index" }); + this.$tab.closePage(); } } }; diff --git a/yudao-ui-admin/src/views/system/user/profile/userInfo.vue b/yudao-ui-admin/src/views/system/user/profile/userInfo.vue index 86ae6ac48..cffccc87d 100644 --- a/yudao-ui-admin/src/views/system/user/profile/userInfo.vue +++ b/yudao-ui-admin/src/views/system/user/profile/userInfo.vue @@ -68,8 +68,7 @@ export default { }); }, close() { - this.$store.dispatch("tagsView/delView", this.$route); - this.$router.push({ path: "/index" }); + this.$tab.closePage(); } } }; diff --git a/yudao-ui-admin/src/views/system/user/profile/userSocial.vue b/yudao-ui-admin/src/views/system/user/profile/userSocial.vue index 2855fa99c..670ee423d 100644 --- a/yudao-ui-admin/src/views/system/user/profile/userSocial.vue +++ b/yudao-ui-admin/src/views/system/user/profile/userSocial.vue @@ -92,8 +92,7 @@ export default { }); }, close() { - this.$store.dispatch("tagsView/delView", this.$route); - this.$router.push({ path: "/index" }); + this.$tab.closePage(); } } }; diff --git a/yudao-ui-admin/src/views/tool/codegen/editTable.vue b/yudao-ui-admin/src/views/tool/codegen/editTable.vue index e9093166d..8f2512903 100644 --- a/yudao-ui-admin/src/views/tool/codegen/editTable.vue +++ b/yudao-ui-admin/src/views/tool/codegen/editTable.vue @@ -211,8 +211,10 @@ export default { }, /** 关闭按钮 */ close() { - this.$store.dispatch("tagsView/delView", this.$route); - this.$router.push({ path: "/tool/codegen", query: { t: Date.now()}}) + this.$tab.closeOpenPage({ + path: "/tool/codegen", + query: { t: Date.now(), pageNum: this.$route.query.pageNum } } + ); } }, mounted() {