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

Upload public.js

Browse files
Files changed (1) hide show
  1. backend/src/routes/public.js +65 -45
backend/src/routes/public.js CHANGED
@@ -178,7 +178,7 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
178
  left: 0 !important;
179
  }
180
 
181
- /* Body - 填满整个窗口,黑色背景 */
182
  body {
183
  width: 100vw !important;
184
  height: 100vh !important;
@@ -188,20 +188,20 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
188
  position: fixed !important;
189
  top: 0 !important;
190
  left: 0 !important;
 
 
 
191
  }
192
 
193
- /* PPT容器 - 完全填满窗口,无边距 */
194
  .slide-container {
195
- width: 100vw !important;
196
- height: 100vh !important;
197
  background-color: ${slide.background?.color || theme.backgroundColor || '#ffffff'} !important;
198
- position: fixed !important;
199
- top: 0 !important;
200
- left: 0 !important;
201
  overflow: hidden !important;
 
202
  }
203
 
204
- /* PPT内容区域 - 自适应容器尺寸 */
205
  .ppt-content {
206
  width: 100% !important;
207
  height: 100% !important;
@@ -271,42 +271,69 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
271
  height: ${pptDimensions.height}
272
  };
273
 
274
- console.log('PPT页面初始化 - 自适应填充模式:', window.PPT_DIMENSIONS);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
 
