index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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(newVal == "screen");
  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. } else {
  113. $("#pano").empty();
  114. window.vrInitFn = () => {
  115. $waiting.hide();
  116. __krfn.utils.initHotspot(
  117. this.$getKrpano(),
  118. newVal && newVal.someData,
  119. true
  120. );
  121. __krfn.utils.toggleHotspot(
  122. this.$getKrpano(),
  123. this.$route.name == "hotspot"
  124. );
  125. };
  126. window.vrViewFn = () => {
  127. try {
  128. let visual = newVal.initVisual;
  129. const { sky, earth } = newVal.customMask;
  130. this.handleVisual(visual);
  131. this.handleSkyCover(sky);
  132. this.handleEarthCover(earth);
  133. } catch (error) {
  134. console.error(error);
  135. }
  136. };
  137. var settings = {
  138. "events[skin_events].onxmlcomplete": "js(window.vrViewFn());",
  139. "events[skin_events].onloadcomplete": "js(window.vrInitFn());",
  140. };
  141. if (newVal) {
  142. removepano("#pano");
  143. $waiting.show();
  144. embedpano({
  145. // http://oss-xiaoan.oss-cn-shenzhen.aliyuncs.com/720yun_fd_manage/fd720_Va0LrkXW3/vtour/tour.xml
  146. // xml: "%HTMLPATH%/static/template/tour.xml",
  147. xml: `${this.$cdn}/720yun_fd_manage/${newVal.sceneCode}/vtour/tour.xml`,
  148. swf: "%HTMLPATH%/static/template/tour.swf",
  149. target: "pano",
  150. html5: "auto",
  151. mobilescale: 1,
  152. vars: settings,
  153. webglsettings: { preserveDrawingBuffer: true },
  154. passQueryParameters: true,
  155. });
  156. }
  157. }
  158. },
  159. isConfirmingPosi(newVal) {
  160. this.inter && clearInterval(this.inter);
  161. this.inter = null;
  162. console.log("isConfirmingPosi", newVal);
  163. if (newVal) {
  164. this.inter = setInterval(() => {
  165. __krfn.utils.getCurrentMousePosition(this.$getKrpano(), newVal);
  166. }, 20);
  167. } else {
  168. this.$bus.emit("resethotspotTitle", "");
  169. }
  170. },
  171. },
  172. methods: {
  173. updateInfo() {
  174. let iidx = this.info.scenes.findIndex(
  175. (item) => this.currentScene.sceneCode == item.sceneCode
  176. );
  177. if (iidx > -1) {
  178. this.info.scenes[iidx] = {
  179. ...this.currentScene,
  180. };
  181. }
  182. this.$store.commit("SetInfo", this.info);
  183. },
  184. onClick() {
  185. this.$bus.emit("toggleFlash", true);
  186. let canvas = $("#krpanoSWFObject canvas")[0];
  187. let data = __krfn.utils.setInitView(this.$getKrpano(), canvas);
  188. uploadCover({ file: data.url, filename: "initCover.jpg" }, (res) => {
  189. if (res.code == 0) {
  190. this.currentScene.icon = res.data;
  191. this.currentScene.initVisual = {
  192. hlookat: data.hlookat,
  193. vlookat: data.vlookat,
  194. };
  195. this.$bus.emit("toggleFlash", false);
  196. this.$bus.emit("initView", res.data);
  197. this.updateInfo();
  198. this.$msg.success(this.$i18n.t("gather.setting_success"));
  199. this.$store.commit("SetInfo", this.info);
  200. }
  201. });
  202. },
  203. addhotspot(param) {
  204. __krfn.utils.addhotspot(this.$getKrpano(), param, true);
  205. this.$store.commit("tags/setIsConfirmingPosi", param.name);
  206. },
  207. handleVisual(visual) {
  208. this.$getKrpano().set("view.vlookat", visual ? visual.vlookat : "");
  209. this.$getKrpano().set("view.hlookat", visual ? visual.hlookat : "");
  210. this.$getKrpano().set("view.limitview", "lookat");
  211. this.$getKrpano().set(
  212. "view.vlookatmin",
  213. visual ? String(visual.vlookatmin) : "-90"
  214. );
  215. this.$getKrpano().set(
  216. "view.vlookatmax",
  217. visual ? String(visual.vlookatmax) : "90"
  218. );
  219. },
  220. /**
  221. * 1.6 处理遮罩层
  222. * @param {*} sky
  223. */
  224. handleSkyCover(sky) {
  225. if (sky) {
  226. if (sky.isShow) {
  227. this.$getKrpano().set("hotspot[peaklogo].visible", true);
  228. sky.icon && this.$getKrpano().set("hotspot[peaklogo].url", sky.icon);
  229. sky.scale &&
  230. this.$getKrpano().set("hotspot[peaklogo].scale", sky.scale);
  231. } else {
  232. this.$getKrpano().set("hotspot[peaklogo].visible", false);
  233. }
  234. }
  235. },
  236. /**
  237. * 1.6 处理遮罩层
  238. * @param {*} sky
  239. */
  240. handleEarthCover(earth) {
  241. if (earth) {
  242. if (earth.isShow) {
  243. this.$getKrpano().set("hotspot[nadirlogo].visible", true);
  244. earth.icon &&
  245. this.$getKrpano().set("hotspot[nadirlogo].url", earth.icon);
  246. earth.scale &&
  247. this.$getKrpano().set("hotspot[nadirlogo].scale", earth.scale);
  248. } else {
  249. this.$getKrpano().set("hotspot[nadirlogo].visible", false);
  250. }
  251. }
  252. },
  253. handleRouterCoverForCap(isRoute) {
  254. if (isRoute) {
  255. this.$getKrpano().set("hotspot[peaklogo].visible", false);
  256. this.$getKrpano().set("hotspot[nadirlogo].visible", false);
  257. } else {
  258. const { sky, earth } = this.currentScene.customMask;
  259. sky.isShow && this.$getKrpano().set("hotspot[peaklogo].visible", true);
  260. earth.isShow &&
  261. this.$getKrpano().set("hotspot[nadirlogo].visible", true);
  262. }
  263. },
  264. },
  265. mounted() {
  266. window.__krfn = __krfn;
  267. this.$bus.on("addhotspot", (data) => {
  268. this.addhotspot(data);
  269. });
  270. this.$bus.on("openHotspot", (data) => {
  271. if (this.isConfirmingPosi) {
  272. this.$store.commit("tags/setIsConfirmingPosi", false);
  273. }
  274. });
  275. },
  276. };
  277. </script>
  278. <style lang="less" scoped>
  279. .panocon {
  280. width: 100%;
  281. height: 100%;
  282. position: relative;
  283. overflow: hidden;
  284. #pano {
  285. width: 100%;
  286. height: 100%;
  287. }
  288. #iframe-4dkk {
  289. width: 100%;
  290. height: 100%;
  291. }
  292. .showexplanation {
  293. position: absolute;
  294. top: 20px;
  295. z-index: 999;
  296. right: 20px;
  297. width: 35px;
  298. height: 35px;
  299. background: rgba(0, 0, 0, 0.4);
  300. border-radius: 50%;
  301. border: 1px solid rgba(255, 255, 255, 0.2);
  302. backdrop-filter: blur(6px);
  303. > img {
  304. width: 100%;
  305. height: 100%;
  306. }
  307. }
  308. button.set-initial-view {
  309. position: absolute;
  310. bottom: 260px;
  311. min-width: 200px;
  312. left: 50%;
  313. transform: translateX(-50%);
  314. z-index: 99;
  315. }
  316. }
  317. </style>