From abff2071bdfaca745ca110736055c9b2b4fce168 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 3 May 2025 22:31:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=A4=9A=E4=B8=AA=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E4=B8=AD=E4=BC=98=E5=8C=96=E5=8A=A8=E6=80=81=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BD=BF=E7=94=A8=20API=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=BB=84=E4=BB=B6=E5=B9=B6=E5=A4=84=E7=90=86=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=A4=B1=E8=B4=A5=E6=83=85=E5=86=B5=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E6=8F=90=E5=8D=87=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C=E5=92=8C?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=81=A5=E5=A3=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/dialog/PluginConfigDialog.vue | 15 ++++++++++++--- src/components/dialog/PluginDataDialog.vue | 12 +++++++++++- src/components/misc/DashboardElement.vue | 17 +++++++++++++---- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/components/dialog/PluginConfigDialog.vue b/src/components/dialog/PluginConfigDialog.vue index 3ee32243..57bb304a 100644 --- a/src/components/dialog/PluginConfigDialog.vue +++ b/src/components/dialog/PluginConfigDialog.vue @@ -48,14 +48,23 @@ const renderMode = ref('vuetify') //Vue 模式:组件 URL const vueComponentUrl = ref(null) -//Vue 模式:动态加载的组件 +// Vue 模式:动态加载的组件 const dynamicComponent = computed(() => { if (renderMode.value === 'vue' && vueComponentUrl.value) { const url = vueComponentUrl.value return defineAsyncComponent(() => - import(/* @vite-ignore */ url) + api + .get(url) + .then((response: any) => { + if (response) { + const blob = new Blob([response.data], { type: 'text/javascript' }) + const blobUrl = URL.createObjectURL(blob) + return import(/* @vite-ignore */ blobUrl) + } else { + return { render: () => h('div', '组件加载失败: 无默认导出') } + } + }) .then(module => { - // 假设 JS 文件默认导出组件 if (module.default) { return module.default } else { diff --git a/src/components/dialog/PluginDataDialog.vue b/src/components/dialog/PluginDataDialog.vue index 2be905ad..e620f9f7 100644 --- a/src/components/dialog/PluginDataDialog.vue +++ b/src/components/dialog/PluginDataDialog.vue @@ -40,7 +40,17 @@ const dynamicComponent = computed(() => { if (renderMode.value === 'vue' && vueComponentUrl.value) { const url = vueComponentUrl.value return defineAsyncComponent(() => - import(/* @vite-ignore */ url) + api + .get(url) + .then((response: any) => { + if (response) { + const blob = new Blob([response.data], { type: 'text/javascript' }) + const blobUrl = URL.createObjectURL(blob) + return import(/* @vite-ignore */ blobUrl) + } else { + return { render: () => h('div', '组件加载失败: 无默认导出') } + } + }) .then(module => { if (module.default) { return module.default diff --git a/src/components/misc/DashboardElement.vue b/src/components/misc/DashboardElement.vue index 11cab2af..4bf826d8 100644 --- a/src/components/misc/DashboardElement.vue +++ b/src/components/misc/DashboardElement.vue @@ -12,6 +12,7 @@ import MediaServerLibrary from '@/views/dashboard/MediaServerLibrary.vue' import MediaServerPlaying from '@/views/dashboard/MediaServerPlaying.vue' import DashboardRender from '@/components/render/DashboardRender.vue' import { isNullOrEmptyObject } from '@/@core/utils' +import api from '@/api' // 输入参数 const props = defineProps({ @@ -35,19 +36,27 @@ const pluginRenderMode = computed(() => props.config?.render_mode || 'vuetify') const dynamicPluginComponent = computed(() => { // 确保 config 存在并且 component_url 也存在 if (pluginRenderMode.value === 'vue' && props.config?.component_url) { - const url = props.config.component_url + const url = props.config?.component_url return defineAsyncComponent(() => - import(/* @vite-ignore */ url) + api + .get(url) + .then((response: any) => { + if (response) { + const blob = new Blob([response.data], { type: 'text/javascript' }) + const blobUrl = URL.createObjectURL(blob) + return import(/* @vite-ignore */ blobUrl) + } else { + return { render: () => h('div', '组件加载失败: 无默认导出') } + } + }) .then(module => { if (module.default) { return module.default } else { - console.error(`无法从 ${url} 加载默认导出的 Vue 组件`) return { render: () => h('div', '组件加载失败: 无默认导出') } } }) .catch(err => { - console.error(`无法加载插件仪表盘组件: ${url}`, err) return { render: () => h('div', '组件加载失败') } }), )