276
- // PPT内容自适应窗口尺寸函数
277
  function adaptPPTToWindow() {
278
  const container = document.getElementById('slideContainer');
279
  const content = document.getElementById('pptContent');
280
  if (!container || !content) return;
281
 
282
- const windowWidth = window.innerWidth;
283
- const windowHeight = window.innerHeight;
284
  const pptWidth = ${pptDimensions.width};
285
  const pptHeight = ${pptDimensions.height};
286
 
287
- // 计算缩放比例
288
- const scaleX = windowWidth / pptWidth;
289
- const scaleY = windowHeight / pptHeight;
290
 
291
- // 使用较大的缩放比例,确保PPT内容完全填满窗口
292
- const scale = Math.max(scaleX, scaleY);
 
293
 
294
- // 应用缩放变换到PPT内容
295
- content.style.transform = \`scale(\${scale})\`;
 
 
296
  content.style.width = pptWidth + 'px';
297
  content.style.height = pptHeight + 'px';
298
-
299
- // 计算居中偏移
300
- const scaledWidth = pptWidth * scale;
301
- const scaledHeight = pptHeight * scale;
302
- const offsetX = (windowWidth - scaledWidth) / 2;
303
- const offsetY = (windowHeight - scaledHeight) / 2;
304
-
305
- content.style.left = offsetX + 'px';
306
- content.style.top = offsetY + 'px';
307
  content.style.position = 'absolute';
 
 
308
 
309
- console.log(\`自适应缩放: 窗口(\${windowWidth}x\${windowHeight}) PPT(\${pptWidth}x\${pptHeight}) 缩放(\${scale.toFixed(3)}) 偏移(\${offsetX.toFixed(1)}, \${offsetY.toFixed(1)})\`);
 
310
  }
311
 
312
  // 页面加载完成后初始化
@@ -316,7 +343,7 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
316
  const container = document.getElementById('slideContainer');
317
  const content = document.getElementById('pptContent');
318
 
319
- console.log('页面加载完成,开始自适应缩放');
320
 
321
  // 确保页面元素填满窗口
322
  html.style.width = '100vw';
@@ -332,18 +359,11 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
332
  body.style.overflow = 'hidden';
333
  body.style.margin = '0';
334
  body.style.padding = '0';
 
 
 
335
 
336
- // 确保容器填满窗口
337
- if (container) {
338
- container.style.width = '100vw';
339
- container.style.height = '100vh';
340
- container.style.position = 'fixed';
341
- container.style.top = '0';
342
- container.style.left = '0';
343
- container.style.overflow = 'hidden';
344
- }
345
-
346
- // 执行自适应缩放
347
  adaptPPTToWindow();
348
 
349
  // 禁用各种用户交互
@@ -377,18 +397,18 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
377
  }
378
  }, { passive: false });
379
 
380
- console.log('自适应PPT页面初始化完成');
381
  });
382
 
383
- // 监听窗口大小变化,实时调整PPT大小
384
  window.addEventListener('resize', function() {
385
- console.log('窗口大小变化,重新自适应PPT尺寸');
386
  adaptPPTToWindow();
387
  });
388
 
389
  // 监听屏幕方向变化(移动设备)
390
  window.addEventListener('orientationchange', function() {
391
- console.log('屏幕方向变化,重新自适应PPT尺寸');
392
  setTimeout(adaptPPTToWindow, 100);
393
  });
394
  </script>
 
178
  left: 0 !important;
179
  }
180
 
181
+ /* Body - 填满整个窗口,黑色背景,居中显示容器 */
182
  body {
183
  width: 100vw !important;
184
  height: 100vh !important;
 
188
  position: fixed !important;
189
  top: 0 !important;
190
  left: 0 !important;
191
+ display: flex !important;
192
+ align-items: center !important;
193
+ justify-content: center !important;
194
  }
195
 
196
+ /* PPT容器 - 保持PPT长宽比,最大化填满窗口 */
197
  .slide-container {
 
 
198
  background-color: ${slide.background?.color || theme.backgroundColor || '#ffffff'} !important;
199
+ position: relative !important;
 
 
200
  overflow: hidden !important;
201
+ /* 尺寸将通过JavaScript动态设置 */
202
  }
203
 
204
+ /* PPT内容区域 - 完全填满容器 */
205
  .ppt-content {
206
  width: 100% !important;
207
  height: 100% !important;
 
271
  height: ${pptDimensions.height}
272
  };
273
 
274
+ console.log('PPT页面初始化 - 长宽比匹配模式:', window.PPT_DIMENSIONS);
275
+
276
+ // 计算容器尺寸,保持PPT长宽比,最大化填满窗口
277
+ function calculateContainerSize() {
278
+ const windowWidth = window.innerWidth;
279
+ const windowHeight = window.innerHeight;
280
+ const pptWidth = ${pptDimensions.width};
281
+ const pptHeight = ${pptDimensions.height};
282
+
283
+ // PPT的长宽比
284
+ const pptAspectRatio = pptWidth / pptHeight;
285
+ // 窗口的长宽比
286
+ const windowAspectRatio = windowWidth / windowHeight;
287
+
288
+ let containerWidth, containerHeight;
289
+
290
+ if (windowAspectRatio > pptAspectRatio) {
291
+ // 窗口比PPT更宽,以高度为准
292
+ containerHeight = windowHeight;
293
+ containerWidth = containerHeight * pptAspectRatio;
294
+ } else {
295
+ // 窗口比PPT更高,以宽度为准
296
+ containerWidth = windowWidth;
297
+ containerHeight = containerWidth / pptAspectRatio;
298
+ }
299
+
300
+ return {
301
+ width: Math.floor(containerWidth),
302
+ height: Math.floor(containerHeight)
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
  // 页面加载完成后初始化
 
343
  const container = document.getElementById('slideContainer');
344
  const content = document.getElementById('pptContent');
345
 
346
+ console.log('页面加载完成,开始长宽比匹配布局');
347
 
348
  // 确保页面元素填满窗口
349
  html.style.width = '100vw';
 
359
  body.style.overflow = 'hidden';
360
  body.style.margin = '0';
361
  body.style.padding = '0';
362
+ body.style.display = 'flex';
363
+ body.style.alignItems = 'center';
364
+ body.style.justifyContent = 'center';
365
 
366
+ // 执行自适应布局
 
 
 
 
 
 
 
 
 
 
367
  adaptPPTToWindow();
368
 
369
  // 禁用各种用户交互
 
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>