From d2a906de31b8932190fd7fb63ff716ec8fa2c771 Mon Sep 17 00:00:00 2001 From: chenrui <1187576398@qq.com> Date: 星期一, 19 五月 2025 13:54:08 +0800 Subject: [PATCH] 插回损功能开发 --- src/util/fileTransform.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 deletions(-) diff --git a/src/util/fileTransform.js b/src/util/fileTransform.js index 832fa2a..6f8ccec 100644 --- a/src/util/fileTransform.js +++ b/src/util/fileTransform.js @@ -17,3 +17,43 @@ document.body.removeChild(elink) } } + +export function transformZip(response) { + const relType = ['application/zip'] + let type = response.data.type + if (relType.includes(type)) { + const blob = new Blob([response.data], {type: 'application/zip'}) + 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) + } +} + +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) + } +} -- Gitblit v1.9.3