'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;
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:
//

View File

@ -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();