From c86bf2419dede97a0dab6d03a3477a6355b17b08 Mon Sep 17 00:00:00 2001 From: dataeaseShu Date: Sun, 18 Feb 2024 13:50:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=B5=8C=E5=85=A5=E5=BC=8F):=20DIV=20?= =?UTF-8?q?=E5=B5=8C=E5=85=A5=E8=A7=86=E5=9B=BE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core-frontend/src/config/axios/service.ts | 14 ++-- .../src/pages/panel/DashboardPreview.vue | 12 +-- .../src/pages/panel/ViewWrapper.vue | 22 ++--- core/core-frontend/src/pages/panel/main.ts | 57 +++++++++++-- .../src/store/modules/embedded.ts | 83 +++++++++++++++++++ core/core-frontend/src/utils/imgUtils.ts | 6 +- core/core-frontend/src/utils/url.ts | 4 +- .../src/views/chart/ChartView.vue | 24 +++--- .../src/views/common/DeResourceTree.vue | 4 +- .../src/views/dashboard/index.vue | 11 ++- .../src/views/data-visualization/index.vue | 14 +++- 11 files changed, 201 insertions(+), 50 deletions(-) create mode 100644 core/core-frontend/src/store/modules/embedded.ts diff --git a/core/core-frontend/src/config/axios/service.ts b/core/core-frontend/src/config/axios/service.ts index c932f2a188..788a77e704 100644 --- a/core/core-frontend/src/config/axios/service.ts +++ b/core/core-frontend/src/config/axios/service.ts @@ -10,6 +10,7 @@ import axios, { import { tryShowLoading, tryHideLoading } from '@/utils/loading' import qs from 'qs' import { usePermissionStoreWithOut } from '@/store/modules/permission' +import { useEmbedded } from '@/store/modules/embedded' import { useLinkStoreWithOut } from '@/store/modules/link' import { config } from './config' import { configHandler } from './refresh' @@ -31,9 +32,10 @@ const { result_code } = config import { useCache } from '@/hooks/web/useCache' const { wsCache } = useCache() +const embeddedStore = useEmbedded() -export const PATH_URL = window.DataEaseBi - ? window.DataEaseBi?.baseUrl + 'de2api/' +export const PATH_URL = embeddedStore.baseUrl + ? embeddedStore?.baseUrl + 'de2api/' : import.meta.env.VITE_API_BASEPATH export interface AxiosInstanceWithLoading extends AxiosInstance { @@ -101,14 +103,14 @@ service.interceptors.request.use( ) { config.data = qs.stringify(config.data) } - if (window.DataEaseBi?.baseUrl) { - config.baseURL = window.DataEaseBi.baseUrl + 'de2api/' + if (embeddedStore.baseUrl) { + config.baseURL = embeddedStore.baseUrl + 'de2api/' } if (linkStore.getLinkToken) { ;(config.headers as AxiosRequestHeaders)['X-DE-LINK-TOKEN'] = linkStore.getLinkToken - } else if (window.DataEaseBi?.token) { - ;(config.headers as AxiosRequestHeaders)['X-EMBEDDED-TOKEN'] = window.DataEaseBi.token + } else if (embeddedStore.token) { + ;(config.headers as AxiosRequestHeaders)['X-EMBEDDED-TOKEN'] = embeddedStore.token } if (wsCache.get('user.language')) { const key = wsCache.get('user.language') diff --git a/core/core-frontend/src/pages/panel/DashboardPreview.vue b/core/core-frontend/src/pages/panel/DashboardPreview.vue index e0edee1f14..99b8bfdb91 100644 --- a/core/core-frontend/src/pages/panel/DashboardPreview.vue +++ b/core/core-frontend/src/pages/panel/DashboardPreview.vue @@ -2,10 +2,12 @@ import { ref, reactive, onBeforeMount, nextTick } from 'vue' import { initCanvasData } from '@/utils/canvasUtils' import { interactiveStoreWithOut } from '@/store/modules/interactive' +import { useEmbedded } from '@/store/modules/embedded' import { check } from '@/utils/CrossPermission' import { useCache } from '@/hooks/web/useCache' const { wsCache } = useCache() const interactiveStore = interactiveStoreWithOut() +const embeddedStore = useEmbedded() const dashboardPreview = ref(null) const state = reactive({ canvasDataPreview: null, @@ -18,19 +20,19 @@ const checkPer = async resourceId => { if (!window.DataEaseBi || !resourceId) { return true } - const request = { busiFlag: window.DataEaseBi.busiFlag } + const request = { busiFlag: embeddedStore.busiFlag } await interactiveStore.setInteractive(request) - const key = window.DataEaseBi.busiFlag === 'dataV' ? 'screen-weight' : 'panel-weight' + const key = embeddedStore.busiFlag === 'dataV' ? 'screen-weight' : 'panel-weight' return check(wsCache.get(key), resourceId, 1) } onBeforeMount(async () => { - const checkResult = await checkPer(window.DataEaseBi.dvId) + const checkResult = await checkPer(embeddedStore.dvId) if (!checkResult) { return } initCanvasData( - window.DataEaseBi.dvId, - window.DataEaseBi.busiFlag, + embeddedStore.dvId, + embeddedStore.busiFlag, function ({ canvasDataResult, canvasStyleResult, diff --git a/core/core-frontend/src/pages/panel/ViewWrapper.vue b/core/core-frontend/src/pages/panel/ViewWrapper.vue index 0ce85aa224..a1895ba174 100644 --- a/core/core-frontend/src/pages/panel/ViewWrapper.vue +++ b/core/core-frontend/src/pages/panel/ViewWrapper.vue @@ -2,10 +2,12 @@ import { ref, onBeforeMount, reactive } from 'vue' import { initCanvasDataPrepare } from '@/utils/canvasUtils' import { interactiveStoreWithOut } from '@/store/modules/interactive' +import { useEmbedded } from '@/store/modules/embedded' import { check } from '@/utils/CrossPermission' import { useCache } from '@/hooks/web/useCache' const { wsCache } = useCache() const interactiveStore = interactiveStoreWithOut() +const embeddedStore = useEmbedded() const config = ref() const viewInfo = ref() const userViewEnlargeRef = ref() @@ -22,19 +24,19 @@ const checkPer = async resourceId => { if (!window.DataEaseBi || !resourceId) { return true } - const request = { busiFlag: window.DataEaseBi.busiFlag } + const request = { busiFlag: embeddedStore.busiFlag } await interactiveStore.setInteractive(request) - const key = window.DataEaseBi.busiFlag === 'dataV' ? 'screen-weight' : 'panel-weight' + const key = embeddedStore.busiFlag === 'dataV' ? 'screen-weight' : 'panel-weight' return check(wsCache.get(key), resourceId, 1) } onBeforeMount(async () => { - const checkResult = await checkPer(window.DataEaseBi.dvId) + const checkResult = await checkPer(embeddedStore.dvId) if (!checkResult) { return } initCanvasDataPrepare( - window.DataEaseBi.dvId, - window.DataEaseBi.busiFlag, + embeddedStore.dvId, + embeddedStore.busiFlag, function ({ canvasDataResult, canvasStyleResult, @@ -48,7 +50,7 @@ onBeforeMount(async () => { state.dvInfo = dvInfo state.curPreviewGap = curPreviewGap - viewInfo.value = canvasViewInfoPreview[window.DataEaseBi.chartId] + viewInfo.value = canvasViewInfoPreview[embeddedStore.chartId] ;( (canvasDataResult as unknown as Array<{ id: string @@ -56,14 +58,14 @@ onBeforeMount(async () => { propValue: Array<{ id: string }> }>) || [] ).some(ele => { - if (ele.id === window.DataEaseBi.chartId) { + if (ele.id === embeddedStore.chartId) { config.value = ele return true } if (ele.component === 'Group') { return (ele.propValue || []).some(itx => { - if (itx.id === window.DataEaseBi.chartId) { + if (itx.id === embeddedStore.chartId) { config.value = itx return true } @@ -97,8 +99,8 @@ const userViewEnlargeOpen = () => { diff --git a/core/core-frontend/src/pages/panel/main.ts b/core/core-frontend/src/pages/panel/main.ts index 022fca0971..848eb31613 100644 --- a/core/core-frontend/src/pages/panel/main.ts +++ b/core/core-frontend/src/pages/panel/main.ts @@ -57,12 +57,23 @@ import 'normalize.css/normalize.css' import AppElement from './App.vue' import { setupI18n } from '@/plugins/vue-i18n' import { setupStore } from '@/store' +import { useEmbedded } from '@/store/modules/embedded' import { useUserStoreWithOut } from '@/store/modules/user' import { setupElementPlus, setupElementPlusIcons } from '@/plugins/element-plus' import { setupRouter } from '@/router' -const setupAll = async (dom: string, componentName: string): Promise> => { - const app = createApp(AppElement, { componentName }) +const setupAll = async ( + dom: string, + type: string, + busiFlag: string, + token: string, + baseUrl: string, + dvId: string, + pid: string, + chartId: string, + resourceId: string +): Promise> => { + const app = createApp(AppElement, { componentName: type }) await setupI18n(app) setupStore(app) setupRouter(app) @@ -70,6 +81,15 @@ const setupAll = async (dom: string, componentName: string): Promise - create(type, options) { + constructor(type, options) { this.type = type this.token = options.token this.busiFlag = options.busiFlag @@ -117,15 +137,42 @@ class DataEaseBi { async initialize(options: Options) { this.deOptions = { ...defaultOptions, ...options } - this.vm = await setupAll(this.deOptions.container, this.type) + this.vm = await setupAll( + this.deOptions.container, + this.type, + this.busiFlag, + this.token, + this.baseUrl, + this.dvId, + this.pid, + this.chartId, + this.resourceId + ) } destroy() { const userStore = useUserStoreWithOut() + const embeddedStore = useEmbedded() userStore.clear() + embeddedStore.setType(null) + embeddedStore.setBusiFlag(null) + embeddedStore.setToken(null) + embeddedStore.setBaseUrl(null) + embeddedStore.setDvId(null) + embeddedStore.setPid(null) + embeddedStore.setChartId(null) + embeddedStore.setResourceId(null) this.vm.unmount() + this.type = null + this.token = null + this.busiFlag = null + this.baseUrl = null + this.dvId = null + this.pid = null + this.chartId = null + this.resourceId = null this.vm = null } } -window.DataEaseBi = new DataEaseBi() +window.DataEaseBi = DataEaseBi diff --git a/core/core-frontend/src/store/modules/embedded.ts b/core/core-frontend/src/store/modules/embedded.ts new file mode 100644 index 0000000000..ab490b8745 --- /dev/null +++ b/core/core-frontend/src/store/modules/embedded.ts @@ -0,0 +1,83 @@ +import { defineStore } from 'pinia' +import { store } from '../index' +interface AppState { + type: string + token: string + busiFlag: string + baseUrl: string + dvId: string + pid: string + chartId: string + resourceId: string +} + +export const userStore = defineStore('embedded', { + state: (): AppState => { + return { + type: '', + token: '', + busiFlag: '', + baseUrl: '', + dvId: '', + pid: '', + chartId: '', + resourceId: '' + } + }, + getters: { + getType(): string { + return this.type + }, + getToken(): string { + return this.token + }, + getBusiFlag(): string { + return this.busiFlag + }, + getBaseUrl(): string { + return this.baseUrl + }, + getDvId(): string { + return this.dvId + }, + getPid(): string { + return this.pid + }, + getChartId(): string { + return this.chartId + }, + getResourceId(): string { + return this.resourceId + } + }, + actions: { + setType(type: string) { + this.type = type + }, + setToken(token: string) { + this.token = token + }, + setBusiFlag(busiFlag: string) { + this.busiFlag = busiFlag + }, + setBaseUrl(baseUrl: string) { + this.baseUrl = baseUrl + }, + setDvId(dvId: string) { + this.dvId = dvId + }, + setPid(pid: string) { + this.pid = pid + }, + setChartId(chartId: string) { + this.chartId = chartId + }, + setResourceId(resourceId: string) { + this.resourceId = resourceId + } + } +}) + +export const useEmbedded = () => { + return userStore(store) +} diff --git a/core/core-frontend/src/utils/imgUtils.ts b/core/core-frontend/src/utils/imgUtils.ts index 004d4738ea..25262d3a0d 100644 --- a/core/core-frontend/src/utils/imgUtils.ts +++ b/core/core-frontend/src/utils/imgUtils.ts @@ -1,10 +1,12 @@ import html2canvas from 'html2canvas' import JsPDF from 'jspdf' import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain' +import { useEmbedded } from '@/store/modules/embedded' import { storeToRefs } from 'pinia' import { findResourceAsBase64 } from '@/api/staticResource' import FileSaver from 'file-saver' import { deepCopy } from '@/utils/utils' +const embeddedStore = useEmbedded() const dvMainStore = dvMainStoreWithOut() const { canvasStyleData, componentData, canvasViewInfo, canvasViewDataInfo, dvInfo } = storeToRefs(dvMainStore) @@ -20,8 +22,8 @@ export function imgUrlTrans(url) { ? (basePath.endsWith('/') ? basePath.substring(0, basePath.length - 1) : basePath) + url : null return formatterUrl( - window.DataEaseBi - ? `${window.DataEaseBi.baseUrl}${ + embeddedStore.baseUrl + ? `${embeddedStore.baseUrl}${ rawUrl.startsWith('/api') ? rawUrl.slice(5) : rawUrl }`.replace('com//', 'com/') : rawUrl diff --git a/core/core-frontend/src/utils/url.ts b/core/core-frontend/src/utils/url.ts index 417590f413..330b44b2df 100644 --- a/core/core-frontend/src/utils/url.ts +++ b/core/core-frontend/src/utils/url.ts @@ -1,3 +1,5 @@ +import { useEmbedded } from '@/store/modules/embedded' +const embeddedStore = useEmbedded() export const formatDataEaseBi = (url: string) => { - return window.DataEaseBi?.baseUrl ? `${window.DataEaseBi.baseUrl}${url}` : url + return embeddedStore.baseUrl ? `${embeddedStore.baseUrl}${url}` : url } diff --git a/core/core-frontend/src/views/chart/ChartView.vue b/core/core-frontend/src/views/chart/ChartView.vue index 27a7d039c7..61be508be5 100644 --- a/core/core-frontend/src/views/chart/ChartView.vue +++ b/core/core-frontend/src/views/chart/ChartView.vue @@ -1,23 +1,19 @@