control.pano_js.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <ul class="control-pano" :style="injectStyle">
  3. <li @click="onIsAutoRotate">
  4. <img :src="require(`@/assets/images/js_icon/${isAutoRotate ? 'auto_active.png' : 'auto.png'}`)"
  5. alt="" />
  6. <div>自动漫游</div>
  7. </li>
  8. <li @click="onIsShowList" v-if="!((metadata.catalogRoot && metadata.catalogRoot.length == 1) && scenes.length == 1 && secondaryList.length == 1)">
  9. <img :src="require(`@/assets/images/js_icon/${isShowScenesList ? 'daolan_active.png' : 'daolan.png'}`)"
  10. alt="" />
  11. <div>导览列表</div>
  12. </li>
  13. <li @click="onIsShowHotspotList">
  14. <img :src="require(`@/assets/images/js_icon/${isShowHotspotList ? 'hotspot_active.png' : 'hotspot.png'}`)"
  15. alt="" />
  16. <div>热点列表</div>
  17. </li>
  18. <li @click="onVR"
  19. v-if="currentScene.type == 'pano' || (fdkkCurrentVersion == 'v3') || (currentScene.type == '4dkk' && (fdkkmetadata.controls && fdkkmetadata.controls.showVR))">
  20. <img :src="require(`@/assets/images/js_icon/${isShowHotspotList ? 'vr_active.png' : 'vr.png'}`)"
  21. alt="" />
  22. <div>VR可视</div>
  23. </li>
  24. </ul>
  25. <teleport to='body'>
  26. <introduce v-if="showIntroduce" />
  27. <telephone v-if="showTelephone" />
  28. <clink v-if="showLink" />
  29. <hotspotList v-if="isShowHotspotList" />
  30. <div class="musicfix" v-if="metadata.backgroundMusic && metadata.backgroundMusic.id" @click="onIsBGM">
  31. <img :src="require(`@/assets/images/js_icon/${showMusicPlaying ? 'music.png' : 'music_active.png'}`)" alt="" />
  32. </div>
  33. </teleport>
  34. </template>
  35. <script setup>
  36. import { ref, watch, computed, onMounted, defineProps, nextTick } from "vue";
  37. import { useStore } from "vuex";
  38. import { useApp } from "@/app";
  39. import introduce from "./control/text";
  40. import telephone from "./control/telephone";
  41. import clink from "./control/link";
  42. import hotspotList from "./control/hotspotList";
  43. import { useMusicPlayer,useSoundPlayer } from '@/utils/sound'
  44. const $iosGrantedTips = (cb) => {
  45. var ua = navigator.userAgent.toLowerCase();
  46. if (ua.indexOf("like mac os x") > 0) {
  47. var reg = /os [\d._]*/gi;
  48. var verinfo = ua.match(reg);
  49. var version = (verinfo + "")
  50. .replace(/[^0-9|_.]/gi, "")
  51. .replace(/_/gi, ".");
  52. var arr = version.split(".");
  53. console.log(arr);
  54. if (arr[0] > 12 && arr[1] >= 0) {
  55. //对13.3以后的版本处理,包括13.3,
  56. DeviceMotionEvent && DeviceMotionEvent.requestPermission()
  57. .then((permissionState) => {
  58. if (permissionState == "granted") {
  59. cb({
  60. msg: '授权成功',
  61. code: 1
  62. })
  63. this.reload();
  64. } else {
  65. cb({
  66. msg: '授权失败',
  67. code: 0
  68. })
  69. }
  70. })
  71. }
  72. else {
  73. //13.3以前的版本
  74. cb({
  75. msg: '无需授权,直接成功',
  76. code: 1
  77. })
  78. }
  79. } else {
  80. cb({
  81. msg: '无需授权,直接成功',
  82. code: 1
  83. })
  84. }
  85. }
  86. const props = defineProps(['injectStyle'])
  87. //背景音乐
  88. const musicPlayer = useMusicPlayer()
  89. //解说音乐
  90. const soundPlayer = useSoundPlayer()
  91. const store = useStore();
  92. const metadata = computed(() => store.getters["scene/metadata"]);
  93. const isAutoRotate = computed(() => store.getters["functions/isAutoRotate"]);
  94. const isShowHotspotList = computed(() => store.getters["functions/isShowHotspotList"]);
  95. const showTours = computed(() => store.getters["fdkk/isShowToursList"]);
  96. const scenes = computed(() => store.getters["scene/list"]);
  97. const secondaryList = computed(() => store.getters["scene/secondaryList"]);
  98. const isShowScenesList = computed(() => store.getters["functions/isShowScenesList"]);
  99. const fdkkmetadata = computed(() => store.getters["fdkk/metadata"]);
  100. const fdkkCurrentVersion = computed(() => store.getters["scene/fdkkCurrentVersion"]);
  101. const vrStatus = computed(() => store.getters["functions/vrStatus"]);
  102. const showMusicPlaying = ref(musicPlayer.isPlay)
  103. const showCommentaryPlaying = ref(soundPlayer.isPlay)
  104. const onIsShowList = (data) => {
  105. if (showTours.value) {
  106. store.commit('fdkk/setShowToursList', false)
  107. }
  108. store.commit("functions/setShowScenesList", !isShowScenesList.value);
  109. };
  110. // const isCommentary = computed(() => store.getters["functions/isCommentary"]);
  111. const currentScene = computed(() => store.getters["scene/currentScene"]);
  112. const customTelephone = computed(() => store.getters["scene/customTelephone"]);
  113. const customLink = computed(() => store.getters["scene/customLink"]);
  114. const showIntroduce = computed(() => store.getters["functions/showIntroduce"]);
  115. const showTelephone = computed(() => store.getters["functions/showTelephone"]);
  116. const showLink = computed(() => store.getters["functions/showLink"]);
  117. const isFullscreen = ref(false)
  118. const onIntroduce = () => {
  119. store.commit("functions/setShowIntroduce", true);
  120. }
  121. const onLink = () => {
  122. store.commit("functions/setShowLink", true);
  123. }
  124. const onIsBGM = () => {
  125. showMusicPlaying.value ? musicPlayer.pause() : musicPlayer.play()
  126. }
  127. const onIsAutoRotate = () => {
  128. store.commit("functions/setAutoRotate", !isAutoRotate.value);
  129. };
  130. const onVR = () => {
  131. $iosGrantedTips((data) => {
  132. console.log(data);
  133. if (data.code == 1) {
  134. store.commit("functions/setVrStatus", !vrStatus.value);
  135. if (currentScene.value.type == 'pano') {
  136. useApp().then((app) => {
  137. app.krpanoDom.call(vrStatus.value ? "webvr.enterVR()" : "webvr.exitVR()")
  138. });
  139. } else {
  140. if (fdkkCurrentVersion.value == 'v4') {
  141. document.querySelector('#fdkkifr') && document.querySelector('#fdkkifr').contentWindow.postMessage(
  142. {
  143. source: "qjkankan",
  144. event: "enterVr",
  145. params: {
  146. toggle: vrStatus.value
  147. }
  148. },
  149. "*"
  150. );
  151. } else {
  152. let ele = document.getElementById("showifr");
  153. ele && ele.contentWindow.postMessage(
  154. {
  155. source: "mingyuan",
  156. event: vrStatus.value ? "vr-in" : "vr-out",
  157. },
  158. "*"
  159. );
  160. }
  161. }
  162. } else {
  163. alert('运动和方向访问失败,您需要完全关闭此应用,然后再次打开,并允许访问运动与方向')
  164. }
  165. });
  166. };
  167. const onIsShowHotspotList = () => {
  168. store.commit("functions/setShowHotspotList", !isShowHotspotList.value);
  169. };
  170. const onIsCommentary = (data) => {
  171. showCommentaryPlaying.value ? soundPlayer.pause() : soundPlayer.play()
  172. };
  173. const onShare = () => {
  174. store.commit("functions/setShareUrl", true);
  175. };
  176. const staticList = ref([
  177. {
  178. id: "cruise",
  179. name: "巡游开关",
  180. icon: "rotation@2x.png",
  181. icondisabled: "rotation_disabled@2x.png",
  182. },
  183. {
  184. id: "vr",
  185. name: "VR",
  186. icon: "vr@2x.png",
  187. },
  188. {
  189. id: "share",
  190. name: "分享",
  191. icon: "share@2x.png",
  192. },
  193. {
  194. id: "full",
  195. name: "全屏",
  196. icon: "fullscreen@2x.png",
  197. icondisabled: "rotation_disabled@2x.png",
  198. },
  199. ]);
  200. onMounted(() => {
  201. let events = ['fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange', 'MSFullscreenChange']
  202. events.forEach((item, index) => {
  203. window.addEventListener(item, () => {
  204. isFullscreen.value = !isFullscreen.value
  205. })
  206. })
  207. })
  208. musicPlayer.on('play', () => {
  209. showMusicPlaying.value = true
  210. soundPlayer.pause()
  211. })
  212. musicPlayer.on('pause', () => (showMusicPlaying.value = false))
  213. soundPlayer.on('play', () => {
  214. showCommentaryPlaying.value = true
  215. musicPlayer.pause()
  216. })
  217. soundPlayer.on('pause', () => (showCommentaryPlaying.value = false))
  218. </script>
  219. <style lang="scss" scoped>
  220. .control-pano {
  221. display: flex;
  222. align-items: center;
  223. justify-content: center;
  224. height: 100%;
  225. transition: 0.3s ease all;
  226. width: 100%;
  227. margin: 0 auto;
  228. background-image: url('@/assets/images/js_icon/line.png');
  229. background-position: 0 6px;
  230. background-size: 100% auto;
  231. background-repeat: no-repeat;
  232. >li {
  233. margin: 0 8px;
  234. cursor: pointer;
  235. display: flex;
  236. flex-direction: column;
  237. justify-content: center;
  238. align-items: center;
  239. flex-shrink: 0;
  240. img {
  241. width: 34px;
  242. height: 34px;
  243. }
  244. >div{
  245. font-size: 12px;
  246. margin-top: 4px;
  247. }
  248. &:last-of-type{
  249. margin-right: 10px;
  250. }
  251. &:first-of-type{
  252. margin-left: 10px;
  253. }
  254. }
  255. }
  256. .musicfix {
  257. position: fixed;
  258. right: 16px;
  259. top: 320px;
  260. transform: translateY(-50%);
  261. z-index: 999;
  262. width: 40px;
  263. >img{
  264. width: 100%;
  265. }
  266. }
  267. </style>