Merge pull request #9927 from dataease/dev-v2-plugin

Dev v2 plugin
This commit is contained in:
fit2cloud-chenyw 2024-05-28 20:37:29 +08:00 committed by GitHub
commit a5a0f985ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 62 additions and 4 deletions

View File

@ -2,6 +2,7 @@ package io.dataease.home;
import io.dataease.utils.ModelUtils;
import io.dataease.utils.RsaUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@ -11,6 +12,9 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping
public class RestIndexController {
@Value("${dataease.xpack-front-distributed:false}")
private boolean xpackFrontDistributed;
@GetMapping("/dekey")
@ResponseBody
public String dekey() {
@ -23,4 +27,11 @@ public class RestIndexController {
return ModelUtils.isDesktop();
}
@GetMapping("/xpackModel")
@ResponseBody
public boolean xpackModel() {
return xpackFrontDistributed;
}
}

View File

@ -1,3 +1,7 @@
import request from '@/config/axios'
export const load = (key: string) => request.get({ url: `/xpackComponent/content/${key}` })
export const loadDistributed = () => request.get({ url: '/DEXPack.umd.js' })
export const xpackModelApi = () => request.get({ url: '/xpackModel' })

View File

@ -1,9 +1,16 @@
<script lang="ts" setup>
import noLic from './nolic.vue'
import { ref, useAttrs } from 'vue'
import { ref, useAttrs, onMounted } from 'vue'
import { execute, randomKey, formatArray } from './convert'
import { load } from '@/api/plugin'
import { load, loadDistributed, xpackModelApi } from '@/api/plugin'
import { useCache } from '@/hooks/web/useCache'
import { i18n } from '@/plugins/vue-i18n'
import * as Vue from 'vue'
import axios from 'axios'
import * as Pinia from 'pinia'
import * as vueI18n from 'vue-i18n'
import * as vueRouter from 'vue-router'
import { useEmitt } from '@/hooks/web/useEmitt'
const { wsCache } = useCache()
@ -73,11 +80,44 @@ const storeCacheProxy = byteArray => {
})
wsCache.set(`de-plugin-proxy`, JSON.stringify(result))
}
loadComponent()
const pluginProxy = ref(null)
const invokeMethod = param => {
pluginProxy.value['invokeMethod'](param)
}
onMounted(async () => {
const key = 'xpack-model-distributed'
let distributed = false
if (wsCache.get(key) === null) {
const res = await xpackModelApi()
wsCache.set('xpack-model-distributed', res.data)
distributed = res.data
} else {
distributed = wsCache.get(key)
}
if (distributed) {
window['Vue'] = Vue
window['Axios'] = axios
window['Pinia'] = Pinia
window['vueI18n'] = vueI18n
window['vueRouter'] = vueRouter
window['MittAll'] = useEmitt().emitter.all
window['i18n'] = i18n
if (window['DEXPack']) {
const xpack = await window['DEXPack'].mapping[attrs.jsname]
plugin.value = xpack.default
} else {
loadDistributed().then(async res => {
new Function(res.data)()
const xpack = await window['DEXPack'].mapping[attrs.jsname]
plugin.value = xpack.default
})
}
} else {
loadComponent()
}
})
const emits = defineEmits(['loadFail'])
defineExpose({
invokeMethod

View File

@ -171,6 +171,8 @@ service.interceptors.response.use(
} else if (response.config.url.match(/^\/map|geo\/\d{3}\/\d+\.json$/)) {
// TODO 处理静态文件
return response
} else if (response.config.url.includes('DEXPack.umd.js')) {
return response
} else {
if (
!response?.config?.url.startsWith('/xpackComponent/content') &&

@ -1 +1 @@
Subproject commit 53ef3a55d9ce36f3227a9851915250e55a32476d
Subproject commit e025afe5ebce6c2987c6b24b4e48c6a8d583fec6

View File

@ -26,6 +26,7 @@ public class WhitelistUtils {
"/dekey",
"/index.html",
"/model",
"/xpackModel",
"/swagger-resources",
"/doc.html",
"/panel.html",