动态路由匹配右键重新加载404

pull/975/head
zhangdaiscott 2023-11-23 23:01:27 +08:00
parent 7f6f07f72c
commit d0ff2225c7
3 changed files with 50 additions and 47 deletions

View File

@ -7,6 +7,7 @@ import { unref } from 'vue';
import { useRouter } from 'vue-router';
import { REDIRECT_NAME } from '/@/router/constant';
import { useUserStore } from '/@/store/modules/user';
import { useMultipleTabStore } from '/@/store/modules/multipleTab';
export type RouteLocationRawEx = Omit<RouteLocationRaw, 'path'> & { path: PageEnum };
@ -51,40 +52,27 @@ export const useRedo = (_router?: Router) => {
resolve(false);
return;
}
// update-begin--author:liaozhiyang---date:20231123---for【QQYUN-7099】动态路由匹配右键重新加载404
const tabStore = useMultipleTabStore();
if (name && Object.keys(params).length > 0) {
//update-begin-author:taoyan date:2022-10-19 for: VUEN-2356 【vue3】online表单、表单设计器 功能测试 右键刷新时 404
if(isDynamicRoute(params, name)){
params['_redirect_type'] = 'path';
params['path'] = fullPath;
}else{
params['_redirect_type'] = 'name';
params['path'] = String(name);
}
//update-end-author:taoyan date:2022-10-19 for: VUEN-2356 【vue3】online表单、表单设计器 功能测试 右键刷新时 404
tabStore.setRedirectPageParam({
redirect_type: 'name',
name: String(name),
params,
query,
});
params['path'] = String(name);
} else {
params['_redirect_type'] = 'path';
tabStore.setRedirectPageParam({
redirect_type: 'path',
path: fullPath,
query,
});
params['path'] = fullPath;
}
// update-end--author:liaozhiyang---date:20231123---for【QQYUN-7099】动态路由匹配右键重新加载404
push({ name: REDIRECT_NAME, params, query }).then(() => resolve(true));
});
}
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;
}

View File

@ -14,11 +14,21 @@ import { MULTIPLE_TABS_KEY } from '/@/enums/cacheEnum';
import projectSetting from '/@/settings/projectSetting';
import { useUserStore } from '/@/store/modules/user';
import type { LocationQueryRaw, RouteParamsRaw } from 'vue-router';
export interface MultipleTabState {
cacheTabList: Set<string>;
tabList: RouteLocationNormalized[];
lastDragEndIndex: number;
redirectPageParam: null | redirectPageParamType;
}
interface redirectPageParamType {
redirect_type: string;
name?: string;
path?: string;
query: LocationQueryRaw;
params?: RouteParamsRaw;
}
function handleGotoPage(router: Router) {
@ -45,6 +55,8 @@ export const useMultipleTabStore = defineStore({
tabList: cacheTab ? Persistent.getLocal(MULTIPLE_TABS_KEY) || [] : [],
// Index of the last moved tab
lastDragEndIndex: 0,
// 重定向时存储的路由参数
redirectPageParam: null,
}),
getters: {
getTabList(): RouteLocationNormalized[] {
@ -348,6 +360,9 @@ export const useMultipleTabStore = defineStore({
await this.updateCacheTab();
}
},
setRedirectPageParam(data) {
this.redirectPageParam = data;
},
},
});

View File

@ -4,27 +4,27 @@
<script lang="ts" setup>
import { unref } from 'vue';
import { useRouter } from 'vue-router';
import { useMultipleTabStore } from '/@/store/modules/multipleTab';
// update-begin--author:liaozhiyang---date:20231123---forQQYUN-7099404
const { currentRoute, replace } = useRouter();
const { params, query } = unref(currentRoute);
const { path, _redirect_type = 'path' } = params;
Reflect.deleteProperty(params, '_redirect_type');
Reflect.deleteProperty(params, 'path');
const { path } = params;
const tabStore = useMultipleTabStore();
const redirectPageParam = tabStore.redirectPageParam;
const _path = Array.isArray(path) ? path.join('/') : path;
if (_redirect_type === 'name') {
replace({
name: _path,
query,
params,
});
} else {
replace({
path: _path.startsWith('/') ? _path : '/' + _path,
query,
});
if (redirectPageParam) {
if (redirectPageParam.redirect_type === 'name') {
replace({
name: redirectPageParam.name,
query: redirectPageParam.query,
params: redirectPageParam.params,
});
} else {
replace({
path: _path.startsWith('/') ? _path : '/' + _path,
query,
});
}
}
// update-end--author:liaozhiyang---date:20231123---forQQYUN-7099404
</script>