From 9674af17d8e7ad8f85c9df3b89d99a71d7e39268 Mon Sep 17 00:00:00 2001
From: 祖安之光 <11848914+light-of-zuan@user.noreply.gitee.com>
Date: 星期三, 03 十二月 2025 13:11:09 +0800
Subject: [PATCH] 修改新增
---
src/views/build/conpanyFunctionConsult/digitalFileDep/manageType/qualityManual/components/exportDoc.js | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 112 insertions(+), 5 deletions(-)
diff --git a/src/views/build/conpanyFunctionConsult/digitalFileDep/manageType/qualityManual/components/exportDoc.js b/src/views/build/conpanyFunctionConsult/digitalFileDep/manageType/qualityManual/components/exportDoc.js
index 41a294d..b027f15 100644
--- a/src/views/build/conpanyFunctionConsult/digitalFileDep/manageType/qualityManual/components/exportDoc.js
+++ b/src/views/build/conpanyFunctionConsult/digitalFileDep/manageType/qualityManual/components/exportDoc.js
@@ -271,12 +271,103 @@
}
return bytes.buffer;
}
+
+function getDimensionsFromBase64Sync(base64Str) {
+ try {
+ // 去除 data:image/...;base64, 前缀
+ const base64Data = base64Str.replace(/^data:image\/\w+;base64,/, '');
+
+ // 将base64转换为二进制
+ const binaryString = atob(base64Data);
+ const bytes = new Uint8Array(binaryString.length);
+ for (let i = 0; i < binaryString.length; i++) {
+ bytes[i] = binaryString.charCodeAt(i);
+ }
+
+ return parseImageDimensions(bytes);
+ } catch (error) {
+ console.warn('解析图片尺寸失败:', error);
+ return { width: 600, height: 400 };
+ }
+}
+
+function parseImageDimensions(bytes) {
+ if (bytes.length < 8) {
+ return { width: 600, height: 400 };
+ }
+
+ // 检查 PNG 格式 (89 50 4E 47 0D 0A 1A 0A)
+ if (bytes[0] === 0x89 && bytes[1] === 0x50 &&
+ bytes[2] === 0x4E && bytes[3] === 0x47) {
+ return parsePNGDimensions(bytes);
+ }
+
+ // 检查 JPEG 格式 (FF D8)
+ if (bytes[0] === 0xFF && bytes[1] === 0xD8) {
+ return parseJPEGDimensions(bytes);
+ }
+
+ return { width: 600, height: 400 };
+}
+
+// 解析 PNG 尺寸
+function parsePNGDimensions(bytes) {
+ // PNG 的宽高在 IHDR chunk 中(偏移 16-24 字节)
+ if (bytes.length >= 24) {
+ const view = new DataView(bytes.buffer);
+ const width = view.getUint32(16, false); // 大端序
+ const height = view.getUint32(20, false);
+ return { width, height };
+ }
+ return { width: 600, height: 400 };
+}
+
+// 解析 JPEG 尺寸
+function parseJPEGDimensions(bytes) {
+ let i = 2; // 跳过 FFD8
+
+ while (i < bytes.length - 1) {
+ // JPEG 标记开始
+ if (bytes[i] === 0xFF) {
+ const marker = bytes[i + 1];
+
+ // SOF0, SOF1, SOF2 (Start of Frame markers)
+ if ((marker >= 0xC0 && marker <= 0xC3) ||
+ (marker >= 0xC5 && marker <= 0xC7) ||
+ (marker >= 0xC9 && marker <= 0xCB) ||
+ (marker >= 0xCD && marker <= 0xCF)) {
+
+ if (i + 7 < bytes.length) {
+ const height = (bytes[i + 5] << 8) | bytes[i + 6];
+ const width = (bytes[i + 7] << 8) | bytes[i + 8];
+ return { width, height };
+ }
+ break;
+ }
+
+ // 跳过当前段
+ const length = (bytes[i + 2] << 8) | bytes[i + 3];
+ i += length + 2;
+ } else {
+ i++;
+ }
+ }
+
+ return { width: 600, height: 400 };
+}
+
const imageOptions = {
getImage(tagValue) {
return base64Parser(tagValue);
},
getSize(img, tagValue, tagName, context) {
- return [600, 600];
+ const dimensions = getDimensionsFromBase64Sync(tagValue);
+ const { width, height } = dimensions;
+ const targetWidth = 600;
+ const scale = targetWidth / width;
+ let targetHeight = height * scale;
+ targetHeight = Math.max(100, Math.min(700, targetHeight));
+ return [targetWidth, Math.round(targetHeight)];
},
};
@@ -309,11 +400,27 @@
// data.departmentsTable = processTableHtml(tableHtml);
// }
- // 生成表格XML
- // if (data.clauses && data.duties) {
- // data.tableXML = generateTableXML(data.clauses, data.duties);
- // }
+ if (data.productServiceImages && Array.isArray(data.productServiceImages)) {
+ // 确保是纯 base64 字符串数组
+ data.productServiceImageArray = data.productServiceImages.map(item =>
+ typeof item === 'object' ? item.image : item
+ ).filter(img => img && typeof img === 'string');
+ // 为前10张图片创建单独的图片变量
+ data.productServiceImageArray.slice(0, 10).forEach((img, index) => {
+ data[`productServiceImage${index + 1}`] = img;
+ });
+
+ // 创建带元数据的对象数组
+ data.productServiceImageObjects = data.productServiceImageArray.map((img, index) => ({
+ image: img, // 这个字段会作为图片插入
+ index: index + 1,
+ description: `产品和服务实现过程图 ${index + 1}`
+ }));
+
+ data.productServiceCount = data.productServiceImageArray.length;
+ data.hasProductServiceImages = data.productServiceImageArray.length > 0;
+ }
// 处理富文本字段(如果有)
if (data.summaries && typeof data.summaries === 'string') {
data.summaries = processRichText(data.summaries);
--
Gitblit v1.9.2