From eb4111e0fd7110e5aa6a00608da2da9af21a3035 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期一, 20 十月 2025 10:13:32 +0800
Subject: [PATCH] 2025.10.18 修改嫉妒报告生成逻辑
---
src/utils/doc.js | 44 ++++++++++++++++++++++++++++++++++++++------
1 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/src/utils/doc.js b/src/utils/doc.js
index 8082330..fb15036 100644
--- a/src/utils/doc.js
+++ b/src/utils/doc.js
@@ -5,6 +5,33 @@
import FileSaver from 'file-saver';
/**
+ * 灏哹ase64鏍煎紡鍥剧墖杞崲涓篈rrayBuffer
+ * @param {string} base64Str - base64鏍煎紡鍥剧墖瀛楃涓诧紙鍙寘鍚玠ata URL鍓嶇紑锛�
+ * @returns {ArrayBuffer} 杞崲鍚庣殑ArrayBuffer瀵硅薄
+ */
+function base64ToArrayBuffer(base64Str) {
+ // 绉婚櫎data URL鍓嶇紑锛堝鏋滃瓨鍦級
+ const base64Content = base64Str.replace(/^data:image\/\w+;base64,/, '');
+
+ // 澶勭悊URL瀹夊叏鐨刡ase64瀛楃
+ const safeBase64 = base64Content.replace(/-/g, '+').replace(/_/g, '/');
+
+ // 瑙g爜base64瀛楃涓�
+ const binaryStr = atob(safeBase64);
+
+ // 杞崲涓篣int8Array
+ const byteLength = binaryStr.length;
+ const uint8Array = new Uint8Array(byteLength);
+
+ for (let i = 0; i < byteLength; i++) {
+ uint8Array[i] = binaryStr.charCodeAt(i);
+ }
+
+ // 杩斿洖ArrayBuffer
+ return uint8Array.buffer;
+}
+
+/**
* 绛夋瘮渚嬬缉鏀惧浘鐗�
* 鏍规嵁鍥剧墖鐨勯暱瀹芥瘮杩涜涓嶅悓鏂瑰紡鐨勭缉鏀�
* 濡傛灉瀹藉害澶т簬楂樺害锛堟í鎷嶅浘鐗囷級锛屽垯鎸夌収璁惧畾楂樺害绛夋瘮缂╂斁锛�
@@ -122,12 +149,17 @@
getImage(tagValue) {
// In this case tagValue will be a URL tagValue = "https://docxtemplater.com/puffin.png"
return new Promise(function (resolve, reject) {
- JSZipUtils.getBinaryContent(tagValue, function (error, content) {
- if (error) {
- return reject(error);
- }
- return resolve(content);
- });
+ if (tagValue.indexOf('http') == 0) {
+ JSZipUtils.getBinaryContent(tagValue, function (error, content) {
+ if (error) {
+ return reject(error);
+ }
+ return resolve(content);
+ });
+ } else if (tagValue.indexOf('data:image') == 0) {
+ const buffer = base64ToArrayBuffer(tagValue);
+ return resolve(buffer);
+ }
});
},
--
Gitblit v1.9.3