fix: 嵌入式的场景下,部分静态资源无法加载。

This commit is contained in:
dataeaseShu 2023-11-23 09:48:38 +08:00
parent 69d69794ee
commit 251b6c3a29
2 changed files with 12 additions and 7 deletions

View File

@ -12,7 +12,7 @@ const formatterUrl = <T extends Node>(node: T, prefix: string) => {
url = node.src
}
if (url.includes(suffix)) {
if (url.includes(suffix) || url.includes('dataease-private')) {
const currentUrlprefix = new URL(url).origin
const newUrl = url.replace(currentUrlprefix, prefix)
if (node instanceof HTMLLinkElement) {

View File

@ -10,19 +10,24 @@ const { canvasStyleData, componentData, canvasViewInfo, canvasViewDataInfo, dvIn
storeToRefs(dvMainStore)
const basePath = import.meta.env.VITE_API_BASEPATH
export function formatterUrl(url: string) {
return url.replace('//de2api', '/de2api')
}
export function imgUrlTrans(url) {
if (url) {
if (typeof url === 'string' && url.indexOf('static-resource') > -1) {
const rawUrl = url
? (basePath.endsWith('/') ? basePath.substring(0, basePath.length - 1) : basePath) + url
: null
return window.DataEaseBi
? `${window.DataEaseBi.baseUrl}${
rawUrl.startsWith('/api') ? rawUrl.slice(5) : rawUrl
}`.replace('com//', 'com/')
: rawUrl
return formatterUrl(
window.DataEaseBi
? `${window.DataEaseBi.baseUrl}${
rawUrl.startsWith('/api') ? rawUrl.slice(5) : rawUrl
}`.replace('com//', 'com/')
: rawUrl
)
} else {
return url.replace('com//', 'com/')
return formatterUrl(url.replace('com//', 'com/'))
}
}
}