From 2a2d419f1c6bd47f670eb19298eb1d3d4b736afe Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Wed, 20 Mar 2024 14:05:58 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20iframe=E5=B5=8C=E5=85=A5=E5=BC=8F?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/plugin/src/index.vue | 2 ++ .../core-frontend/src/config/axios/service.ts | 10 ++++++++- core/core-frontend/src/permission.ts | 21 +++++++++++-------- .../src/store/modules/embedded.ts | 4 +++- .../src/views/dashboard/index.vue | 15 +++---------- .../src/views/data-visualization/index.vue | 14 +++---------- 6 files changed, 32 insertions(+), 34 deletions(-) diff --git a/core/core-frontend/src/components/plugin/src/index.vue b/core/core-frontend/src/components/plugin/src/index.vue index 4ffce4b554..55d8317d71 100644 --- a/core/core-frontend/src/components/plugin/src/index.vue +++ b/core/core-frontend/src/components/plugin/src/index.vue @@ -59,6 +59,7 @@ const loadComponent = () => { importProxy(byteArray) }) .catch(() => { + emits('loadFail') showNolic() }) .finally(() => { @@ -77,6 +78,7 @@ const pluginProxy = ref(null) const invokeMethod = param => { pluginProxy.value['invokeMethod'](param) } +const emits = defineEmits(['loadFail']) defineExpose({ invokeMethod }) diff --git a/core/core-frontend/src/config/axios/service.ts b/core/core-frontend/src/config/axios/service.ts index 8e050b56b8..5e63f9c618 100644 --- a/core/core-frontend/src/config/axios/service.ts +++ b/core/core-frontend/src/config/axios/service.ts @@ -189,6 +189,10 @@ service.interceptors.response.use( } router.push(`/login?redirect=${queryRedirectPath}`) } + } else if (response?.config?.url.startsWith('/xpackComponent/content')) { + console.error( + "never mind this error about '/xpackComponent/content', just a reminder to support the official license" + ) } return Promise.reject(response.data.msg) @@ -209,6 +213,10 @@ service.interceptors.response.use( message: error.message, showClose: true }) + } else if (error?.config?.url.startsWith('/xpackComponent/content')) { + console.error( + "never mind this error about '/xpackComponent/content', just a reminder to support the official license" + ) } error.config.loading && tryHideLoading(permissionStore.getCurrentPath) @@ -225,7 +233,7 @@ service.interceptors.response.use( if (header.has('DE-FORBIDDEN-FLAG')) { showMsg('当前用户权限配置已变更,请刷新页面', '-changed-') } - return Promise.reject(error) + return Promise.resolve() } ) diff --git a/core/core-frontend/src/permission.ts b/core/core-frontend/src/permission.ts index 23155b62c8..9140b459cf 100644 --- a/core/core-frontend/src/permission.ts +++ b/core/core-frontend/src/permission.ts @@ -23,13 +23,8 @@ const { start, done } = useNProgress() const { loadStart, loadDone } = usePageLoading() const whiteList = ['/login', '/de-link', '/chart-view'] // 不重定向白名单 -const embeddedWhiteList = [ - '/dvCanvas', - '/dashboard', - '/dataset-embedded', - '/dataset-form', - '/dataset-embedded-form' -] +const embeddedWindowWhiteList = ['/dvCanvas', '/dashboard'] +const embeddedRouteWhiteList = ['/dataset-embedded', '/dataset-form', '/dataset-embedded-form'] router.beforeEach(async (to, from, next) => { start() loadStart() @@ -106,14 +101,22 @@ router.beforeEach(async (to, from, next) => { } } else { const embeddedStore = useEmbedded() - if (embeddedStore.getToken && appStore.getIsIframe && embeddedWhiteList.includes(to.path)) { + if ( + embeddedStore.getToken && + appStore.getIsIframe && + embeddedRouteWhiteList.includes(to.path) + ) { if (to.path.includes('/dataset-form')) { next({ path: '/dataset-embedded-form', query: to.query }) return } permissionStore.setCurrentPath(to.path) next() - } else if (whiteList.indexOf(to.path) !== -1 || to.path.startsWith('/de-link/')) { + } else if ( + embeddedWindowWhiteList.includes(to.path) || + whiteList.includes(to.path) || + to.path.startsWith('/de-link/') + ) { permissionStore.setCurrentPath(to.path) next() } else { diff --git a/core/core-frontend/src/store/modules/embedded.ts b/core/core-frontend/src/store/modules/embedded.ts index 65f1bc56a3..c7050d3b83 100644 --- a/core/core-frontend/src/store/modules/embedded.ts +++ b/core/core-frontend/src/store/modules/embedded.ts @@ -56,7 +56,8 @@ export const userStore = defineStore('embedded', { type: this.type, dvId: this.dvId, chartId: this.chartId, - pid: this.pid + pid: this.pid, + resourceId: this.resourceId } } }, @@ -92,6 +93,7 @@ export const userStore = defineStore('embedded', { this.dvId = data['dvId'] this.chartId = data['chartId'] this.pid = data['pid'] + this.resourceId = data['resourceId'] } } }) diff --git a/core/core-frontend/src/views/dashboard/index.vue b/core/core-frontend/src/views/dashboard/index.vue index 0f2c831975..830bd804f1 100644 --- a/core/core-frontend/src/views/dashboard/index.vue +++ b/core/core-frontend/src/views/dashboard/index.vue @@ -96,20 +96,11 @@ const onMobileConfig = () => { } const loadFinish = ref(false) -const newWindowHandler = ref(null) - let p = null -const XpackLoaded = () => { - p(true) -} +const XpackLoaded = () => p(true) // 全局监听按键事件 onMounted(async () => { - await new Promise(r => { - if (!newWindowHandler?.value) { - return r(null) - } - p = r - }) + await new Promise(r => (p = r)) loadFinish.value = true useEmitt({ name: 'mobileConfig', @@ -254,9 +245,9 @@ onUnmounted(() => { v-else-if="loadFinish && mobileConfig" > diff --git a/core/core-frontend/src/views/data-visualization/index.vue b/core/core-frontend/src/views/data-visualization/index.vue index 54ef3dc8fc..90e79ec49c 100644 --- a/core/core-frontend/src/views/data-visualization/index.vue +++ b/core/core-frontend/src/views/data-visualization/index.vue @@ -200,19 +200,11 @@ const checkPer = async resourceId => { } const loadFinish = ref(false) -const newWindowHandler = ref(null) let p = null -const XpackLoaded = () => { - p(true) -} +const XpackLoaded = () => p(true) onMounted(async () => { - await new Promise(r => { - if (!newWindowHandler?.value) { - return r(null) - } - p = r - }) + await new Promise(r => (p = r)) loadFinish.value = true window.addEventListener('blur', releaseAttachKey) if (editMode.value === 'edit') { @@ -389,9 +381,9 @@ eventBus.on('handleNew', handleNew)