chenrui
2025-03-28 5692bc829ac5cb1b1fbd113a89c44d2d3c3a41ee
src/util/fileTransform.js
@@ -36,4 +36,24 @@
    URL.revokeObjectURL(elink.href) // 释放URL 对象
    document.body.removeChild(elink)
  }
}
}
export function transformDoc(response) {
    const relType = ['application/vnd.openxmlformats-officedocument.wordprocessingml.document']
    let type = response.data.type
    if (relType.includes(type)) {
        const blob = new Blob([response.data], {type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'})
        const disposition = response.headers["content-disposition"]
        let temp = disposition.substring(disposition.lastIndexOf('=') + 1)
        let filename = decodeURI(temp)
        // 创建一个超链接,将文件流赋进去,然后实现这个超链接的单击事件
        const elink = document.createElement('a')
        elink.download = filename
        elink.style.display = 'none'
        elink.href = URL.createObjectURL(blob)
        document.body.appendChild(elink)
        elink.click()
        URL.revokeObjectURL(elink.href) // 释放URL 对象
        document.body.removeChild(elink)
    }
}