fix:处理图片加载的闭包问题

This commit is contained in:
zhangyu
2022-07-06 10:37:03 +08:00
parent 543f6efda8
commit 8a6635b7ff
3 changed files with 51 additions and 13 deletions

View File

@@ -16,7 +16,7 @@ export function getUUID () {
return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4())
}
const chartCache = {}
export const chartCache = {}
export function getChart (key) {
return chartCache[`chart${key}`]
@@ -48,6 +48,48 @@ export function getTopologyImg (key) {
return false
}
const topologyImg = {}
export function dealImg (url, id) {
if (url) {
return new Promise((resolve, reject) => {
if (topologyImg['img' + id]) {
resolve(topologyImg['img' + id])
return
}
vm.$axios
.get(url)
.then((res) => {
const imageInfo = {
data: ('data:image/jpeg;base64,' + res.data),
// width: res.headers.width === -1 ? 100 : (res.headers.width > 900 ? 900 : res.headers.width),
// height: res.headers.height === -1 ? 100 : (res.headers.height > 900 ? 900 : res.headers.height)
width: res.headers.width === -1 ? 100 : Number(res.headers.width),
height: res.headers.height === -1 ? 100 : Number(res.headers.height)
}
if (imageInfo.width > 900 || imageInfo.height > 900) {
if (imageInfo.height > imageInfo.width) {
imageInfo.width = imageInfo.width * 900 / imageInfo.height
imageInfo.height = 900
} else if (imageInfo.height < imageInfo.width) {
imageInfo.height = imageInfo.height * 900 / imageInfo.width
imageInfo.width = 900
} else {
imageInfo.height = 900
imageInfo.width = 900
}
}
topologyImg['img' + id] = imageInfo
resolve(topologyImg['img' + id])
})
})
} else {
return new Promise(resolve => {
resolve({})
})
}
}
export function setTopologyImg (key, img) {
// localStorage.setItem('nz-topologyImg-' + key, img)
}