forked from github/dataease
feat(X-Pack): xpack前端分离部署打包
This commit is contained in:
parent
1d6838b835
commit
c56514b063
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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' })
|
||||
|
@ -1,10 +1,9 @@
|
||||
<script lang="ts" setup>
|
||||
import noLic from './nolic.vue'
|
||||
import { ref, useAttrs, nextTick, shallowRef, computed, reactive, watch, onMounted } 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 { useI18n } from '@/hooks/web/useI18n'
|
||||
import { i18n } from '@/plugins/vue-i18n'
|
||||
import * as Vue from 'vue'
|
||||
import axios from 'axios'
|
||||
@ -13,32 +12,6 @@ import * as vueI18n from 'vue-i18n'
|
||||
import * as vueRouter from 'vue-router'
|
||||
import { useEmitt } from '@/hooks/web/useEmitt'
|
||||
|
||||
const target = ref()
|
||||
|
||||
onMounted(() => {
|
||||
window.Vue = Vue
|
||||
window.Axios = axios
|
||||
window.Pinia = Pinia
|
||||
window.vueI18n = vueI18n
|
||||
window.vueRouter = vueRouter
|
||||
window.MittAll = useEmitt().emitter.all
|
||||
window.I18n = i18n
|
||||
const xhr = new XMLHttpRequest()
|
||||
xhr.onreadystatechange = () => {
|
||||
if (xhr.readyState !== xhr.DONE) return
|
||||
async function getDEXPack() {
|
||||
const xpack = await window.DEXPack.mapping[attrs.jsname]
|
||||
target.value = xpack.default
|
||||
}
|
||||
|
||||
nextTick(() => {
|
||||
getDEXPack()
|
||||
})
|
||||
}
|
||||
xhr.open('get', 'http://192.168.31.47:8000/DEXPack.umd.js')
|
||||
xhr.send()
|
||||
})
|
||||
|
||||
const { wsCache } = useCache()
|
||||
|
||||
const plugin = ref()
|
||||
@ -107,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
|
||||
|
@ -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') &&
|
||||
|
2
de-xpack
2
de-xpack
@ -1 +1 @@
|
||||
Subproject commit 53ef3a55d9ce36f3227a9851915250e55a32476d
|
||||
Subproject commit e025afe5ebce6c2987c6b24b4e48c6a8d583fec6
|
@ -26,6 +26,7 @@ public class WhitelistUtils {
|
||||
"/dekey",
|
||||
"/index.html",
|
||||
"/model",
|
||||
"/xpackModel",
|
||||
"/swagger-resources",
|
||||
"/doc.html",
|
||||
"/panel.html",
|
||||
|
Loading…
Reference in New Issue
Block a user