H5GamesPreview.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="imageText-preview" :style="getAreaStyle()">
  4. <SerialNumberPosition v-if="isEnable(data.property.sn_display_mode)" :property="data.property" />
  5. <div ref="fullscreenElement">
  6. <el-button
  7. type="primary"
  8. :class="[full_type ? 'exit-btn' : '']"
  9. style="margin-bottom: 10px"
  10. :style="{
  11. background:
  12. data.unified_attrib && data.unified_attrib.topic_color ? data.unified_attrib.topic_color : '#165dff',
  13. borderColor:
  14. data.unified_attrib && data.unified_attrib.topic_color ? data.unified_attrib.topic_color : '#165dff',
  15. }"
  16. @click="toggleFullScreen"
  17. >{{ full_type ? '退出全屏' : '进入全屏' }}</el-button
  18. >
  19. <iframe :src="games_url" width="100%" :height="full_type ? '100%' : '580px'" style="border: none"></iframe>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. import PreviewMixin from '../common/PreviewMixin';
  25. import { getH5GamesData } from '@/views/book/courseware/data/h5Games';
  26. import { H5StartupFile } from '@/api/app';
  27. export default {
  28. name: 'H5GamesPreview',
  29. components: {},
  30. mixins: [PreviewMixin],
  31. data() {
  32. return {
  33. data: getH5GamesData(),
  34. games_url: '',
  35. full_type: false,
  36. };
  37. },
  38. watch: {
  39. 'data.file_list.length': {
  40. handler() {
  41. this.initData();
  42. },
  43. },
  44. },
  45. created() {
  46. this.initData();
  47. },
  48. mounted() {},
  49. methods: {
  50. initData() {
  51. this.data.file_list.forEach((item) => {
  52. const suffix = item.file_name.slice(item.file_name.lastIndexOf('.') + 1, item.file_name.length).toLowerCase();
  53. if (suffix === 'html') {
  54. this.games_url = item.file_url;
  55. } else {
  56. H5StartupFile({ file_id: item.file_id, index_file_name: 'index.html' }).then((res) => {
  57. this.games_url = res.file_url;
  58. });
  59. }
  60. });
  61. },
  62. toggleFullScreen() {
  63. const elem = this.$refs.fullscreenElement; // 获取需要全屏的元素
  64. if (!document.fullscreenElement) {
  65. this.full_type = true;
  66. if (elem.requestFullscreen) {
  67. elem.requestFullscreen(); // 现代浏览器,如Chrome, Firefox, Opera, Safari等
  68. } else if (elem.mozRequestFullScreen) {
  69. // Firefox
  70. elem.mozRequestFullScreen();
  71. } else if (elem.webkitRequestFullscreen) {
  72. // Chrome, Safari等
  73. elem.webkitRequestFullscreen();
  74. } else if (elem.msRequestFullscreen) {
  75. // IE/Edge
  76. elem.msRequestFullscreen();
  77. }
  78. } else {
  79. this.full_type = false;
  80. if (document.exitFullscreen) {
  81. document.exitFullscreen(); // 退出全屏模式
  82. } else if (document.mozCancelFullScreen) {
  83. // Firefox
  84. document.mozCancelFullScreen();
  85. } else if (document.webkitExitFullscreen) {
  86. // Chrome, Safari等
  87. document.webkitExitFullscreen();
  88. } else if (document.msExitFullscreen) {
  89. // IE/Edge
  90. document.msExitFullscreen();
  91. }
  92. }
  93. },
  94. },
  95. };
  96. </script>
  97. <style lang="scss" scoped>
  98. @use '@/styles/mixin.scss' as *;
  99. .exit-btn {
  100. position: fixed;
  101. top: 10px;
  102. left: 10px;
  103. }
  104. </style>