'admin-22.11.19:修复v2.3.0版本动态路由事件调用关闭当前tagsview、普通路由刷新界面参数丢失问题'

This commit is contained in:
lyt 2022-11-19 00:09:19 +08:00
parent f9ce14431d
commit 161748a549
2 changed files with 26 additions and 19 deletions

View File

@ -101,6 +101,7 @@ interface CurrentContextmenu {
query: any; query: any;
path: string; path: string;
contextMenuClickId: string | number; contextMenuClickId: string | number;
commonUrl: string;
} }
export default defineComponent({ export default defineComponent({
@ -357,29 +358,34 @@ export default defineComponent({
else await router.push({ name: item.name, query: item.query }); else await router.push({ name: item.name, query: item.query });
stores.setCurrenFullscreen(true); stores.setCurrenFullscreen(true);
}; };
// tagsView // `` `tagsView `
// tagsView // tagsView
const getCurrentRouteItem = (path: string, cParams: any) => { // https://gitee.com/lyt-top/vue-next-admin/issues/I61VS9
const itemRoute = Session.get('tagsViewList') ? Session.get('tagsViewList') : state.tagsViewList; const getCurrentRouteItem = (item: any) => {
return itemRoute.find((v: any) => { let resItem: any = {};
if ( state.tagsViewList.forEach((v: any) => {
v.path === path && v.transUrl = transUrlParams(v);
isObjectValueEqual( if (v.transUrl) {
v.meta.isDynamic ? (v.params ? v.params : null) : v.query ? v.query : null, if (v.meta.isDynamic) {
cParams && Object.keys(cParams ? cParams : {}).length > 0 ? cParams : null // xxx/:id/:name"isDynamic
) if (v.transUrl === transUrlParams(v) && v.transUrl === decodeURI(item.path)) resItem = v;
) { } else {
return v; // tagsView /
} else if (v.path === path && Object.keys(cParams ? cParams : {}).length <= 0) { if (v.transUrl === transUrlParams(v) && v.transUrl === item.commonUrl) resItem = v;
return v; }
} else {
//
if (v.path === decodeURI(item.path)) resItem = v;
} }
}); });
if (!resItem) return null;
else return resItem;
}; };
// //
const onCurrentContextmenuClick = async (item: CurrentContextmenu) => { const onCurrentContextmenuClick = async (item: CurrentContextmenu) => {
const cParams = item.meta.isDynamic ? item.params : item.query; item.commonUrl = transUrlParams(item);
if (!getCurrentRouteItem(item.path, cParams)) return ElMessage({ type: 'warning', message: '请正确输入路径及完整参数query、params' }); if (!getCurrentRouteItem(item)) return ElMessage({ type: 'warning', message: '请正确输入路径及完整参数query、params' });
const { path, name, params, query, meta, url } = getCurrentRouteItem(item.path, cParams); const { path, name, params, query, meta, url } = getCurrentRouteItem(item);
switch (item.contextMenuClickId) { switch (item.contextMenuClickId) {
case 0: case 0:
// //

View File

@ -114,11 +114,12 @@ router.beforeEach(async (to, from, next) => {
// 后端控制路由:路由数据初始化,防止刷新时丢失 // 后端控制路由:路由数据初始化,防止刷新时丢失
await initBackEndControlRoutes(); await initBackEndControlRoutes();
// 解决刷新时,一直跳 404 页面问题,关联问题 No match found for location with path 'xxx' // 解决刷新时,一直跳 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 { } else {
// https://gitee.com/lyt-top/vue-next-admin/issues/I5F1HP // https://gitee.com/lyt-top/vue-next-admin/issues/I5F1HP
await initFrontEndControlRoutes(); await initFrontEndControlRoutes();
next({ path: to.path }); next({ path: to.path, query: to.query });
} }
} else { } else {
next(); next();