diff --git a/CHANGELOG.md b/CHANGELOG.md index 098874fd6f380034725618b83a8a71d333e9ec10..54f330398da346197c62ef8e7d6e9b96389f3b4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ ## [Unreleased] +### Fixed + +- 修复打开相同链接视图时路由报错异常 + ## [0.7.38-alpha.55] - 2025-02-07 ### Added diff --git a/src/util/open-view-util/open-view-util.ts b/src/util/open-view-util/open-view-util.ts index c2f83077ad6b8cd3bfc997e58e41f33d105ad744..2926bec3e91bafdad2f15194ae55cb054fe7af46 100644 --- a/src/util/open-view-util/open-view-util.ts +++ b/src/util/open-view-util/open-view-util.ts @@ -1,8 +1,11 @@ import { IModalData, + IOpenViewOptions, IOpenViewUtil, IPopoverOptions, Placement, + Srfuf, + calcDeCodeNameById, } from '@ibiz-template/runtime'; import { generateRoutePath, @@ -15,6 +18,7 @@ import { } from '@ibiz-template/vue3-util'; import { Router } from 'vue-router'; import { UrlHelper } from '@ibiz-template/core'; +import { clone } from 'ramda'; import { FloatingUIConfig } from '../app-popover/app-popover-component'; /** @@ -35,6 +39,72 @@ export class OpenViewUtil implements IOpenViewUtil { return routerCallback.open(this.router, path); } + async verify( + appViewId: string, + _context: IContext, + params: IParams = {}, + opts: IOpenViewOptions = {}, + ): Promise { + const appView = await ibiz.hub.config.view.get(appViewId); + if (!appView) { + return true; + } + if (appView.redirectView) { + return true; + } + const { openMode = 'INDEXVIEWTAB' } = appView; + const viewOpenMode = opts.openMode || openMode; + if ( + viewOpenMode !== 'INDEXVIEWTAB' && + viewOpenMode !== 'INDEXVIEWTAB_POPUP' + ) { + return true; + } + const context = clone(_context); + if (context.srfsimple) { + delete context.srfsimple; + } + if (viewOpenMode !== undefined && viewOpenMode !== 'INDEXVIEWTAB') { + if (context.toRouteDepth) { + context.toRouteDepth = undefined; + } + } + if ( + (context.srfkey || params.srfuf === Srfuf.CREATE) && + appView.appDataEntityId + ) { + const deName = calcDeCodeNameById(appView.appDataEntityId); + if (context.srfkey) { + context[deName] = context.srfkey; + context.srfkey = undefined; + } + if (params.srfuf === Srfuf.CREATE) { + context[deName] = undefined; + delete params.srfuf; + } + } + if (!this.router.currentRoute.value) { + return true; + } + let { path } = await generateRoutePath( + appView, + this.router.currentRoute.value, + context, + params, + ); + if (path.endsWith(`/${ibiz.env.routePlaceholder}`)) { + path = path.slice( + 0, + path.length - (ibiz.env.routePlaceholder.length + 1), + ); + } + const fullPath = this.router.currentRoute.value.fullPath; + if (fullPath && fullPath.startsWith(path)) { + return false; + } + return true; + } + async root( appViewId: string, context: IContext,