ScreenSlide.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <!-- {
  3. width: viewportSize + 'px',
  4. height: viewportSize * viewportRatio + 'px',
  5. transform: `scale(${iframeScale})`,
  6. } -->
  7. <div
  8. class="screen-slide"
  9. :style="iframeScale"
  10. >
  11. <div class="background" :style="{ ...backgroundStyle }"></div>
  12. <ScreenElement
  13. v-for="(element, index) in slide.elements"
  14. :key="element.id"
  15. :elementInfo="element"
  16. :elementIndex="index + 1"
  17. :animationIndex="animationIndex"
  18. :turnSlideToId="turnSlideToId"
  19. :manualExitFullscreen="manualExitFullscreen"
  20. :is-visible="isVisible"
  21. />
  22. </div>
  23. </template>
  24. <script lang="ts" setup>
  25. import { computed, provide } from 'vue'
  26. import { storeToRefs } from 'pinia'
  27. import { useSlidesStore } from '@/store'
  28. import { ElementTypes, type Slide } from '@/types/slides'
  29. import { injectKeySlideId } from '@/types/injectKey'
  30. import useSlideBackgroundStyle from '@/hooks/useSlideBackgroundStyle'
  31. import ScreenElement from './ScreenElement.vue'
  32. const props = defineProps<{
  33. slide: Slide
  34. scale: number
  35. animationIndex: number
  36. turnSlideToId: (id: string) => void
  37. manualExitFullscreen: () => void
  38. isVisible: boolean
  39. }>()
  40. const { viewportRatio, viewportSize } = storeToRefs(useSlidesStore())
  41. const background = computed(() => props.slide.background)
  42. const { backgroundStyle } = useSlideBackgroundStyle(background)
  43. const slideId = computed(() => props.slide.id)
  44. provide(injectKeySlideId, slideId)
  45. // 判断是否包含指定类型的iframe界面
  46. const hasIframe = computed(() => {
  47. return props.slide.elements.some(element =>
  48. element.type === ElementTypes.FRAME &&
  49. [72, 73, 75, 76].includes(element.toolType as number)
  50. )
  51. })
  52. // 计算scale:如果是iframe界面且scale大于1就按1,否则按原scale
  53. const iframeScale = computed(() => {
  54. if (hasIframe.value) {
  55. // return Math.min(props.scale, 1)
  56. //return props.scale;
  57. return {
  58. width: '100%',
  59. height: '100%',
  60. transform: `scale(1)`,
  61. }
  62. }
  63. return {
  64. width: viewportSize + 'px',
  65. height: viewportSize * viewportRatio + 'px',
  66. transform: `scale(${props.scale})`,
  67. }
  68. })
  69. </script>
  70. <style lang="scss" scoped>
  71. .screen-slide {
  72. position: absolute;
  73. top: 0;
  74. left: 0;
  75. transform-origin: 0 0;
  76. overflow: hidden;
  77. }
  78. .background {
  79. width: 100%;
  80. height: 100%;
  81. background-position: center;
  82. position: absolute;
  83. }
  84. </style>