index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <div class="panocon">
  3. <div v-show="currentScene.type !== '4dkk'" id="pano">
  4. </div>
  5. <iframe
  6. id="iframe-4dkk"
  7. width=""
  8. v-if="currentScene.type === '4dkk'"
  9. :src="`${locationOrigin}/sp${currentScene.version === 'V3' ? 'c' : currentScene.version === 'V4' ? 'g' : ''}.html?m=${currentScene.sceneCode}&lang=${lang}`"
  10. frameborder="0"
  11. />
  12. <div class="showexplanation" v-if="showExplanation&&currentScene.explanation && currentScene.explanation.audioId">
  13. <img :src="require(`@/assets/images/commentary@2x.png`)" alt="">
  14. </div>
  15. <list></list>
  16. <template v-if="showSnapshot && currentScene&&currentScene.type !=='4dkk'">
  17. <snapshot :showFlash="showFlash"></snapshot>
  18. <button class="ui-button submit set-initial-view" :class="{disable: currentScene.type === '4dkk',}" @click="onClick">{{$i18n.t('screen.setting_screen')}}</button>
  19. </template>
  20. </div>
  21. </template>
  22. <script>
  23. import list from "./components/list";
  24. import { mapGetters } from "vuex";
  25. import * as krfn from "@/core/index.js";
  26. import { $waiting } from "@/components/shared/loading";
  27. import Snapshot from "@/components/Snapshot";
  28. import {
  29. uploadCover,
  30. searchInAll3DScenes,
  31. } from "@/api";
  32. import config from '@/config'
  33. let __krfn = krfn.default;
  34. export default {
  35. components: { list, Snapshot },
  36. data() {
  37. return {
  38. showFlash: false,
  39. inter: null,
  40. lang: config.lang || 'zh',
  41. locationOrigin: process.env.VUE_APP_PROXY_URL_ROOT,
  42. }
  43. },
  44. computed: {
  45. ...mapGetters({
  46. currentScene: "scene/currentScene",
  47. info: "info",
  48. isConfirmingPosi: "tags/isConfirmingPosi",
  49. }),
  50. showSnapshot() {
  51. return this.$route.name == "screen";
  52. },
  53. showExplanation() {
  54. return this.$route.name == "explanation";
  55. },
  56. },
  57. watch: {
  58. '$route.name': function (newVal) {
  59. __krfn.utils.toggleHotspot(this.$getKrpano(), newVal == 'hotspot');
  60. },
  61. currentScene(newVal) {
  62. if (newVal) {
  63. this.$nextTick(() => {
  64. this.$bus.emit("initView", newVal.icon);
  65. })
  66. }
  67. if (newVal.type == '4dkk') {
  68. $("#pano").empty();
  69. if (!newVal.version) { // v1.3之前在作品中新增的三维场景,没有version这个值,需要查询。
  70. searchInAll3DScenes({
  71. searchKey: newVal.sceneTitle,
  72. }, (res) => {
  73. const originItem = res.data.list.find((item) => {
  74. return item.num === newVal.sceneCode
  75. })
  76. newVal.version = originItem.buildType
  77. })
  78. }
  79. return
  80. } else {
  81. $("#pano").empty();
  82. window.vrInitFn = () => {
  83. $waiting.hide()
  84. __krfn.utils.initHotspot(this.$getKrpano(), newVal && newVal.someData, true);
  85. __krfn.utils.toggleHotspot(this.$getKrpano(), this.$route.name == "hotspot");
  86. };
  87. window.vrViewFn = () => {
  88. try {
  89. let tmp = newVal.initVisual;
  90. this.$getKrpano().set("view.vlookat", tmp.vlookat);
  91. this.$getKrpano().set("view.hlookat", tmp.hlookat);
  92. } catch (error) {
  93. error;
  94. }
  95. };
  96. var settings = {
  97. "events[skin_events].onxmlcomplete": "js(window.vrViewFn());",
  98. "events[skin_events].onloadcomplete": "js(window.vrInitFn());",
  99. };
  100. if (newVal) {
  101. removepano("#pano");
  102. $waiting.show();
  103. embedpano({
  104. // http://oss-xiaoan.oss-cn-shenzhen.aliyuncs.com/720yun_fd_manage/fd720_Va0LrkXW3/vtour/tour.xml
  105. // xml: "%HTMLPATH%/static/template/tour.xml",
  106. xml: `${this.$cdn}/720yun_fd_manage/${newVal.sceneCode}/vtour/tour.xml`,
  107. swf: "%HTMLPATH%/static/template/tour.swf",
  108. target: "pano",
  109. html5: "auto",
  110. mobilescale: 1,
  111. vars: settings,
  112. webglsettings: { preserveDrawingBuffer: true },
  113. passQueryParameters: true,
  114. });
  115. }
  116. }
  117. var settings = {
  118. "events[skin_events].onxmlcomplete": "js(window.vrViewFn());",
  119. "events[skin_events].onloadcomplete": "js(window.vrInitFn());",
  120. };
  121. if (newVal) {
  122. removepano("#pano");
  123. $waiting.show();
  124. embedpano({
  125. // http://ossxiaoan.4dage.com/720yun_fd_manage/fd720_Va0LrkXW3/vtour/tour.xml
  126. // xml: "%HTMLPATH%/static/template/tour.xml",
  127. xml: `${this.$cdn}/720yun_fd_manage/${newVal.sceneCode}/vtour/tour.xml`,
  128. swf: "%HTMLPATH%/static/template/tour.swf",
  129. target: "pano",
  130. html5: "auto",
  131. mobilescale: 1,
  132. vars: settings,
  133. webglsettings: { preserveDrawingBuffer: true },
  134. passQueryParameters: true,
  135. });
  136. }
  137. },
  138. isConfirmingPosi(newVal) {
  139. this.inter && clearInterval(this.inter)
  140. this.inter = null
  141. console.log(newVal,'isConfirmingPosiisConfirmingPosi');
  142. if (newVal) {
  143. this.inter = setInterval(() => {
  144. __krfn.utils.getCurrentMousePosition(this.$getKrpano(), newVal)
  145. }, 20);
  146. } else {
  147. this.$bus.emit('resethotspotTitle', '')
  148. }
  149. }
  150. },
  151. methods: {
  152. updateInfo() {
  153. let iidx = this.info.scenes.findIndex(item => this.currentScene.sceneCode == item.sceneCode)
  154. if (iidx > -1) {
  155. this.info.scenes[iidx] = {
  156. ...this.currentScene
  157. }
  158. }
  159. this.$store.commit("SetInfo", this.info);
  160. },
  161. onClick() {
  162. this.$bus.emit('toggleFlash', true)
  163. let canvas = $("#krpanoSWFObject canvas")[0];
  164. let data = __krfn.utils.setInitView(this.$getKrpano(), canvas);
  165. uploadCover(
  166. { file: data.url, filename: "initCover.jpg" },
  167. res => {
  168. if (res.code == 0) {
  169. this.currentScene.icon = res.data
  170. this.currentScene.initVisual = {
  171. hlookat: data.hlookat,
  172. vlookat: data.vlookat
  173. }
  174. this.$bus.emit('toggleFlash', false)
  175. this.$bus.emit("initView", res.data);
  176. this.updateInfo()
  177. this.$msg.success(this.$i18n.t("gather.setting_success"))
  178. this.$store.commit("SetInfo", this.info);
  179. }
  180. });
  181. },
  182. addhotspot(param) {
  183. __krfn.utils.addhotspot(this.$getKrpano(), param, true);
  184. this.$store.commit("tags/setIsConfirmingPosi", param.name);
  185. },
  186. },
  187. mounted() {
  188. window.__krfn = __krfn;
  189. this.$bus.on("addhotspot", data => {
  190. this.addhotspot(data);
  191. });
  192. this.$bus.on("openHotspot", (data) => {
  193. if (this.isConfirmingPosi) {
  194. this.$store.commit("tags/setIsConfirmingPosi", false);
  195. }
  196. })
  197. },
  198. };
  199. </script>
  200. <style lang="less" scoped>
  201. .panocon {
  202. width: 100%;
  203. height: 100%;
  204. position: relative;
  205. overflow: hidden;
  206. #pano {
  207. width: 100%;
  208. height: 100%;
  209. }
  210. #iframe-4dkk {
  211. width: 100%;
  212. height: 100%;
  213. }
  214. .showexplanation {
  215. position: absolute;
  216. top: 20px;
  217. z-index: 999;
  218. right: 20px;
  219. width: 35px;
  220. height: 35px;
  221. background: rgba(0, 0, 0, 0.4);
  222. border-radius: 50%;
  223. border: 1px solid rgba(255, 255, 255, 0.2);
  224. backdrop-filter: blur(6px);
  225. >img {
  226. width: 100%;
  227. height: 100%;
  228. }
  229. }
  230. button.set-initial-view {
  231. position: absolute;
  232. bottom: 260px;
  233. min-width: 200px;
  234. left: 50%;
  235. transform: translateX(-50%);
  236. z-index: 99;
  237. }
  238. }
  239. </style>