From 161748a549664812c3dded853f20d92ffa5bfdbb Mon Sep 17 00:00:00 2001 From: lyt <1105290566@qq.com> Date: Sat, 19 Nov 2022 00:09:19 +0800 Subject: [PATCH] =?UTF-8?q?'admin-22.11.19:=E4=BF=AE=E5=A4=8Dv2.3.0?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8A=A8=E6=80=81=E8=B7=AF=E7=94=B1=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E8=B0=83=E7=94=A8=E5=85=B3=E9=97=AD=E5=BD=93=E5=89=8D?= =?UTF-8?q?tagsview=E3=80=81=E6=99=AE=E9=80=9A=E8=B7=AF=E7=94=B1=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E7=95=8C=E9=9D=A2=E5=8F=82=E6=95=B0=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E9=97=AE=E9=A2=98'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/navBars/tagsView/tagsView.vue | 40 ++++++++++++++---------- src/router/index.ts | 5 +-- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/layout/navBars/tagsView/tagsView.vue b/src/layout/navBars/tagsView/tagsView.vue index d914d6be..a582375f 100644 --- a/src/layout/navBars/tagsView/tagsView.vue +++ b/src/layout/navBars/tagsView/tagsView.vue @@ -101,6 +101,7 @@ interface CurrentContextmenu { query: any; path: string; contextMenuClickId: string | number; + commonUrl: string; } export default defineComponent({ @@ -357,29 +358,34 @@ export default defineComponent({ else await router.push({ name: item.name, query: item.query }); stores.setCurrenFullscreen(true); }; - // 当前项右键菜单点击,拿当前点击的路由路径对比 浏览器缓存中的 tagsView 路由数组,取当前点击项的详细路由信息 + // 当前项右键菜单点击,拿 `当前点击的路由路径` 对比 `tagsView 路由数组`,取当前点击项的详细路由信息 // 防止 tagsView 非当前页演示时,操作异常 - const getCurrentRouteItem = (path: string, cParams: any) => { - const itemRoute = Session.get('tagsViewList') ? Session.get('tagsViewList') : state.tagsViewList; - return itemRoute.find((v: any) => { - if ( - v.path === path && - isObjectValueEqual( - v.meta.isDynamic ? (v.params ? v.params : null) : v.query ? v.query : null, - cParams && Object.keys(cParams ? cParams : {}).length > 0 ? cParams : null - ) - ) { - return v; - } else if (v.path === path && Object.keys(cParams ? cParams : {}).length <= 0) { - return v; + // https://gitee.com/lyt-top/vue-next-admin/issues/I61VS9 + const getCurrentRouteItem = (item: any) => { + let resItem: any = {}; + state.tagsViewList.forEach((v: any) => { + v.transUrl = transUrlParams(v); + if (v.transUrl) { + if (v.meta.isDynamic) { + // 路由带参数:动态路由(xxx/:id/:name")isDynamic + if (v.transUrl === transUrlParams(v) && v.transUrl === decodeURI(item.path)) resItem = v; + } else { + // 路由带参数:普通路由,因为有 tagsView 共用/不共用 + if (v.transUrl === transUrlParams(v) && v.transUrl === item.commonUrl) resItem = v; + } + } else { + // 路由不带参数 + if (v.path === decodeURI(item.path)) resItem = v; } }); + if (!resItem) return null; + else return resItem; }; // 当前项右键菜单点击 const onCurrentContextmenuClick = async (item: CurrentContextmenu) => { - const cParams = item.meta.isDynamic ? item.params : item.query; - if (!getCurrentRouteItem(item.path, cParams)) return ElMessage({ type: 'warning', message: '请正确输入路径及完整参数(query、params)' }); - const { path, name, params, query, meta, url } = getCurrentRouteItem(item.path, cParams); + item.commonUrl = transUrlParams(item); + if (!getCurrentRouteItem(item)) return ElMessage({ type: 'warning', message: '请正确输入路径及完整参数(query、params)' }); + const { path, name, params, query, meta, url } = getCurrentRouteItem(item); switch (item.contextMenuClickId) { case 0: // 刷新当前 diff --git a/src/router/index.ts b/src/router/index.ts index a3e174f6..a92deabc 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -114,11 +114,12 @@ router.beforeEach(async (to, from, next) => { // 后端控制路由:路由数据初始化,防止刷新时丢失 await initBackEndControlRoutes(); // 解决刷新时,一直跳 404 页面问题,关联问题 No match found for location with path 'xxx' - next({ path: to.path }); + // to.query 防止页面刷新时,普通路由带参数时,参数丢失。动态路由(xxx/:id/:name")isDynamic 无需处理 + next({ path: to.path, query: to.query }); } else { // https://gitee.com/lyt-top/vue-next-admin/issues/I5F1HP await initFrontEndControlRoutes(); - next({ path: to.path }); + next({ path: to.path, query: to.query }); } } else { next();