CatPtain commited on
Commit
c69749e
·
verified ·
1 Parent(s): ad7128b

Upload useExport.ts

Browse files
Files changed (1) hide show
  1. frontend/src/hooks/useExport.ts +61 -2
frontend/src/hooks/useExport.ts CHANGED
@@ -996,14 +996,58 @@ export default () => {
996
 
997
  else if (el.type === 'shape') {
998
  if (el.special) {
999
- const svgRef = document.querySelector(`.thumbnail-list .base-element-${el.id} svg`) as HTMLElement
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1000
 
1001
  // 改进的尺寸检查逻辑
1002
  if (!svgRef) {
1003
- console.warn(`SVG element not found for shape ${el.id}`);
 
 
1004
  continue;
1005
  }
1006
 
 
 
 
 
 
 
1007
  // 获取多种尺寸信息进行判断
1008
  const clientWidth = svgRef.clientWidth;
1009
  const clientHeight = svgRef.clientHeight;
@@ -1070,12 +1114,27 @@ export default () => {
1070
  // SVG序列化with错误处理
1071
  let base64SVG;
1072
  try {
 
 
 
1073
  base64SVG = svg2Base64(svgRef);
 
 
 
 
 
 
 
1074
  if (!base64SVG || base64SVG === 'data:image/svg+xml;base64,') {
1075
  throw new Error('SVG serialization returned empty result');
1076
  }
1077
  } catch (error) {
1078
  console.error(`SVG serialization failed for shape ${el.id}:`, error);
 
 
 
 
 
1079
  continue;
1080
  }
1081
 
 
996
 
997
  else if (el.type === 'shape') {
998
  if (el.special) {
999
+ // 调试:记录元素信息
1000
+ console.log(`Processing special shape ${el.id}:`, {
1001
+ type: el.type,
1002
+ special: el.special,
1003
+ width: el.width,
1004
+ height: el.height,
1005
+ left: el.left,
1006
+ top: el.top
1007
+ });
1008
+
1009
+ // 尝试多种选择器策略
1010
+ let svgRef = document.querySelector(`.thumbnail-list .base-element-${el.id} svg`) as HTMLElement;
1011
+
1012
+ if (!svgRef) {
1013
+ // 尝试其他可能的选择器
1014
+ svgRef = document.querySelector(`[data-element-id="${el.id}"] svg`) as HTMLElement;
1015
+ }
1016
+
1017
+ if (!svgRef) {
1018
+ svgRef = document.querySelector(`#element-${el.id} svg`) as HTMLElement;
1019
+ }
1020
+
1021
+ if (!svgRef) {
1022
+ // 尝试查找所有SVG元素并匹配
1023
+ const allSvgs = document.querySelectorAll('svg');
1024
+ console.log(`Found ${allSvgs.length} SVG elements in document`);
1025
+
1026
+ for (let i = 0; i < allSvgs.length; i++) {
1027
+ const svg = allSvgs[i] as HTMLElement;
1028
+ const parent = svg.closest(`[class*="${el.id}"]`);
1029
+ if (parent) {
1030
+ svgRef = svg;
1031
+ console.log(`Found SVG for ${el.id} using parent matching`);
1032
+ break;
1033
+ }
1034
+ }
1035
+ }
1036
 
1037
  // 改进的尺寸检查逻辑
1038
  if (!svgRef) {
1039
+ console.warn(`SVG element not found for shape ${el.id} after trying multiple selectors`);
1040
+ console.log('Available elements with class containing element ID:',
1041
+ document.querySelectorAll(`[class*="${el.id}"]`));
1042
  continue;
1043
  }
1044
 
1045
+ console.log(`Found SVG element for ${el.id}:`, {
1046
+ tagName: svgRef.tagName,
1047
+ className: svgRef.className,
1048
+ innerHTML: svgRef.innerHTML.substring(0, 200) + '...'
1049
+ });
1050
+
1051
  // 获取多种尺寸信息进行判断
1052
  const clientWidth = svgRef.clientWidth;
1053
  const clientHeight = svgRef.clientHeight;
 
1114
  // SVG序列化with错误处理
1115
  let base64SVG;
1116
  try {
1117
+ console.log(`Starting SVG serialization for ${el.id}`);
1118
+ console.log('SVG content before serialization:', svgRef.outerHTML.substring(0, 500) + '...');
1119
+
1120
  base64SVG = svg2Base64(svgRef);
1121
+
1122
+ console.log(`SVG serialization result for ${el.id}:`, {
1123
+ success: !!base64SVG,
1124
+ length: base64SVG ? base64SVG.length : 0,
1125
+ preview: base64SVG ? base64SVG.substring(0, 100) + '...' : 'null'
1126
+ });
1127
+
1128
  if (!base64SVG || base64SVG === 'data:image/svg+xml;base64,') {
1129
  throw new Error('SVG serialization returned empty result');
1130
  }
1131
  } catch (error) {
1132
  console.error(`SVG serialization failed for shape ${el.id}:`, error);
1133
+ console.log('SVG element that failed:', svgRef);
1134
+ console.log('SVG outerHTML:', svgRef.outerHTML);
1135
+
1136
+ // 尝试降级处理
1137
+ console.log(`Attempting fallback processing for shape ${el.id}`);
1138
  continue;
1139
  }
1140