CatPtain commited on
Commit
22fed99
·
verified ·
1 Parent(s): 4f82329

Upload public.js

Browse files
Files changed (1) hide show
  1. backend/src/routes/public.js +33 -38
backend/src/routes/public.js CHANGED
@@ -98,26 +98,34 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
98
 
99
  const pptDimensions = calculatePptDimensions(slide);
100
 
101
- // 渲染幻灯片元素
102
  const renderElements = (elements) => {
103
  if (!elements || elements.length === 0) return '';
104
 
105
  return elements.map(element => {
 
 
 
 
 
 
106
  const style = `
107
  position: absolute;
108
- left: ${element.left}px;
109
- top: ${element.top}px;
110
- width: ${element.width}px;
111
- height: ${element.height}px;
112
  transform: rotate(${element.rotate || 0}deg);
113
  z-index: ${element.zIndex || 1};
114
  `;
115
 
116
  switch (element.type) {
117
  case 'text':
 
 
118
  return `
119
  <div style="${style}
120
- font-size: ${element.fontSize || 14}px;
121
  font-family: ${element.fontName || 'Arial'};
122
  color: ${element.defaultColor || '#000'};
123
  font-weight: ${element.bold ? 'bold' : 'normal'};
@@ -125,9 +133,10 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
125
  text-decoration: ${element.underline ? 'underline' : 'none'};
126
  text-align: ${element.align || 'left'};
127
  line-height: ${element.lineHeight || 1.2};
128
- padding: 10px;
129
  word-wrap: break-word;
130
  overflow: hidden;
 
131
  ">
132
  ${element.content || ''}
133
  </div>
@@ -135,14 +144,14 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
135
  case 'image':
136
  return `
137
  <div style="${style}">
138
- <img src="${element.src}" alt="" style="width: 100%; height: 100%; object-fit: ${element.objectFit || 'contain'};" />
139
  </div>
140
  `;
141
  case 'shape':
142
  const shapeStyle = element.fill ? `background-color: ${element.fill};` : '';
143
- const borderStyle = element.outline ? `border: ${element.outline.width || 1}px ${element.outline.style || 'solid'} ${element.outline.color || '#000'};` : '';
144
  return `
145
- <div style="${style} ${shapeStyle} ${borderStyle}"></div>
146
  `;
147
  default:
148
  return `<div style="${style}"></div>`;
@@ -201,12 +210,12 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
201
  /* 尺寸将通过JavaScript动态设置 */
202
  }
203
 
204
- /* PPT内容区域 - 完全填满容器 */
205
  .ppt-content {
206
  width: 100% !important;
207
  height: 100% !important;
208
  position: relative !important;
209
- transform-origin: top left !important;
210
  }
211
 
212
  /* 背景图片处理 */
@@ -271,7 +280,7 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
271
  height: ${pptDimensions.height}
272
  };
273
 
274
- console.log('PPT页面初始化 - 长宽比匹配模式:', window.PPT_DIMENSIONS);
275
 
276
  // 计算容器尺寸,保持PPT长宽比,最大化填满窗口
277
  function calculateContainerSize() {
@@ -303,47 +312,33 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
303
  };
304
  }
305
 
306
- // 应用容器尺寸和PPT内容缩放
307
  function adaptPPTToWindow() {
308
  const container = document.getElementById('slideContainer');
309
  const content = document.getElementById('pptContent');
310
  if (!container || !content) return;
311
 
312
  const containerSize = calculateContainerSize();
313
- const pptWidth = ${pptDimensions.width};
314
- const pptHeight = ${pptDimensions.height};
315
 
316
  // 设置容器尺寸(保持PPT长宽比)
317
  container.style.width = containerSize.width + 'px';
318
  container.style.height = containerSize.height + 'px';
319
 
320
- // 计算PPT内容的缩放比例
321
- const scaleX = containerSize.width / pptWidth;
322
- const scaleY = containerSize.height / pptHeight;
 
323
 
324
- // 由于容器已经保持了PPT的长宽比,scaleX和scaleY应该相等
325
- const scale = Math.min(scaleX, scaleY);
326
-
327
- // 设置PPT内容尺寸和缩放
328
- content.style.width = pptWidth + 'px';
329
- content.style.height = pptHeight + 'px';
330
- content.style.transform = \`scale(\${scale})\`;
331
- content.style.position = 'absolute';
332
- content.style.top = '0';
333
- content.style.left = '0';
334
-
335
- console.log(\`容器尺寸: \${containerSize.width}x\${containerSize.height}, PPT原始: \${pptWidth}x\${pptHeight}, 缩放: \${scale.toFixed(3)}\`);
336
- console.log(\`PPT长宽比: \${(pptWidth/pptHeight).toFixed(3)}, 容器长宽比: \${(containerSize.width/containerSize.height).toFixed(3)}\`);
337
  }
338
 
339
  // 页面加载完成后初始化
340
  window.addEventListener('load', function() {
341
  const html = document.documentElement;
342
  const body = document.body;
343
- const container = document.getElementById('slideContainer');
344
- const content = document.getElementById('pptContent');
345
 
346
- console.log('页面加载完成,开始长宽比匹配布局');
347
 
348
  // 确保页面元素填满窗口
349
  html.style.width = '100vw';
@@ -397,18 +392,18 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
397
  }
398
  }, { passive: false });
399
 
400
- console.log('长宽比匹配PPT页面初始化完成');
401
  });
402
 
403
  // 监听窗口大小变化,实时调整布局
404
  window.addEventListener('resize', function() {
405
- console.log('窗口大小变化,重新计算长宽比匹配布局');
406
  adaptPPTToWindow();
407
  });
408
 
409
  // 监听屏幕方向变化(移动设备)
410
  window.addEventListener('orientationchange', function() {
411
- console.log('屏幕方向变化,重新计算长宽比匹配布局');
412
  setTimeout(adaptPPTToWindow, 100);
413
  });
414
  </script>
 
98
 
99
  const pptDimensions = calculatePptDimensions(slide);
100
 
101
+ // 渲染幻灯片元素 - 使用相对单位,支持动态缩放
102
  const renderElements = (elements) => {
103
  if (!elements || elements.length === 0) return '';
104
 
105
  return elements.map(element => {
106
+ // 计算相对于PPT原始尺寸的百分比位置和大小
107
+ const leftPercent = ((element.left || 0) / pptDimensions.width) * 100;
108
+ const topPercent = ((element.top || 0) / pptDimensions.height) * 100;
109
+ const widthPercent = ((element.width || 0) / pptDimensions.width) * 100;
110
+ const heightPercent = ((element.height || 0) / pptDimensions.height) * 100;
111
+
112
  const style = `
113
  position: absolute;
114
+ left: ${leftPercent}%;
115
+ top: ${topPercent}%;
116
+ width: ${widthPercent}%;
117
+ height: ${heightPercent}%;
118
  transform: rotate(${element.rotate || 0}deg);
119
  z-index: ${element.zIndex || 1};
120
  `;
121
 
122
  switch (element.type) {
123
  case 'text':
124
+ // 字体大小也需要相对于容器尺寸进行缩放
125
+ const fontSizePercent = ((element.fontSize || 14) / pptDimensions.height) * 100;
126
  return `
127
  <div style="${style}
128
+ font-size: ${fontSizePercent}vh;
129
  font-family: ${element.fontName || 'Arial'};
130
  color: ${element.defaultColor || '#000'};
131
  font-weight: ${element.bold ? 'bold' : 'normal'};
 
133
  text-decoration: ${element.underline ? 'underline' : 'none'};
134
  text-align: ${element.align || 'left'};
135
  line-height: ${element.lineHeight || 1.2};
136
+ padding: 1vh;
137
  word-wrap: break-word;
138
  overflow: hidden;
139
+ box-sizing: border-box;
140
  ">
141
  ${element.content || ''}
142
  </div>
 
144
  case 'image':
145
  return `
146
  <div style="${style}">
147
+ <img src="${element.src}" alt="" style="width: 100%; height: 100%; object-fit: ${element.objectFit || 'cover'}; display: block;" />
148
  </div>
149
  `;
150
  case 'shape':
151
  const shapeStyle = element.fill ? `background-color: ${element.fill};` : '';
152
+ const borderStyle = element.outline ? `border: ${((element.outline.width || 1) / pptDimensions.height) * 100}vh ${element.outline.style || 'solid'} ${element.outline.color || '#000'};` : '';
153
  return `
154
+ <div style="${style} ${shapeStyle} ${borderStyle} box-sizing: border-box;"></div>
155
  `;
156
  default:
157
  return `<div style="${style}"></div>`;
 
210
  /* 尺寸将通过JavaScript动态设置 */
211
  }
212
 
213
+ /* PPT内容区域 - 完全填满容器,不需要额外缩放 */
214
  .ppt-content {
215
  width: 100% !important;
216
  height: 100% !important;
217
  position: relative !important;
218
+ overflow: hidden !important;
219
  }
220
 
221
  /* 背景图片处理 */
 
280
  height: ${pptDimensions.height}
281
  };
282
 
283
+ console.log('PPT页面初始化 - 响应式元素缩放模式:', window.PPT_DIMENSIONS);
284
 
285
  // 计算容器尺寸,保持PPT长宽比,最大化填满窗口
286
  function calculateContainerSize() {
 
312
  };
313
  }
314
 
315
+ // 应用容器尺寸,PPT元素会自动适应
316
  function adaptPPTToWindow() {
317
  const container = document.getElementById('slideContainer');
318
  const content = document.getElementById('pptContent');
319
  if (!container || !content) return;
320
 
321
  const containerSize = calculateContainerSize();
 
 
322
 
323
  // 设置容器尺寸(保持PPT长宽比)
324
  container.style.width = containerSize.width + 'px';
325
  container.style.height = containerSize.height + 'px';
326
 
327
+ // PPT内容完全填满容器,元素使用百分比单位会自动缩放
328
+ content.style.width = '100%';
329
+ content.style.height = '100%';
330
+ content.style.position = 'relative';
331
 
332
+ console.log(`容器尺寸: ${containerSize.width}x${containerSize.height}`);
333
+ console.log(`PPT长宽比: ${(pptDimensions.width/pptDimensions.height).toFixed(3)}, 容器长宽比: ${(containerSize.width/containerSize.height).toFixed(3)}`);
 
 
 
 
 
 
 
 
 
 
 
334
  }
335
 
336
  // 页面加载完成后初始化
337
  window.addEventListener('load', function() {
338
  const html = document.documentElement;
339
  const body = document.body;
 
 
340
 
341
+ console.log('页面加载完成,开始响应式元素布局');
342
 
343
  // 确保页面元素填满窗口
344
  html.style.width = '100vw';
 
392
  }
393
  }, { passive: false });
394
 
395
+ console.log('响应式元素PPT页面初始化完成');
396
  });
397
 
398
  // 监听窗口大小变化,实时调整布局
399
  window.addEventListener('resize', function() {
400
+ console.log('窗口大小变化,重新计算响应式布局');
401
  adaptPPTToWindow();
402
  });
403
 
404
  // 监听屏幕方向变化(移动设备)
405
  window.addEventListener('orientationchange', function() {
406
+ console.log('屏幕方向变化,重新计算响应式布局');
407
  setTimeout(adaptPPTToWindow, 100);
408
  });
409
  </script>