BaseFrameElement.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div class="base-element-frame"
  3. :style="{
  4. top: elementInfo.top + 'px',
  5. left: elementInfo.left + 'px',
  6. width: elementInfo.width + 'px',
  7. height: elementInfo.height + 'px',
  8. }"
  9. >
  10. <div
  11. class="rotate-wrapper"
  12. :style="{ transform: `rotate(${elementInfo.rotate}deg)` }"
  13. >
  14. <div class="element-content">
  15. <iframe
  16. :key="`html-${iframeKey}`"
  17. :srcdoc="elementInfo.url"
  18. v-if="elementInfo.isHTML"
  19. :width="elementInfo.width"
  20. :height="elementInfo.height"
  21. :frameborder="0"
  22. :allowfullscreen="true"
  23. allow="camera *; microphone *; display-capture; midi; encrypted-media; fullscreen; geolocation; clipboard-read; clipboard-write; accelerometer; autoplay; gyroscope; payment; picture-in-picture; usb; xr-spatial-tracking;"
  24. ></iframe>
  25. <iframe
  26. :key="`src-${iframeKey}`"
  27. v-else
  28. :src="elementInfo.url"
  29. :width="elementInfo.width"
  30. :height="elementInfo.height"
  31. :frameborder="0"
  32. :allowfullscreen="true"
  33. allow="camera *; microphone *; display-capture; midi; encrypted-media; fullscreen; geolocation; clipboard-read; clipboard-write; accelerometer; autoplay; gyroscope; payment; picture-in-picture; usb; xr-spatial-tracking;"
  34. ></iframe>
  35. <!-- 在放映模式下不显示遮罩层,允许用户与iframe交互 -->
  36. <div class="mask" v-if="false"></div>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script lang="ts" setup>
  42. import type { PropType } from 'vue'
  43. import type { PPTFrameElement } from '@/types/slides'
  44. import { ref, watch } from 'vue'
  45. const props = defineProps({
  46. elementInfo: {
  47. type: Object as PropType<PPTFrameElement>,
  48. required: true,
  49. },
  50. })
  51. // 用于强制刷新iframe的key
  52. const iframeKey = ref(0)
  53. // 监听elementInfo.url的变化
  54. watch(() => props.elementInfo.url, (newUrl, oldUrl) => {
  55. if (newUrl !== oldUrl) {
  56. // 通过改变key来强制刷新iframe
  57. iframeKey.value++
  58. }
  59. })
  60. </script>
  61. <style lang="scss" scoped>
  62. .base-element-frame {
  63. position: absolute;
  64. }
  65. .element-content {
  66. width: 100%;
  67. height: 100%;
  68. overflow: hidden;
  69. }
  70. .mask {
  71. position: absolute;
  72. top: 0;
  73. bottom: 0;
  74. left: 0;
  75. right: 0;
  76. }
  77. .rotate-wrapper {
  78. width: 100%;
  79. height: 100%;
  80. overflow: hidden;
  81. }
  82. </style>