index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <div class="panocon" :class="[routerName]">
  3. <div v-show="currentScene.type !== '4dkk'" id="pano"></div>
  4. <!-- 调试信息: {{ currentScene }} -->
  5. <iframe
  6. id="iframe-4dkk"
  7. :class="currentSceneVersion"
  8. width=""
  9. v-if="currentScene.type === '4dkk'"
  10. :src="`${locationOrigin}/sp${
  11. currentSceneVersion === 'V3'
  12. ? 'c'
  13. : currentSceneVersion === 'V4'
  14. ? 'g'
  15. : 'g'
  16. }.html?m=${currentScene.sceneCode}&lang=${lang}`"
  17. frameborder="0"
  18. />
  19. <div
  20. class="showexplanation"
  21. v-if="
  22. showExplanation &&
  23. currentScene.explanation &&
  24. currentScene.explanation.audioId
  25. "
  26. >
  27. <img :src="require(`@/assets/images/commentary@2x.png`)" alt="" />
  28. </div>
  29. <list></list>
  30. <template
  31. v-if="showSnapshot && currentScene && currentScene.type !== '4dkk'"
  32. >
  33. <snapshot :showFlash="showFlash"></snapshot>
  34. <button
  35. class="ui-button submit set-initial-view"
  36. :class="{ disable: currentScene.type === '4dkk' }"
  37. @click="onClick"
  38. >
  39. {{ $i18n.t("screen.setting_screen") }}
  40. </button>
  41. </template>
  42. </div>
  43. </template>
  44. <script>
  45. import list from "./components/list";
  46. import { mapGetters } from "vuex";
  47. import * as krfn from "@/core/index.js";
  48. import { $waiting } from "@/components/shared/loading";
  49. import Snapshot from "@/components/Snapshot";
  50. import { uploadCover, searchInAll3DScenes } from "@/api";
  51. import config from "@/config";
  52. import { isUpgradeAdapter } from "@/utils/fixVersion";
  53. let __krfn = krfn.default;
  54. export default {
  55. components: { list, Snapshot },
  56. data() {
  57. return {
  58. showFlash: false,
  59. inter: null,
  60. lang: config.lang || "zh",
  61. locationOrigin: process.env.VUE_APP_PROXY_URL_ROOT,
  62. currentSceneVersion: "V4",
  63. };
  64. },
  65. computed: {
  66. routerName() {
  67. return this.$route.name;
  68. },
  69. ...mapGetters({
  70. currentScene: "scene/currentScene",
  71. info: "info",
  72. isConfirmingPosi: "tags/isConfirmingPosi",
  73. }),
  74. showSnapshot() {
  75. return this.$route.name == "screen";
  76. },
  77. showExplanation() {
  78. return this.$route.name == "explanation";
  79. },
  80. },
  81. watch: {
  82. "$route.name": function (newVal) {
  83. __krfn.utils.toggleHotspot(this.$getKrpano(), newVal == "hotspot");
  84. this.handleRouterCoverForCap();
  85. },
  86. currentScene(newVal) {
  87. if (newVal) {
  88. this.$nextTick(() => {
  89. this.$bus.emit("initView", newVal.icon);
  90. });
  91. }
  92. if (newVal.type == "4dkk") {
  93. $("#pano").empty();
  94. if (!newVal.version) {
  95. // v1.3之前在作品中新增的三维场景,没有version这个值,需要查询。
  96. searchInAll3DScenes(
  97. {
  98. searchKey: newVal.sceneTitle,
  99. },
  100. (res) => {
  101. const originItem = res.data.list.find((item) => {
  102. return item.num === newVal.sceneCode;
  103. });
  104. const isVersion = isUpgradeAdapter(originItem.isUpgrade);
  105. newVal.version = isVersion;
  106. this.currentSceneVersion = isVersion;
  107. }
  108. );
  109. } else {
  110. this.currentSceneVersion = newVal.version;
  111. }
  112. this.handleIFrameCss();
  113. } else {
  114. $("#pano").empty();
  115. window.vrInitFn = () => {
  116. $waiting.hide();
  117. __krfn.utils.initHotspot(
  118. this.$getKrpano(),
  119. newVal && newVal.someData,
  120. true
  121. );
  122. __krfn.utils.toggleHotspot(
  123. this.$getKrpano(),
  124. this.$route.name == "hotspot"
  125. );
  126. };
  127. window.vrViewFn = () => {
  128. try {
  129. let visual = newVal.initVisual;
  130. const { sky, earth } = newVal.customMask;
  131. this.handleVisual(visual);
  132. this.handleSkyCover(sky);
  133. this.handleEarthCover(earth);
  134. } catch (error) {
  135. console.error(error);
  136. }
  137. };
  138. var settings = {
  139. "events[skin_events].onxmlcomplete": "js(window.vrViewFn());",
  140. "events[skin_events].onloadcomplete": "js(window.vrInitFn());",
  141. };
  142. if (newVal) {
  143. removepano("#pano");
  144. $waiting.show();
  145. embedpano({
  146. // http://oss-xiaoan.oss-cn-shenzhen.aliyuncs.com/720yun_fd_manage/fd720_Va0LrkXW3/vtour/tour.xml
  147. // xml: "%HTMLPATH%/static/template/tour.xml",
  148. xml: `${this.$cdn}/720yun_fd_manage/${newVal.sceneCode}/vtour/tour.xml`,
  149. swf: "%HTMLPATH%/static/template/tour.swf",
  150. target: "pano",
  151. html5: "auto",
  152. mobilescale: 1,
  153. vars: settings,
  154. webglsettings: { preserveDrawingBuffer: true },
  155. passQueryParameters: true,
  156. });
  157. }
  158. }
  159. },
  160. isConfirmingPosi(newVal) {
  161. this.inter && clearInterval(this.inter);
  162. this.inter = null;
  163. console.log("isConfirmingPosi", newVal);
  164. if (newVal) {
  165. this.inter = setInterval(() => {
  166. __krfn.utils.getCurrentMousePosition(this.$getKrpano(), newVal);
  167. }, 20);
  168. } else {
  169. this.$bus.emit("resethotspotTitle", "");
  170. }
  171. },
  172. },
  173. methods: {
  174. updateInfo() {
  175. let iidx = this.info.scenes.findIndex(
  176. (item) => this.currentScene.sceneCode == item.sceneCode
  177. );
  178. if (iidx > -1) {
  179. this.info.scenes[iidx] = {
  180. ...this.currentScene,
  181. };
  182. }
  183. this.$store.commit("SetInfo", this.info);
  184. },
  185. onClick() {
  186. this.$bus.emit("toggleFlash", true);
  187. let canvas = $("#krpanoSWFObject canvas")[0];
  188. let data = __krfn.utils.setInitView(this.$getKrpano(), canvas);
  189. uploadCover({ file: data.url, filename: "initCover.jpg" }, (res) => {
  190. if (res.code == 0) {
  191. this.currentScene.icon = res.data;
  192. this.currentScene.initVisual = {
  193. hlookat: data.hlookat,
  194. vlookat: data.vlookat,
  195. };
  196. this.$bus.emit("toggleFlash", false);
  197. this.$bus.emit("initView", res.data);
  198. this.updateInfo();
  199. this.$msg.success(this.$i18n.t("gather.setting_success"));
  200. this.$store.commit("SetInfo", this.info);
  201. }
  202. });
  203. },
  204. addhotspot(param) {
  205. __krfn.utils.addhotspot(this.$getKrpano(), param, true);
  206. this.$store.commit("tags/setIsConfirmingPosi", param.name);
  207. },
  208. handleVisual(visual) {
  209. this.$getKrpano().set(
  210. "view.vlookat",
  211. "vlookat" in visual ? visual.vlookat : ""
  212. );
  213. this.$getKrpano().set(
  214. "view.hlookat",
  215. "hlookat" in visual ? visual.hlookat : ""
  216. );
  217. this.$getKrpano().set("view.limitview", "lookat");
  218. this.$getKrpano().set(
  219. "view.vlookatmin",
  220. "vlookatmin" in visual ? visual.vlookatmin : "-90"
  221. );
  222. this.$getKrpano().set(
  223. "view.vlookatmax",
  224. "vlookatmax" in visual ? visual.vlookatmax : "90"
  225. );
  226. },
  227. /**
  228. * 1.6 处理遮罩层
  229. * @param {*} sky
  230. */
  231. handleSkyCover(sky) {
  232. if (sky) {
  233. if (sky.isShow) {
  234. this.$getKrpano().set("hotspot[peaklogo].visible", true);
  235. sky.icon && this.$getKrpano().set("hotspot[peaklogo].url", sky.icon);
  236. sky.scale &&
  237. this.$getKrpano().set("hotspot[peaklogo].scale", sky.scale);
  238. } else {
  239. this.$getKrpano().set("hotspot[peaklogo].visible", false);
  240. }
  241. }
  242. },
  243. /**
  244. * 1.6 处理遮罩层
  245. * @param {*} sky
  246. */
  247. handleEarthCover(earth) {
  248. if (earth) {
  249. if (earth.isShow) {
  250. this.$getKrpano().set("hotspot[nadirlogo].visible", true);
  251. earth.icon &&
  252. this.$getKrpano().set("hotspot[nadirlogo].url", earth.icon);
  253. earth.scale &&
  254. this.$getKrpano().set("hotspot[nadirlogo].scale", earth.scale);
  255. } else {
  256. this.$getKrpano().set("hotspot[nadirlogo].visible", false);
  257. }
  258. }
  259. },
  260. handleRouterCoverForCap() {
  261. const { sky, earth } = this.currentScene.customMask;
  262. sky.isShow &&
  263. this.$getKrpano() &&
  264. this.$getKrpano().set("hotspot[peaklogo].visible", true);
  265. earth.isShow &&
  266. this.$getKrpano() &&
  267. this.$getKrpano().set("hotspot[nadirlogo].visible", true);
  268. },
  269. handleIFrameCss() {
  270. setTimeout(() => {
  271. // const css = `
  272. // <style type="text/css">
  273. // .controls-right-buttons{display:none !important};
  274. // .controls-left-buttons .play-control {display: none !important;}
  275. // </style>
  276. // `;
  277. const iframe = document.getElementById("iframe-4dkk");
  278. const doc = iframe.contentWindow.document;
  279. if (doc) {
  280. console.log("存在-doc");
  281. var css =
  282. ".controls-right-buttons{display:none !important} " +
  283. ".controls-left-buttons .play-control{display:none !important} " +
  284. ".link-btn{display:none !important} " +
  285. ".clear-box{display:none !important} " +
  286. ".camera-btn{display:none !important} ";
  287. var head = doc.head || doc.getElementsByTagName("head")[0];
  288. var style = doc.createElement("style");
  289. style.type = "text/css";
  290. if (style.styleSheet) {
  291. style.styleSheet.cssText = css;
  292. } else {
  293. style.appendChild(doc.createTextNode(css));
  294. }
  295. head.appendChild(style);
  296. }
  297. }, 1000);
  298. },
  299. },
  300. mounted() {
  301. window.__krfn = __krfn;
  302. this.$bus.on("addhotspot", (data) => {
  303. this.addhotspot(data);
  304. });
  305. this.$bus.on("openHotspot", (data) => {
  306. if (this.isConfirmingPosi) {
  307. this.$store.commit("tags/setIsConfirmingPosi", false);
  308. }
  309. });
  310. },
  311. };
  312. </script>
  313. <style lang="less" scoped>
  314. .panocon {
  315. width: 100%;
  316. height: 100%;
  317. position: relative;
  318. overflow: hidden;
  319. #pano {
  320. width: 100%;
  321. height: 100%;
  322. }
  323. #iframe-4dkk {
  324. width: 100%;
  325. height: 100%;
  326. }
  327. .showexplanation {
  328. position: absolute;
  329. top: 20px;
  330. z-index: 999;
  331. right: 20px;
  332. width: 35px;
  333. height: 35px;
  334. background: rgba(0, 0, 0, 0.4);
  335. border-radius: 50%;
  336. border: 1px solid rgba(255, 255, 255, 0.2);
  337. backdrop-filter: blur(6px);
  338. > img {
  339. width: 100%;
  340. height: 100%;
  341. }
  342. }
  343. button.set-initial-view {
  344. position: absolute;
  345. bottom: 260px;
  346. min-width: 200px;
  347. left: 50%;
  348. transform: translateX(-50%);
  349. z-index: 99;
  350. }
  351. }
  352. </style>