RightButtons.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="controls-right-buttons" :class="{ disabled: isPlay }">
  3. <div @click="onVRClick" v-if="controls.showVR">
  4. <ui-icon type="vr" :tip="$t('mode.vr')" tipV="top"></ui-icon>
  5. </div>
  6. <div :class="{ playing: showMusicPlaying }" v-if="showMusic" @click="onMusicClick">
  7. <ui-icon type="music" :tip="showMusicPlaying ? '' : $t('mode.music')" tipV="top"></ui-icon>
  8. </div>
  9. <div v-if="controls.showRule" class="rule" @click="onRuleClick">
  10. <ui-icon :tip="$t('mode.rule')" tipV="top" type="show_more_ruler"></ui-icon>
  11. </div>
  12. <div @click="onFullScreen">
  13. <ui-icon :type="isFullscreen ? 'scene_window' : 'full'" :tip="isFullscreen ? $t('mode.exitFullScene') : $t('mode.fullScene')" tipV="top"></ui-icon>
  14. <!-- <i class="iconfont" :class="isFullscreen ? 'icon-scene_window' : 'icon-full'"></i> -->
  15. </div>
  16. </div>
  17. <teleport to="body">
  18. <Rules v-if="showRules" @close="closeRules" />
  19. </teleport>
  20. </template>
  21. <script setup>
  22. import { computed, ref, onMounted } from 'vue'
  23. import { useStore } from 'vuex'
  24. import { useMusicPlayer } from '@/utils/sound'
  25. import { Dialog } from '@/global_components'
  26. import { useApp, getApp, getNum } from '@/app'
  27. import Rules from './rules'
  28. import { useI18n } from '@/i18n'
  29. const { t } = useI18n({ useScope: 'global' })
  30. const store = useStore()
  31. const controls = computed(() => store.getters['scene/metadata'].controls || {})
  32. const showMusic = computed(() => store.getters['scene/metadata'].music)
  33. const showMusicPlaying = ref(false)
  34. const musicPlayer = useMusicPlayer()
  35. const isFullscreen = ref(false)
  36. const showRules = ref(false)
  37. const onVRClick = () => {
  38. Dialog.toast(t('limit.viewInVr'))
  39. }
  40. const isPlay = computed(() => {
  41. return store.getters['tour/isPlay']
  42. })
  43. const closeRules = () => {
  44. showRules.value = false
  45. getApp().TagManager.cancelMeasure()
  46. store.commit('SetOptions', { sceneUI: true })
  47. }
  48. const onRuleClick = () => {
  49. showRules.value = true
  50. getApp().MinMap.hide()
  51. getApp().TagManager.startMeasure()
  52. store.commit('SetOptions', { sceneUI: false })
  53. }
  54. const onMusicClick = () => {
  55. showMusicPlaying.value ? musicPlayer.pause() : musicPlayer.play()
  56. }
  57. const onFullScreen = () => {
  58. let element = document.documentElement
  59. if (isFullscreen.value) {
  60. if (document.exitFullscreen) {
  61. document.exitFullscreen()
  62. } else if (document.webkitCancelFullScreen) {
  63. document.webkitCancelFullScreen()
  64. } else if (document.mozCancelFullScreen) {
  65. document.mozCancelFullScreen()
  66. } else if (document.msExitFullscreen) {
  67. document.msExitFullscreen()
  68. }
  69. } else {
  70. if (element.requestFullscreen) {
  71. element.requestFullscreen()
  72. } else if (element.webkitRequestFullScreen) {
  73. element.webkitRequestFullScreen()
  74. } else if (element.mozRequestFullScreen) {
  75. element.mozRequestFullScreen()
  76. } else if (element.msRequestFullscreen) {
  77. element.msRequestFullscreen()
  78. }
  79. }
  80. // 改变当前全屏状态
  81. //this.isFullscreen = !this.isFullscreen;
  82. }
  83. onMounted(() => {
  84. let events = ['fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange', 'MSFullscreenChange']
  85. events.forEach((item, index) => {
  86. window.addEventListener(item, () => {
  87. isFullscreen.value = !isFullscreen.value
  88. })
  89. })
  90. useApp().then(app => {
  91. app.TagManager.on('tagManager.firstMarkTagPosB', () => {
  92. Dialog.toast(t('toast.clickLeft'))
  93. })
  94. })
  95. })
  96. musicPlayer.on('play', () => (showMusicPlaying.value = true))
  97. musicPlayer.on('pause', () => (showMusicPlaying.value = false))
  98. </script>
  99. <style lang="scss" scoped>
  100. .controls-right-buttons {
  101. display: flex;
  102. margin-right: 20px;
  103. margin-bottom: 20px;
  104. > div {
  105. cursor: pointer;
  106. margin-left: 10px;
  107. display: flex;
  108. align-items: center;
  109. justify-content: center;
  110. width: 34px;
  111. height: 34px;
  112. background-color: rgba(0, 0, 0, 0.3);
  113. border-radius: 50%;
  114. // pointer-events: all;
  115. font-size: 18px;
  116. }
  117. .playing {
  118. animation: spinner 4s linear infinite;
  119. }
  120. }
  121. @keyframes spinner {
  122. 0% {
  123. transform: rotate(0);
  124. }
  125. to {
  126. transform: rotate(1turn);
  127. }
  128. }
  129. </style>