From 5b6600be63ff9bde21516dc474c4dc0137e45cd5 Mon Sep 17 00:00:00 2001 From: liulong <18539103286> Date: Tue, 26 May 2026 21:42:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BF=AE=E5=A4=8D=E9=A1=B5=E8=84=9A?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/index/components/nav/index2.vue | 10 +- .../src/pages/index/utils/tzzx-iframe.js | 65 +++ txw-mhzc-web/src/pages/index/views/main.vue | 6 +- .../src/pages/index/views/tzzx/index.vue | 432 ++++++++++-------- 4 files changed, 329 insertions(+), 184 deletions(-) create mode 100644 txw-mhzc-web/src/pages/index/utils/tzzx-iframe.js diff --git a/txw-mhzc-web/src/pages/index/components/nav/index2.vue b/txw-mhzc-web/src/pages/index/components/nav/index2.vue index 0916ede..e9157e1 100644 --- a/txw-mhzc-web/src/pages/index/components/nav/index2.vue +++ b/txw-mhzc-web/src/pages/index/components/nav/index2.vue @@ -474,10 +474,16 @@ export default { } }, updateIframeUrl(menus) { - if (!menus || !this.kxurl) return; + if (!menus) return; menus.forEach(menu => { if (menu.path) { - menu.iframeUrl = `${this.kxurl}${menu.path}`; + // 门户内嵌碳证中心:走同源 /web/ 反代(测试/生产 nginx),便于 iframe 高度自适应 + const portalEmbed = menu.iframeUrl && String(menu.iframeUrl).startsWith('/web/'); + if (portalEmbed) { + menu.iframeUrl = `/web${menu.path}`; + } else if (this.kxurl) { + menu.iframeUrl = `${this.kxurl}${menu.path}`; + } } if (menu.child && menu.child.length > 0) { this.updateIframeUrl(menu.child); diff --git a/txw-mhzc-web/src/pages/index/utils/tzzx-iframe.js b/txw-mhzc-web/src/pages/index/utils/tzzx-iframe.js new file mode 100644 index 0000000..60bf8c0 --- /dev/null +++ b/txw-mhzc-web/src/pages/index/utils/tzzx-iframe.js @@ -0,0 +1,65 @@ +/** + * 碳证中心 iframe 地址归一化:门户内嵌统一走同源 /web/ 反代(如 carbon.liantu.tech/web/...) + */ +export function normalizeTzzxPageUrl(page) { + if (!page || typeof page !== 'string') return ''; + + let url = page.trim(); + if (!url) return ''; + + if (url.startsWith('http://') || url.startsWith('https://')) { + try { + const parsed = new URL(url); + if (parsed.origin === window.location.origin) { + url = parsed.pathname + parsed.search + parsed.hash; + } + } catch (e) { + return url; + } + } + + if (url.startsWith('/web/')) { + return url; + } + + const kxtfwzxMarker = '/view/kxtfwzx'; + const kxtIdx = url.indexOf(kxtfwzxMarker); + if (kxtIdx !== -1) { + const rest = url.slice(kxtIdx + kxtfwzxMarker.length); + return `/web${rest.startsWith('/') ? rest : `/${rest}`}`; + } + + const carbonPathMatch = url.match(/\/(carbon[\w-]*|trustedCarbon[\w-/]*)(?:\?.*)?$/i); + if (carbonPathMatch) { + const pathStart = url.indexOf(carbonPathMatch[0]); + const subPath = url.slice(pathStart); + return subPath.startsWith('/web/') ? subPath : `/web${subPath.startsWith('/') ? subPath : `/${subPath}`}`; + } + + if (url.startsWith('/') && !url.startsWith('/web/')) { + return `/web${url}`; + } + + return url; +} + +export function getViewportIframeFallbackHeight() { + const navOffset = parseInt( + getComputedStyle(document.documentElement).getPropertyValue('--page-offset-top'), + 10 + ); + const offset = Number.isFinite(navOffset) ? navOffset : 76; + return Math.max(window.innerHeight - offset, 480); +} + +export function isAllowedIframeMessageOrigin(origin) { + if (!origin) return false; + if (origin === window.location.origin) return true; + try { + const host = window.location.hostname; + if (host === 'localhost' || host === '127.0.0.1') return true; + } catch (e) { + return false; + } + return false; +} diff --git a/txw-mhzc-web/src/pages/index/views/main.vue b/txw-mhzc-web/src/pages/index/views/main.vue index 5a9af56..6fa06ee 100644 --- a/txw-mhzc-web/src/pages/index/views/main.vue +++ b/txw-mhzc-web/src/pages/index/views/main.vue @@ -128,10 +128,10 @@ export default { window.location.href = `/view/mhzc/login`; return; } - // this.iframeUrl = iframeUrl; this.$router.push({ - path: `/tzzx?page=${iframeUrl}` - }) + path: '/tzzx', + query: { page: iframeUrl }, + }); }, diff --git a/txw-mhzc-web/src/pages/index/views/tzzx/index.vue b/txw-mhzc-web/src/pages/index/views/tzzx/index.vue index 7c647bd..43a6141 100644 --- a/txw-mhzc-web/src/pages/index/views/tzzx/index.vue +++ b/txw-mhzc-web/src/pages/index/views/tzzx/index.vue @@ -1,179 +1,253 @@ - - - - - + + + + +