From 1f4a3c1ef5daa66a5b96c62ad670a79df008b066 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Mon, 18 Mar 2024 18:51:57 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20iframe=E5=B5=8C=E5=85=A5=E5=BC=8F?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/core-frontend/src/utils/communication.ts | 77 ------------------- .../src/views/chart/ChartView.vue | 21 +++-- .../src/views/common/DeResourceTree.vue | 22 ++++-- .../src/views/dashboard/index.vue | 35 +++++++-- .../src/views/data-visualization/index.vue | 36 +++++++-- de-xpack | 2 +- .../permissions/embedded/api/EmbeddedApi.java | 6 ++ .../embedded/dto/EmbeddedOrigin.java | 13 ++++ .../io/dataease/utils/WhitelistUtils.java | 1 + 9 files changed, 102 insertions(+), 111 deletions(-) delete mode 100644 core/core-frontend/src/utils/communication.ts create mode 100644 sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/embedded/dto/EmbeddedOrigin.java diff --git a/core/core-frontend/src/utils/communication.ts b/core/core-frontend/src/utils/communication.ts deleted file mode 100644 index 1a0e32db1a..0000000000 --- a/core/core-frontend/src/utils/communication.ts +++ /dev/null @@ -1,77 +0,0 @@ -export interface EmbeddedData { - 'de-embedded': boolean - embeddedToken?: string - busiFlag?: string - type?: string - dvId?: string - chartId?: string - pid: string -} - -export const communicationInit = cb => { - window.addEventListener('message', event => { - if (!event.data['de-embedded']) { - return - } - const origin = event.origin - console.log(origin) - const embeddedData: EmbeddedData = event.data - // validate origin - if (cb) { - cb(embeddedData) - } - }) - const readyData = { - ready: true, - msgOrigin: 'de-fit2cloud' - } - window.parent.postMessage(readyData, '*') -} - -export const initOpenHandler = (newWindow, data) => { - if (!data.embeddedToken) { - return - } - window['uuid'] = new Date().getTime() - newWindow['uuid'] = window['uuid'] + 1 - newWindow['name'] = 'de-new-resource-window' - window.addEventListener('message', event => { - if ( - event.data?.msgOrigin !== 'de-inner-fit2cloud' || - event.origin !== window.origin || - event.source['uuid'] !== newWindow['uuid'] - ) { - return - } - data['de-inner-embedded'] = true - if (event.data.ready) { - newWindow.postMessage(data, '/') - } - }) -} - -export const newWindowReady = async cb => { - return new Promise((resolve, reject) => { - if (!window.opener || window['name'] !== 'de-new-resource-window') { - return resolve(null) - } - window.addEventListener('message', event => { - if ( - !event.data['de-inner-embedded'] || - event.origin !== window.origin || - window['uuid'] !== event.source['uuid'] - 1 - ) { - return - } - if (cb) { - cb(event.data) - resolve(true) - } - }) - const readyData = { - ready: true, - msgOrigin: 'de-inner-fit2cloud' - } - window.opener.postMessage(readyData, '/') - }) -} diff --git a/core/core-frontend/src/views/chart/ChartView.vue b/core/core-frontend/src/views/chart/ChartView.vue index 72bea1e486..6561206c5d 100644 --- a/core/core-frontend/src/views/chart/ChartView.vue +++ b/core/core-frontend/src/views/chart/ChartView.vue @@ -1,12 +1,7 @@