From 54d254e29012719dbf3ae8ba398c53b28700306c Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Thu, 20 Jun 2024 16:32:02 +0800 Subject: [PATCH] =?UTF-8?q?perf(X-Pack):=20=E6=8F=92=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86-=E5=89=8D=E7=AB=AF=E5=88=86=E5=B8=83=E5=BC=8F?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=9D=99=E6=80=81=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/db/migration/V2.8__ddl.sql | 21 +++++++++- core/core-frontend/config/distributed.ts | 2 +- .../data-visualization/canvas/CanvasCore.vue | 19 --------- .../components/plugin/src/PluginComponent.vue | 41 +++++++++++-------- .../core-frontend/src/config/axios/service.ts | 2 + .../component-group/UserViewGroup.vue | 11 ++--- .../src/custom-component/component-list.ts | 6 ++- .../src/models/chart/chart-plugin.d.ts | 2 +- .../modules/data-visualization/dvMain.ts | 2 +- .../src/views/canvas/DeCanvas.vue | 5 +-- .../views/chart/components/editor/index.vue | 2 +- .../views/chart/components/views/index.vue | 2 +- .../xpack/component/XpackComponentApi.java | 3 ++ .../io/dataease/utils/WhitelistUtils.java | 1 + .../view/factory/PluginsChartFactory.java | 15 +++++-- .../view/vo/XpackPluginsViewVO.java | 3 ++ 16 files changed, 82 insertions(+), 55 deletions(-) diff --git a/core/core-backend/src/main/resources/db/migration/V2.8__ddl.sql b/core/core-backend/src/main/resources/db/migration/V2.8__ddl.sql index 9ac0579979..369bac5301 100644 --- a/core/core-backend/src/main/resources/db/migration/V2.8__ddl.sql +++ b/core/core-backend/src/main/resources/db/migration/V2.8__ddl.sql @@ -1 +1,20 @@ -ALTER TABLE `core_export_task` ADD COLUMN `msg` LONGTEXT NULL COMMENT '错误信息' AFTER `params`; +ALTER TABLE `core_export_task` + ADD COLUMN `msg` LONGTEXT NULL COMMENT '错误信息' AFTER `params`; + + +DROP TABLE IF EXISTS `xpack_plugin`; +CREATE TABLE `xpack_plugin` +( + `id` bigint NOT NULL COMMENT 'ID', + `name` varchar(255) NOT NULL COMMENT '插件名称', + `icon` longtext NOT NULL COMMENT '图标', + `version` varchar(255) NOT NULL COMMENT '版本', + `install_time` bigint NOT NULL COMMENT '安装时间', + `flag` varchar(255) NOT NULL COMMENT '类型', + `developer` varchar(255) NOT NULL COMMENT '开发者', + `config` longtext NOT NULL COMMENT '插件配置', + `require_version` varchar(255) NOT NULL COMMENT 'DE最低版本', + `module_name` varchar(255) NOT NULL COMMENT '模块名称', + `jar_name` varchar(255) NOT NULL COMMENT 'Jar包名称', + PRIMARY KEY (`id`) +) COMMENT ='插件表'; \ No newline at end of file diff --git a/core/core-frontend/config/distributed.ts b/core/core-frontend/config/distributed.ts index ca1cd87465..9db5d95f95 100644 --- a/core/core-frontend/config/distributed.ts +++ b/core/core-frontend/config/distributed.ts @@ -14,7 +14,7 @@ export default { ], build: { rollupOptions: { - external: id => /de-xpack/.test(id) || /extensions-view-3dpie/.test(id), + external: id => /de-xpack/.test(id) || /extensions/.test(id), output: { // 用于命名代码拆分时创建的共享块的输出命名 chunkFileNames: `assets/chunk/[name]-${pkg.version}-${pkg.name}.js`, diff --git a/core/core-frontend/src/components/data-visualization/canvas/CanvasCore.vue b/core/core-frontend/src/components/data-visualization/canvas/CanvasCore.vue index f3e6b67ffc..2217027e66 100644 --- a/core/core-frontend/src/components/data-visualization/canvas/CanvasCore.vue +++ b/core/core-frontend/src/components/data-visualization/canvas/CanvasCore.vue @@ -1490,25 +1490,6 @@ defineExpose({ @linkJumpSetOpen="linkJumpSetOpen(item)" @linkageSetOpen="linkageSetOpen(item)" > - - { } const importProxy = (bytesArray: any[]) => { - /* const promise = import( - `../../../../../../../${formatArray(bytesArray[7])}/${formatArray(bytesArray[8])}/${formatArray( - bytesArray[9] - )}/${formatArray(bytesArray[10])}/${formatArray(bytesArray[11])}.vue` - ) */ const promise = import( - `../../../../../../../extensions-view-3dpie/${formatArray(bytesArray[8])}/${formatArray( + `../../../../../../../extensions/${formatArray(bytesArray[8])}/${formatArray( bytesArray[9] - )}/${formatArray(bytesArray[10])}/${formatArray(bytesArray[11])}.vue` + )}/${formatArray(bytesArray[10])}/${formatArray(bytesArray[11])}/${formatArray( + bytesArray[12] + )}.vue` ) promise .then((res: any) => { @@ -53,16 +50,23 @@ const importProxy = (bytesArray: any[]) => { }) } +const getModuleName = () => { + const jsPath = window.atob(attrs.jsname.toString()) + return jsPath.split('/')[0] +} const loadComponent = () => { + const moduleName = getModuleName() loading.value = true - const byteArray = wsCache.get(`de-plugin-proxy-plugin`) + const byteArray = wsCache.get(`de-plugin-proxy-${moduleName}`) if (byteArray) { importProxy(JSON.parse(byteArray)) loading.value = false return } const key = generateRamStr(randomKey()) - loadPluginApi(key) + const moduleNameKey = window.btoa(moduleName) + const saltKey = `${key},${moduleNameKey}` + loadPluginApi(saltKey) .then(response => { let code = response.data const byteArray = execute(code, key) @@ -82,7 +86,8 @@ const storeCacheProxy = byteArray => { byteArray.forEach(item => { result.push([...item]) }) - wsCache.set(`de-plugin-proxy-plugin`, JSON.stringify(result)) + const moduleName = getModuleName() + wsCache.set(`de-plugin-proxy-${moduleName}`, JSON.stringify(result)) } const pluginProxy = ref(null) const invokeMethod = param => { @@ -104,8 +109,9 @@ onMounted(async () => { distributed = wsCache.get(key) } if (distributed) { - if (window['DEXPack']) { - const xpack = await window['DEXPack'].mapping[attrs.jsname] + const moduleName = getModuleName() + if (window[moduleName]) { + const xpack = await window[moduleName].mapping[attrs.jsname] plugin.value = xpack.default } else { window['Vue'] = Vue @@ -114,9 +120,10 @@ onMounted(async () => { window['vueRouter'] = vueRouter window['MittAll'] = useEmitt().emitter.all window['I18n'] = i18n - loadDistributed().then(async res => { - new Function(res.data)() - const xpack = await window['DEXPack'].mapping[attrs.jsname] + const url = `/xpackComponent/pluginStaticInfo/${moduleName}` + request.get({ url }).then(async res => { + new Function(res.data || res)() + const xpack = await window[moduleName].mapping[attrs.jsname] plugin.value = xpack.default }) } diff --git a/core/core-frontend/src/config/axios/service.ts b/core/core-frontend/src/config/axios/service.ts index cced05ba8a..3e9931eab1 100644 --- a/core/core-frontend/src/config/axios/service.ts +++ b/core/core-frontend/src/config/axios/service.ts @@ -173,6 +173,8 @@ service.interceptors.response.use( return response } else if (response.config.url.includes('DEXPack.umd.js')) { return response + } else if (response.config.url.startsWith('/xpackComponent/pluginStaticInfo/extensions-')) { + return response } else { if ( !response?.config?.url.startsWith('/xpackComponent/content') && diff --git a/core/core-frontend/src/custom-component/component-group/UserViewGroup.vue b/core/core-frontend/src/custom-component/component-group/UserViewGroup.vue index a29141eaf4..887eeac210 100644 --- a/core/core-frontend/src/custom-component/component-group/UserViewGroup.vue +++ b/core/core-frontend/src/custom-component/component-group/UserViewGroup.vue @@ -48,8 +48,8 @@ const anchorPosition = anchor => { scrollTo(element.offsetTop) } -const newComponent = (innerType, isPlugin) => { - eventBus.emit('handleNew', { componentName: 'UserView', innerType: innerType, isPlugin }) +const newComponent = (innerType, staticMap) => { + eventBus.emit('handleNew', { componentName: 'UserView', innerType: innerType, staticMap }) } const handleDragStart = e => { @@ -66,14 +66,15 @@ const groupActiveChange = category => { } const loadPluginCategory = data => { data.forEach(item => { - const { category, title, render, chartValue, chartTitle, icon } = item + const { category, title, render, chartValue, chartTitle, icon, staticMap } = item const node = { render, category, icon, value: chartValue, title: chartTitle, - isPlugin: true + isPlugin: true, + staticMap } const stack = [...state.chartGroupList] let findParent = false @@ -128,7 +129,7 @@ const loadPluginCategory = data => { :key="chartInfo.title" >
{ if (comp.component === componentName) { @@ -540,6 +541,9 @@ export function findNewComponentFromList( newComponent.label = viewConfig?.title newComponent.render = viewConfig?.render newComponent.isPlugin = !!isPlugin + if (isPlugin) { + newComponent.staticMap = staticMap + } } return newComponent } diff --git a/core/core-frontend/src/models/chart/chart-plugin.d.ts b/core/core-frontend/src/models/chart/chart-plugin.d.ts index 2a6893825a..f7ac06f348 100644 --- a/core/core-frontend/src/models/chart/chart-plugin.d.ts +++ b/core/core-frontend/src/models/chart/chart-plugin.d.ts @@ -1,4 +1,4 @@ declare interface ChartPlugin { isPlugin: boolean - pluginResourceId?: string + staticMap?: object } diff --git a/core/core-frontend/src/store/modules/data-visualization/dvMain.ts b/core/core-frontend/src/store/modules/data-visualization/dvMain.ts index 8a8a843146..4029140825 100644 --- a/core/core-frontend/src/store/modules/data-visualization/dvMain.ts +++ b/core/core-frontend/src/store/modules/data-visualization/dvMain.ts @@ -391,7 +391,7 @@ export const dvMainStore = defineStore('dataVisualization', { render: component.render, plugin: { isPlugin: component.isPlugin, - pluginResourceId: component.pluginResourceId + staticMap: component.staticMap } } as unknown as ChartObj // 处理配置项默认值,不同图表的同一配置项默认值不同 diff --git a/core/core-frontend/src/views/canvas/DeCanvas.vue b/core/core-frontend/src/views/canvas/DeCanvas.vue index 71aaca2a0f..385571f060 100644 --- a/core/core-frontend/src/views/canvas/DeCanvas.vue +++ b/core/core-frontend/src/views/canvas/DeCanvas.vue @@ -73,10 +73,9 @@ const editStyle = computed(() => { // 通过实时监听的方式直接添加组件 const handleNewFromCanvasMain = newComponentInfo => { - const { componentName, innerType, isPlugin } = newComponentInfo + const { componentName, innerType, staticMap } = newComponentInfo if (componentName) { - const component = findNewComponentFromList(componentName, innerType, curOriginThemes, isPlugin) - component.isPlugin = !!isPlugin + const component = findNewComponentFromList(componentName, innerType, curOriginThemes, staticMap) syncShapeItemStyle(component, baseWidth.value, baseHeight.value) component.id = guid() component.y = 200 diff --git a/core/core-frontend/src/views/chart/components/editor/index.vue b/core/core-frontend/src/views/chart/components/editor/index.vue index 37ae2b03ca..06757296ec 100644 --- a/core/core-frontend/src/views/chart/components/editor/index.vue +++ b/core/core-frontend/src/views/chart/components/editor/index.vue @@ -1605,7 +1605,7 @@ const deleteChartFieldItem = id => {
{
viewPlugins(); + + @GetMapping("/pluginStaticInfo/{moduleName}") + void pluginStaticInfo(@PathVariable("moduleName") String moduleName); } diff --git a/sdk/common/src/main/java/io/dataease/utils/WhitelistUtils.java b/sdk/common/src/main/java/io/dataease/utils/WhitelistUtils.java index 608be9fbd5..7dcdbb68b5 100644 --- a/sdk/common/src/main/java/io/dataease/utils/WhitelistUtils.java +++ b/sdk/common/src/main/java/io/dataease/utils/WhitelistUtils.java @@ -63,6 +63,7 @@ public class WhitelistUtils { || StringUtils.startsWithAny(requestURI, "/appearance/image/") || StringUtils.startsWithAny(requestURI, "/share/proxyInfo") || StringUtils.startsWithAny(requestURI, "/xpackComponent/content") + || StringUtils.startsWithAny(requestURI, "/xpackComponent/pluginStaticInfo") || StringUtils.startsWithAny(requestURI, "/geo/") || StringUtils.startsWithAny(requestURI, "/websocket") || StringUtils.startsWithAny(requestURI, "/map/") diff --git a/sdk/extensions/extensions-view/src/main/java/io/dataease/extensions/view/factory/PluginsChartFactory.java b/sdk/extensions/extensions-view/src/main/java/io/dataease/extensions/view/factory/PluginsChartFactory.java index 382036c3a7..b25f4562c6 100644 --- a/sdk/extensions/extensions-view/src/main/java/io/dataease/extensions/view/factory/PluginsChartFactory.java +++ b/sdk/extensions/extensions-view/src/main/java/io/dataease/extensions/view/factory/PluginsChartFactory.java @@ -1,7 +1,10 @@ package io.dataease.extensions.view.factory; +import io.dataease.exception.DEException; import io.dataease.extensions.view.template.PluginsChartTemplate; import io.dataease.extensions.view.vo.XpackPluginsViewVO; +import io.dataease.license.utils.LogUtil; +import io.dataease.plugins.factory.DataEasePluginFactory; import java.util.List; import java.util.Map; @@ -11,6 +14,7 @@ public class PluginsChartFactory { private static final Map templateMap = new ConcurrentHashMap<>(); + public static PluginsChartTemplate getInstance(String render, String type) { String key = render + "_" + type; return templateMap.get(key); @@ -20,13 +24,16 @@ public class PluginsChartFactory { String key = render + "_" + type; if (templateMap.containsKey(key)) return; templateMap.put(key, template); + try { + String moduleName = template.getPluginInfo().getModuleName(); + DataEasePluginFactory.loadTemplate(moduleName, template); + } catch (Exception e) { + LogUtil.error(e.getMessage(), new Throwable(e)); + DEException.throwException(e); + } } public static List getViewConfigList() { return templateMap.values().stream().map(PluginsChartTemplate::getConfig).toList(); } - - public static List getAllPlugins() { - return null; - } } diff --git a/sdk/extensions/extensions-view/src/main/java/io/dataease/extensions/view/vo/XpackPluginsViewVO.java b/sdk/extensions/extensions-view/src/main/java/io/dataease/extensions/view/vo/XpackPluginsViewVO.java index 96856520b6..757e3fbc2d 100644 --- a/sdk/extensions/extensions-view/src/main/java/io/dataease/extensions/view/vo/XpackPluginsViewVO.java +++ b/sdk/extensions/extensions-view/src/main/java/io/dataease/extensions/view/vo/XpackPluginsViewVO.java @@ -4,6 +4,7 @@ import lombok.Data; import java.io.Serial; import java.io.Serializable; +import java.util.Map; @Data public class XpackPluginsViewVO implements Serializable { @@ -26,4 +27,6 @@ public class XpackPluginsViewVO implements Serializable { private String render; + private Map staticMap; + }