index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div class="panocon">
  3. <div id="pano"></div>
  4. <div class="showexplanation" v-if="showExplanation&&currentScene.explanation && currentScene.explanation.audioId">
  5. <img :src="require(`@/assets/images/commentary@2x.png`)" alt="">
  6. </div>
  7. <list></list>
  8. <template v-if="showSnapshot && currentScene">
  9. <snapshot :showFlash="showFlash"></snapshot>
  10. <button class="ui-button submit" @click="onClick">将当前视角设为初始画面</button>
  11. </template>
  12. </div>
  13. </template>
  14. <script>
  15. import list from "./components/list";
  16. import { mapGetters } from "vuex";
  17. import * as krfn from "@/core/index.js";
  18. import { $waiting } from "@/components/shared/loading";
  19. import Snapshot from "@/components/Snapshot";
  20. import { uploadCover } from "@/api";
  21. let __krfn = krfn.default;
  22. export default {
  23. components: { list, Snapshot },
  24. data() {
  25. return {
  26. showFlash: false,
  27. inter: null
  28. }
  29. },
  30. computed: {
  31. ...mapGetters({
  32. currentScene: "scene/currentScene",
  33. info: "info",
  34. isConfirmingPosi: "tags/isConfirmingPosi",
  35. }),
  36. showSnapshot() {
  37. return this.$route.name == "screen";
  38. },
  39. showExplanation() {
  40. return this.$route.name == "explanation";
  41. },
  42. },
  43. watch: {
  44. '$route.name': function (newVal) {
  45. __krfn.utils.toggleHotspot(this.$getKrpano(), newVal == 'hotspot');
  46. },
  47. currentScene(newVal) {
  48. if (newVal) {
  49. this.$nextTick(() => {
  50. this.$bus.emit("initView", newVal.icon);
  51. })
  52. }
  53. if (newVal.type == '4dkk') {
  54. return
  55. }
  56. $("#pano").empty();
  57. window.vrInitFn = () => {
  58. $waiting.hide()
  59. __krfn.utils.initHotspot(this.$getKrpano(), newVal && newVal.someData, true);
  60. __krfn.utils.toggleHotspot(this.$getKrpano(), this.$route.name == "hotspot");
  61. };
  62. window.vrViewFn = () => {
  63. try {
  64. let tmp = newVal.initVisual;
  65. this.$getKrpano().set("view.vlookat", tmp.vlookat);
  66. this.$getKrpano().set("view.hlookat", tmp.hlookat);
  67. } catch (error) {
  68. error;
  69. }
  70. };
  71. var settings = {
  72. "events[skin_events].onxmlcomplete": "js(window.vrViewFn());",
  73. "events[skin_events].onloadcomplete": "js(window.vrInitFn());",
  74. };
  75. if (newVal) {
  76. removepano("#pano");
  77. $waiting.show();
  78. embedpano({
  79. // http://ossxiaoan.4dage.com/720yun_fd_manage/fd720_Va0LrkXW3/vtour/tour.xml
  80. // xml: "%HTMLPATH%/static/template/tour.xml",
  81. xml: `${this.$cdn}/720yun_fd_manage/${newVal.sceneCode}/vtour/tour.xml`,
  82. swf: "%HTMLPATH%/static/template/tour.swf",
  83. target: "pano",
  84. html5: "auto",
  85. mobilescale: 1,
  86. vars: settings,
  87. webglsettings: { preserveDrawingBuffer: true },
  88. passQueryParameters: true,
  89. });
  90. }
  91. },
  92. isConfirmingPosi(newVal) {
  93. this.inter && clearInterval(this.inter)
  94. this.inter = null
  95. console.log(newVal,'isConfirmingPosiisConfirmingPosi');
  96. if (newVal) {
  97. this.inter = setInterval(() => {
  98. __krfn.utils.getCurrentMousePosition(this.$getKrpano(), newVal)
  99. }, 20);
  100. } else {
  101. this.$bus.emit('resethotspotTitle', '')
  102. }
  103. }
  104. },
  105. methods: {
  106. updateInfo() {
  107. let iidx = this.info.scenes.findIndex(item => this.currentScene.sceneCode == item.sceneCode)
  108. if (iidx > -1) {
  109. this.info.scenes[iidx] = {
  110. ...this.currentScene
  111. }
  112. }
  113. this.$store.commit("SetInfo", this.info);
  114. },
  115. onClick() {
  116. this.$bus.emit('toggleFlash', true)
  117. let canvas = $("#krpanoSWFObject canvas")[0];
  118. let data = __krfn.utils.setInitView(this.$getKrpano(), canvas);
  119. uploadCover(
  120. { file: data.url, filename: "initCover.jpg" },
  121. res => {
  122. if (res.code == 0) {
  123. this.currentScene.icon = res.data
  124. this.currentScene.initVisual = {
  125. hlookat: data.hlookat,
  126. vlookat: data.vlookat
  127. }
  128. this.$bus.emit('toggleFlash', false)
  129. this.$bus.emit("initView", res.data);
  130. this.updateInfo()
  131. this.$msg.success("设置成功")
  132. this.$store.commit("SetInfo", this.info);
  133. }
  134. });
  135. },
  136. addhotspot(param) {
  137. __krfn.utils.addhotspot(this.$getKrpano(), param, true);
  138. this.$store.commit("tags/setIsConfirmingPosi", param.name);
  139. }
  140. },
  141. mounted() {
  142. window.__krfn = __krfn;
  143. this.$bus.on("addhotspot", data => {
  144. this.addhotspot(data);
  145. });
  146. this.$bus.on("openHotspot", (data) => {
  147. if (this.isConfirmingPosi) {
  148. this.$store.commit("tags/setIsConfirmingPosi", false);
  149. }
  150. })
  151. },
  152. };
  153. </script>
  154. <style lang="less" scoped>
  155. .panocon {
  156. width: 100%;
  157. height: 100%;
  158. position: relative;
  159. overflow: hidden;
  160. #pano {
  161. width: 100%;
  162. height: 100%;
  163. }
  164. .showexplanation {
  165. position: absolute;
  166. top: 20px;
  167. z-index: 999;
  168. right: 20px;
  169. width: 35px;
  170. height: 35px;
  171. background: rgba(0, 0, 0, 0.4);
  172. border-radius: 50%;
  173. border: 1px solid rgba(255, 255, 255, 0.2);
  174. backdrop-filter: blur(6px);
  175. >img {
  176. width: 100%;
  177. height: 100%;
  178. }
  179. }
  180. .ui-button {
  181. position: absolute;
  182. bottom: 260px;
  183. min-width: 200px;
  184. left: 50%;
  185. transform: translateX(-50%);
  186. z-index: 99;
  187. }
  188. }
  189. </style>