动态路由匹配右键重新加载404
parent
7f6f07f72c
commit
d0ff2225c7
|
@ -7,6 +7,7 @@ import { unref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { REDIRECT_NAME } from '/@/router/constant';
|
import { REDIRECT_NAME } from '/@/router/constant';
|
||||||
import { useUserStore } from '/@/store/modules/user';
|
import { useUserStore } from '/@/store/modules/user';
|
||||||
|
import { useMultipleTabStore } from '/@/store/modules/multipleTab';
|
||||||
|
|
||||||
export type RouteLocationRawEx = Omit<RouteLocationRaw, 'path'> & { path: PageEnum };
|
export type RouteLocationRawEx = Omit<RouteLocationRaw, 'path'> & { path: PageEnum };
|
||||||
|
|
||||||
|
@ -51,40 +52,27 @@ export const useRedo = (_router?: Router) => {
|
||||||
resolve(false);
|
resolve(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// update-begin--author:liaozhiyang---date:20231123---for:【QQYUN-7099】动态路由匹配右键重新加载404
|
||||||
|
const tabStore = useMultipleTabStore();
|
||||||
if (name && Object.keys(params).length > 0) {
|
if (name && Object.keys(params).length > 0) {
|
||||||
//update-begin-author:taoyan date:2022-10-19 for: VUEN-2356 【vue3】online表单、表单设计器 功能测试 右键刷新时 404
|
tabStore.setRedirectPageParam({
|
||||||
if(isDynamicRoute(params, name)){
|
redirect_type: 'name',
|
||||||
params['_redirect_type'] = 'path';
|
name: String(name),
|
||||||
params['path'] = fullPath;
|
params,
|
||||||
}else{
|
query,
|
||||||
params['_redirect_type'] = 'name';
|
});
|
||||||
params['path'] = String(name);
|
params['path'] = String(name);
|
||||||
}
|
|
||||||
//update-end-author:taoyan date:2022-10-19 for: VUEN-2356 【vue3】online表单、表单设计器 功能测试 右键刷新时 404
|
|
||||||
} else {
|
} else {
|
||||||
params['_redirect_type'] = 'path';
|
tabStore.setRedirectPageParam({
|
||||||
|
redirect_type: 'path',
|
||||||
|
path: fullPath,
|
||||||
|
query,
|
||||||
|
});
|
||||||
params['path'] = fullPath;
|
params['path'] = fullPath;
|
||||||
}
|
}
|
||||||
|
// update-end--author:liaozhiyang---date:20231123---for:【QQYUN-7099】动态路由匹配右键重新加载404
|
||||||
push({ name: REDIRECT_NAME, params, query }).then(() => resolve(true));
|
push({ name: REDIRECT_NAME, params, query }).then(() => resolve(true));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return redo;
|
return redo;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断是不是动态路由的跳转
|
|
||||||
* @param params
|
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
function isDynamicRoute(params, name){
|
|
||||||
let arr = Object.keys(params);
|
|
||||||
let flag = false;
|
|
||||||
for(let i=0;i<arr.length;i++){
|
|
||||||
let key = '@'+arr[i];
|
|
||||||
if((name as string).indexOf(key)>0){
|
|
||||||
flag = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,11 +14,21 @@ import { MULTIPLE_TABS_KEY } from '/@/enums/cacheEnum';
|
||||||
|
|
||||||
import projectSetting from '/@/settings/projectSetting';
|
import projectSetting from '/@/settings/projectSetting';
|
||||||
import { useUserStore } from '/@/store/modules/user';
|
import { useUserStore } from '/@/store/modules/user';
|
||||||
|
import type { LocationQueryRaw, RouteParamsRaw } from 'vue-router';
|
||||||
|
|
||||||
export interface MultipleTabState {
|
export interface MultipleTabState {
|
||||||
cacheTabList: Set<string>;
|
cacheTabList: Set<string>;
|
||||||
tabList: RouteLocationNormalized[];
|
tabList: RouteLocationNormalized[];
|
||||||
lastDragEndIndex: number;
|
lastDragEndIndex: number;
|
||||||
|
redirectPageParam: null | redirectPageParamType;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface redirectPageParamType {
|
||||||
|
redirect_type: string;
|
||||||
|
name?: string;
|
||||||
|
path?: string;
|
||||||
|
query: LocationQueryRaw;
|
||||||
|
params?: RouteParamsRaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleGotoPage(router: Router) {
|
function handleGotoPage(router: Router) {
|
||||||
|
@ -45,6 +55,8 @@ export const useMultipleTabStore = defineStore({
|
||||||
tabList: cacheTab ? Persistent.getLocal(MULTIPLE_TABS_KEY) || [] : [],
|
tabList: cacheTab ? Persistent.getLocal(MULTIPLE_TABS_KEY) || [] : [],
|
||||||
// Index of the last moved tab
|
// Index of the last moved tab
|
||||||
lastDragEndIndex: 0,
|
lastDragEndIndex: 0,
|
||||||
|
// 重定向时存储的路由参数
|
||||||
|
redirectPageParam: null,
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
getTabList(): RouteLocationNormalized[] {
|
getTabList(): RouteLocationNormalized[] {
|
||||||
|
@ -348,6 +360,9 @@ export const useMultipleTabStore = defineStore({
|
||||||
await this.updateCacheTab();
|
await this.updateCacheTab();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setRedirectPageParam(data) {
|
||||||
|
this.redirectPageParam = data;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -4,22 +4,20 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { unref } from 'vue';
|
import { unref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
import { useMultipleTabStore } from '/@/store/modules/multipleTab';
|
||||||
|
// update-begin--author:liaozhiyang---date:20231123---for:【QQYUN-7099】动态路由匹配右键重新加载404
|
||||||
const { currentRoute, replace } = useRouter();
|
const { currentRoute, replace } = useRouter();
|
||||||
|
|
||||||
const { params, query } = unref(currentRoute);
|
const { params, query } = unref(currentRoute);
|
||||||
const { path, _redirect_type = 'path' } = params;
|
const { path } = params;
|
||||||
|
const tabStore = useMultipleTabStore();
|
||||||
Reflect.deleteProperty(params, '_redirect_type');
|
const redirectPageParam = tabStore.redirectPageParam;
|
||||||
Reflect.deleteProperty(params, 'path');
|
|
||||||
|
|
||||||
const _path = Array.isArray(path) ? path.join('/') : path;
|
const _path = Array.isArray(path) ? path.join('/') : path;
|
||||||
|
if (redirectPageParam) {
|
||||||
if (_redirect_type === 'name') {
|
if (redirectPageParam.redirect_type === 'name') {
|
||||||
replace({
|
replace({
|
||||||
name: _path,
|
name: redirectPageParam.name,
|
||||||
query,
|
query: redirectPageParam.query,
|
||||||
params,
|
params: redirectPageParam.params,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
replace({
|
replace({
|
||||||
|
@ -27,4 +25,6 @@
|
||||||
query,
|
query,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// update-end--author:liaozhiyang---date:20231123---for:【QQYUN-7099】动态路由匹配右键重新加载404
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue