首页 > 其他 > 详细

二进制流转base64加快速度

时间:2019-12-13 13:47:59      阅读:131      评论:0      收藏:0      [点我收藏+]
updateImgList() {
const reg = /\.(\w+)$/
const __arrPromise__ = []
const self = this
for (let i = 0; i < self.totalPicture[self.pageNum].length; i++) {
const fn = new Promise((resolve) => {
self.$api.getArrayBuffer(self.totalPicture[self.pageNum][i].id).then((response) => {
let obj = null
// 是否TIF和TIFF格式的图片
if (self.totalPicture[self.pageNum][i].filePath.match(reg)[1] === ‘tif‘ || self.totalPicture[self.pageNum][i].filePath.match(reg)[1] === ‘tiff‘) {
// eslint-disable-next-line no-undef
const tiff = new Tiff({ buffer: response })
obj = {
id: self.totalPicture[self.pageNum][i].id,
type: ‘tif‘,
url: tiff.toDataURL()
}
} else {
obj = {
type: ‘mormal‘,
id: self.totalPicture[self.pageNum][i].id,
url: (‘data:data/png;base64,‘ + btoa(
new Uint8Array(response).reduce((data, byte) => data + String.fromCharCode(byte), ‘‘)
))
// ‘/label/job-picture/show-image?id=‘ + self.totalPicture[self.pageNum][i].id
}
}
resolve(obj)
}).catch(error => {})
})
__arrPromise__.push(fn)
}
Promise.all(__arrPromise__).then((res) => {
self.imgList = self.imgList.concat(res)
let activeIndex = 0
if (self.imgSwiper) {
activeIndex = self.imgSwiper.activeIndex
}
if (self.pageNum == 0) {
self.$nextTick(() => {
self.initSwiper()
})
}
self.updateTopImg(self.imgList[activeIndex].id)
})
},

二进制流转base64加快速度

原文:https://www.cnblogs.com/MDGE/p/12034415.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!