feat: 流程详情页打开后,关闭跳回对应的列表页

This commit is contained in:
gaoyunqi
2024-04-22 12:34:17 +08:00
parent 8b0174ddb9
commit 66669b7888
5 changed files with 22 additions and 6 deletions

View File

@ -32,12 +32,16 @@ export function setupRouterGuard(router: Router) {
function createPageGuard(router: Router) {
const loadedPageMap = new Map<string, boolean>();
router.beforeEach(async (to) => {
router.beforeEach(async (to, from) => {
// The page has already been loaded, it will be faster to open it again, you dont need to do loading and other processing
to.meta.loaded = !!loadedPageMap.get(to.path);
// Notify routing changes
setRouteChange(to);
const toPath = to.path;
if (toPath.indexOf('views/secondDev') >= 0 || toPath.indexOf('/viewForm') >= 0) {
// 记录从哪里来的 关闭页面的时候好跳回去
localStorage.setItem('parentRoutePath', from.path);
}
return true;
});

View File

@ -184,7 +184,7 @@ export const useMultipleTabStore = defineStore({
}
},
async closeTab(tab: RouteLocationNormalized, router: Router) {
async closeTab(tab: RouteLocationNormalized, router: Router, backTo: String) {
const close = (route: RouteLocationNormalized) => {
const { fullPath, meta: { affix } = {} } = route;
if (affix) {
@ -207,6 +207,7 @@ export const useMultipleTabStore = defineStore({
let toTarget: RouteLocationRaw = {};
const index = this.tabList.findIndex((item) => item.path === path);
const backToIndex = backTo ? this.tabList.findIndex((item) => item.path === backTo) : -1;
// If the current is the leftmost tab
if (index === 0) {
@ -224,6 +225,11 @@ export const useMultipleTabStore = defineStore({
const page = this.tabList[index - 1];
toTarget = getToTarget(page);
}
if (backToIndex >= 0) {
const tabPage = this.tabList[backToIndex];
toTarget = getToTarget(tabPage);
}
close(currentRoute.value);
await replace(toTarget);
},

View File

@ -75,6 +75,8 @@ const { bus, FLOW_PROCESSED } = useEventBus();
const tabStore = useMultipleTabStore();
const router = useRouter();
const currentRoute = router.currentRoute.value;
const parentRoutePath = localStorage.getItem('parentRoutePath');
localStorage.removeItem('parentRoutePath');
const fullPath = currentRoute.fullPath;
const rQuery = currentRoute.query;
const rParams = currentRoute.params;
@ -122,7 +124,7 @@ function openFlowChart() {
}
function close() {
tabStore.closeTab(currentRoute, router);
tabStore.closeTab(currentRoute, router, parentRoutePath);
}
async function onApproveClick() {

View File

@ -80,6 +80,8 @@ const { data, approveUserData, initProcessData, notificationSuccess, notificatio
const currentRoute = router.currentRoute.value;
const rParams = currentRoute.params;
const fullPath = currentRoute.fullPath;
const parentRoutePath = localStorage.getItem('parentRoutePath');
localStorage.removeItem('parentRoutePath');
const rSchemaId = rParams.arg1;
const rDraftsId = rParams.arg2;
const taskId = ref();
@ -123,7 +125,7 @@ function openFlowChart() {
}
function close() {
tabStore.closeTab(currentRoute, router);
tabStore.closeTab(currentRoute, router, parentRoutePath);
}
const props = defineProps({

View File

@ -41,6 +41,8 @@ const { currentRoute } = router;
const { formPath } = currentRoute.value.query;
const pathArr = formPath.split('/');
const parentRoutePath = localStorage.getItem('parentRoutePath');
localStorage.removeItem('parentRoutePath');
const tabStore = useMultipleTabStore();
const formProps = ref(null);
@ -80,7 +82,7 @@ async function setFormType() {
}
function close() {
tabStore.closeTab(currentRoute.value, router);
tabStore.closeTab(currentRoute.value, router, parentRoutePath);
}
async function handleSubmit() {