iframe.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div class="ifrcon">
  3. <vvheader
  4. :somedatainfo="somedatainfo"
  5. :bgmstatus="bgmstatus"
  6. :params="params"
  7. class="hhh"
  8. />
  9. <iframe
  10. allow="autoplay"
  11. allowfullscreen="true"
  12. ref="iframe"
  13. id="showifr"
  14. :src="url"
  15. frameborder="0"
  16. @load="onIframLoad"
  17. ></iframe>
  18. </div>
  19. </template>
  20. <script>
  21. import browser from "@/utils/browser";
  22. import vvheader from "./vheader.vue";
  23. import { useStore } from "vuex";
  24. import { getApp } from "@/app";
  25. export default {
  26. props: ["url", "bgmUrl", "somedatainfo"],
  27. components: { vvheader },
  28. data() {
  29. return {
  30. store: useStore(),
  31. params: "",
  32. bgmstatus: false,
  33. };
  34. },
  35. computed: {
  36. tempBgm() {
  37. return this.bgmUrl;
  38. },
  39. },
  40. methods: {
  41. onIframLoad() {
  42. window.onmessage = (e) => {
  43. if (e.data.source != "4dage") {
  44. return;
  45. }
  46. console.log(e.data, "e.data.params");
  47. getApp().Scene.emit("ready");
  48. if (e.data.event == "guide-stop") {
  49. this.store.commit("fdkk/setV3ToursStatus", false);
  50. }
  51. if (e.data.event == "guide-rooms") {
  52. this.store.commit("fdkk/setToursList", e.data.params);
  53. }
  54. if (e.data.event == "link-click") {
  55. if (
  56. e.data.params.url.indexOf(
  57. `https://${window.location.hostname}/spc.html?`
  58. ) > -1 ||
  59. e.data.params.url.indexOf(
  60. `https://${window.location.hostname}/smobile.html?`
  61. ) > -1
  62. ) {
  63. let m = browser.urlHasValueFromUrl("m", e.data.params.url);
  64. this.$emit("changeUrl", m);
  65. } else {
  66. this.$emit("otherUrl", e.data.params.url);
  67. }
  68. }
  69. if (e.data.event == "action") {
  70. // this.$bus.emit("currentMode", e.data.params);
  71. if (e.data.params.type == "playMusic") {
  72. this.bgmstatus = e.data.params.data.status;
  73. // this.store.dispatch('audio/initV3BGM',this.bgmstatus);
  74. console.log("V3-BGM-status", this.bgmstatus);
  75. this.store.dispatch(
  76. "audio/updateV3BGMStatus",
  77. e.data.params.data.status
  78. );
  79. // this.store.commit('fdkk/setV3BGMStatus', e.data.params.data.status)
  80. }
  81. if (e.data.params.type == "mode") {
  82. if (e.data.params.data.mode != "pano") {
  83. this.store.commit("functions/setShowScenesList", false);
  84. }
  85. }
  86. // store.commit('fdkk/setIsPlayTours', params.isPlay)
  87. }
  88. // if (e.data.event == "settings") {
  89. // this.store.commit('fdkk/setV3BGMStatus', e.data.params.status)
  90. // }
  91. if (e.data.event == "loaded") {
  92. console.log(e.data.params, "e.data.params");
  93. this.params = e.data.params;
  94. this.$refs.iframe.contentWindow.postMessage(
  95. {
  96. source: "mingyuan",
  97. event: "guide-rooms",
  98. },
  99. "*"
  100. );
  101. this.$refs.iframe.contentWindow.postMessage(
  102. {
  103. source: "mingyuan",
  104. event: "settings",
  105. params: {
  106. playMusic: true,
  107. },
  108. },
  109. "*"
  110. );
  111. }
  112. };
  113. },
  114. handleBGM(status) {
  115. this.$refs.iframe.contentWindow.postMessage(
  116. {
  117. source: "mingyuan",
  118. event: "settings",
  119. params: {
  120. playMusic: status,
  121. },
  122. },
  123. "*"
  124. );
  125. },
  126. },
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. .ifrcon {
  131. width: 100%;
  132. height: 100%;
  133. position: relative;
  134. > iframe {
  135. width: 100%;
  136. height: 100%;
  137. }
  138. .hhh {
  139. position: absolute;
  140. left: 50%;
  141. transform: translate(-50%);
  142. z-index: 999;
  143. top: 10px;
  144. }
  145. }
  146. </style>