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

Upload public.js

Browse files
Files changed (1) hide show
  1. backend/src/routes/public.js +55 -44
backend/src/routes/public.js CHANGED
@@ -167,7 +167,7 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
167
  box-sizing: border-box !important;
168
  }
169
 
170
- /* HTML - 填满整个窗口 */
171
  html {
172
  width: 100vw !important;
173
  height: 100vh !important;
@@ -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,19 +188,25 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
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容器 - 响应式缩放,保持宽高比,填满窗口 */
197
  .slide-container {
198
- width: ${pptDimensions.width}px !important;
199
- height: ${pptDimensions.height}px !important;
200
  background-color: ${slide.background?.color || theme.backgroundColor || '#ffffff'} !important;
201
- position: relative !important;
 
 
202
  overflow: hidden !important;
203
- transform-origin: center center !important;
 
 
 
 
 
 
 
204
  }
205
 
206
  /* 背景图片处理 */
@@ -213,7 +219,7 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
213
  width: 100% !important;
214
  height: 100% !important;
215
  background-image: url('${slide.background.image}') !important;
216
- background-size: ${slide.background.imageSize || 'cover'} !important;
217
  background-position: center !important;
218
  background-repeat: no-repeat !important;
219
  z-index: 0 !important;
@@ -253,7 +259,9 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
253
  </head>
254
  <body>
255
  <div class="slide-container" id="slideContainer">
256
- ${renderElements(slide.elements)}
 
 
257
  </div>
258
 
259
  <script>
@@ -263,40 +271,42 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
263
  height: ${pptDimensions.height}
264
  };
265
 
266
- console.log('PPT页面初始化 - 响应式填充模式:', window.PPT_DIMENSIONS);
267
 
268
- // 响应式缩放函数 - PPT内容自动填满窗口
269
- function resizePPTToFitWindow() {
270
  const container = document.getElementById('slideContainer');
271
- if (!container) return;
 
272
 
273
  const windowWidth = window.innerWidth;
274
  const windowHeight = window.innerHeight;
275
  const pptWidth = ${pptDimensions.width};
276
  const pptHeight = ${pptDimensions.height};
277
 
278
- // 计算缩放比例,使PPT完全填满窗口
279
  const scaleX = windowWidth / pptWidth;
280
  const scaleY = windowHeight / pptHeight;
281
 
282
- // 使用较大的缩放比例,确保PPT内容填满窗口(可能会有部分内容被裁切)
283
  const scale = Math.max(scaleX, scaleY);
284
 
285
- // 应用缩放变换
286
- container.style.transform = \`scale(\${scale})\`;
 
 
287
 
288
- // 如果需要居中显示(当一个方向填满,另一个方向可能会超出)
289
  const scaledWidth = pptWidth * scale;
290
  const scaledHeight = pptHeight * scale;
 
 
291
 
292
- // 计算偏移,使内容居中
293
- const offsetX = (windowWidth - scaledWidth) / 2 / scale;
294
- const offsetY = (windowHeight - scaledHeight) / 2 / scale;
295
-
296
- container.style.left = offsetX + 'px';
297
- container.style.top = offsetY + 'px';
298
 
299
- console.log(\`窗口尺寸: \${windowWidth}x\${windowHeight}, PPT尺寸: \${pptWidth}x\${pptHeight}, 缩放比例: \${scale.toFixed(3)}, 偏移: \${offsetX.toFixed(1)}, \${offsetY.toFixed(1)}\`);
300
  }
301
 
302
  // 页面加载完成后初始化
@@ -304,36 +314,37 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
304
  const html = document.documentElement;
305
  const body = document.body;
306
  const container = document.getElementById('slideContainer');
 
307
 
308
- console.log('页面加载完成,开始响应式缩放');
309
 
310
  // 确保页面元素填满窗口
311
  html.style.width = '100vw';
312
  html.style.height = '100vh';
313
  html.style.background = '#000000';
314
  html.style.overflow = 'hidden';
 
 
315
 
316
  body.style.width = '100vw';
317
  body.style.height = '100vh';
318
  body.style.background = '#000000';
319
  body.style.overflow = 'hidden';
320
- body.style.display = 'flex';
321
- body.style.alignItems = 'center';
322
- body.style.justifyContent = 'center';
323
  body.style.margin = '0';
324
  body.style.padding = '0';
325
 
326
- // 初始化PPT容器
327
  if (container) {
328
- container.style.width = '${pptDimensions.width}px';
329
- container.style.height = '${pptDimensions.height}px';
330
- container.style.position = 'relative';
 
 
331
  container.style.overflow = 'hidden';
332
- container.style.transformOrigin = 'center center';
333
  }
334
 
335
- // 执行初始缩放
336
- resizePPTToFitWindow();
337
 
338
  // 禁用各种用户交互
339
  document.addEventListener('wheel', function(e) {
@@ -366,19 +377,19 @@ const generateSlideHTML = (pptData, slideIndex, title) => {
366
  }
367
  }, { passive: false });
368
 
369
- console.log('响应式PPT页面初始化完成');
370
  });
371
 
372
  // 监听窗口大小变化,实时调整PPT大小
373
  window.addEventListener('resize', function() {
374
- console.log('窗口大小变化,重新调整PPT尺寸');
375
- resizePPTToFitWindow();
376
  });
377
 
378
  // 监听屏幕方向变化(移动设备)
379
  window.addEventListener('orientationchange', function() {
380
- console.log('屏幕方向变化,重新调整PPT尺寸');
381
- setTimeout(resizePPTToFitWindow, 100); // 延迟一点时间等待方向变化完成
382
  });
383
  </script>
384
  </body>
 
167
  box-sizing: border-box !important;
168
  }
169
 
170
+ /* HTML - 填满整个窗口,黑色背景 */
171
  html {
172
  width: 100vw !important;
173
  height: 100vh !important;
 
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
  }
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;
208
+ position: relative !important;
209
+ transform-origin: top left !important;
210
  }
211
 
212
  /* 背景图片处理 */
 
219
  width: 100% !important;
220
  height: 100% !important;
221
  background-image: url('${slide.background.image}') !important;
222
+ background-size: cover !important;
223
  background-position: center !important;
224
  background-repeat: no-repeat !important;
225
  z-index: 0 !important;
 
259
  </head>
260
  <body>
261
  <div class="slide-container" id="slideContainer">
262
+ <div class="ppt-content" id="pptContent">
263
+ ${renderElements(slide.elements)}
264
+ </div>
265
  </div>
266
 
267
  <script>
 
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
  // 页面加载完成后初始化
 
314
  const html = document.documentElement;
315
  const body = document.body;
316
  const container = document.getElementById('slideContainer');
317
+ const content = document.getElementById('pptContent');
318
 
319
+ console.log('页面加载完成,开始自适应缩放');
320
 
321
  // 确保页面元素填满窗口
322
  html.style.width = '100vw';
323
  html.style.height = '100vh';
324
  html.style.background = '#000000';
325
  html.style.overflow = 'hidden';
326
+ html.style.margin = '0';
327
+ html.style.padding = '0';
328
 
329
  body.style.width = '100vw';
330
  body.style.height = '100vh';
331
  body.style.background = '#000000';
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
  // 禁用各种用户交互
350
  document.addEventListener('wheel', function(e) {
 
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>
395
  </body>