zoukankan      html  css  js  c++  java
  • 二进制流转base64加快速度

    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)
    })
    },
  • 相关阅读:
    model.object对象查询过滤、增删改、Q
    模板中的标签、过滤器
    模板(template)包含与继承
    url用法
    AD用户登录验证,遍历OU(LDAP)
    Python下操作sqlite3
    多线程应用-类(thread)
    数组(list)分组、分段
    多线程应用-函数方式(thread)
    IntelliJ IDEA maven项目 ***
  • 原文地址:https://www.cnblogs.com/MDGE/p/12034415.html
Copyright © 2011-2022 走看看