|
|
@@ -260,18 +260,27 @@ export default function WordPreview() {
|
|
|
const arrayBuffer = await wordFile.arrayBuffer();
|
|
|
const zip = new PizZip(arrayBuffer);
|
|
|
|
|
|
- // 配置图片模块
|
|
|
+ // 预加载所有图片数据,避免Promise问题
|
|
|
+ const folderIndex = (rowIndex + 1).toString();
|
|
|
+ const imageDataMap: Record<string, ArrayBuffer> = {};
|
|
|
+
|
|
|
+ // 预加载当前文件夹的所有图片
|
|
|
+ if (imageMappings[folderIndex]) {
|
|
|
+ for (const [imageName, imageFile] of Object.entries(imageMappings[folderIndex])) {
|
|
|
+ try {
|
|
|
+ imageDataMap[imageName] = await imageFile.arrayBuffer();
|
|
|
+ } catch (error) {
|
|
|
+ console.warn(`Failed to load image ${imageName}:`, error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 配置图片模块 - 使用同步数据
|
|
|
const imageOpts = {
|
|
|
centered: false,
|
|
|
- getImage: (tagValue: string) => {
|
|
|
- console.log('tagValue', tagValue);
|
|
|
+ getImage: (tagValue: string): ArrayBuffer | null => {
|
|
|
if (tagValue && typeof tagValue === 'string') {
|
|
|
- // 从imageMappings中获取对应的图片
|
|
|
- const folderIndex = (rowIndex + 1).toString();
|
|
|
- const imageFile = imageMappings[folderIndex]?.[tagValue];
|
|
|
- if (imageFile) {
|
|
|
- return imageFile.arrayBuffer();
|
|
|
- }
|
|
|
+ return imageDataMap[tagValue] || null;
|
|
|
}
|
|
|
return null;
|
|
|
},
|
|
|
@@ -306,10 +315,10 @@ export default function WordPreview() {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 处理图片字段 - 直接传递图片名称
|
|
|
- const folderIndex = (rowIndex + 1).toString();
|
|
|
+ // 处理图片字段 - 确保图片名称正确传递给模板
|
|
|
if (imageMappings[folderIndex]) {
|
|
|
for (const [imageName] of Object.entries(imageMappings[folderIndex])) {
|
|
|
+ // 确保图片名称作为标签值传递给模板
|
|
|
processedData[imageName] = imageName;
|
|
|
}
|
|
|
}
|