App.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <div id="app">
  3. <transition name="fade-out">
  4. <HomeFadeIn
  5. v-if="isShowFadeInMask"
  6. class="fade-in-mask"
  7. :progress="progress"
  8. />
  9. </transition>
  10. <div
  11. v-show="$route.meta.isShowUnityModel"
  12. id="unity-container"
  13. >
  14. <canvas
  15. id="unity-canvas"
  16. width="960"
  17. height="600"
  18. tabindex="-1"
  19. />
  20. </div>
  21. <router-view />
  22. <nav
  23. v-show="!$route.meta.hideNavBar"
  24. :style="{
  25. bottom: isShowNavBar ? '0' : '-112px',
  26. }"
  27. >
  28. <button
  29. class="tab-item"
  30. :class="{
  31. active: $route.meta.belongNavGroup === 0
  32. }"
  33. @click="$router.push({name: 'GeneralView'})"
  34. >
  35. 概述总览
  36. <img
  37. class="decorator"
  38. src="@/assets/images/nav-item-active-decorator.png"
  39. alt=""
  40. draggable="false"
  41. >
  42. </button>
  43. <button
  44. class="tab-item"
  45. :class="{
  46. active: $route.meta.belongNavGroup === 1
  47. }"
  48. @click="$router.push({name: 'HistoryView'})"
  49. >
  50. 历史回顾
  51. <img
  52. class="decorator"
  53. src="@/assets/images/nav-item-active-decorator.png"
  54. alt=""
  55. draggable="false"
  56. >
  57. </button>
  58. <button
  59. class="tab-item"
  60. :class="{
  61. active: $route.meta.belongNavGroup === 2
  62. }"
  63. @click="$router.push({name: 'TreasureView'})"
  64. >
  65. 国之重器
  66. <img
  67. class="decorator"
  68. src="@/assets/images/nav-item-active-decorator.png"
  69. alt=""
  70. draggable="false"
  71. >
  72. </button>
  73. <button
  74. class="tab-item"
  75. :class="{
  76. active: $route.meta.belongNavGroup === 3
  77. }"
  78. @click="$router.push({name: 'MetaverseView'})"
  79. >
  80. 工业元宇宙
  81. <img
  82. class="decorator"
  83. src="@/assets/images/nav-item-active-decorator.png"
  84. alt=""
  85. draggable="false"
  86. >
  87. </button>
  88. </nav>
  89. <button
  90. v-show="!$route.meta.hideNavBar"
  91. class="show-hide"
  92. :style="{
  93. backgroundImage: isShowNavBar ? `url(${require(`@/assets/images/arrow-down.png`)})` : `url(${require(`@/assets/images/arrow-up.png`)})`,
  94. }"
  95. @click="isShowNavBar = !isShowNavBar"
  96. />
  97. </div>
  98. </template>
  99. <script>
  100. import HomeFadeIn from "@/components/HomeFadeIn.vue"
  101. import {
  102. computed,
  103. onMounted,
  104. reactive,
  105. ref,
  106. } from 'vue'
  107. export default {
  108. components: {
  109. HomeFadeIn,
  110. },
  111. setup () {
  112. const isShowFadeInMask = ref(process.env.VUE_APP_CLI_MODE === 'dev' ? false : true)
  113. const progress = ref(0)
  114. onMounted(() => {
  115. // this.$mitt.on('test', e => {
  116. // console.log('test', e)
  117. // })
  118. /**
  119. * 加载unity
  120. */
  121. window.addEventListener("load", function () {
  122. if ("serviceWorker" in navigator) {
  123. navigator.serviceWorker.register("ServiceWorker.js")
  124. }
  125. })
  126. var canvas = document.querySelector("#unity-canvas")
  127. var buildUrl = "unity/Build"
  128. var loaderUrl = buildUrl + "/SHIndustryMuseum_2.3.loader.js"
  129. var config = {
  130. dataUrl: buildUrl + "/SHIndustryMuseum_2.3.data.unityweb",
  131. frameworkUrl: buildUrl + "/SHIndustryMuseum_2.3.framework.js.unityweb",
  132. codeUrl: buildUrl + "/SHIndustryMuseum_2.3.wasm.unityweb",
  133. streamingAssetsUrl: "StreamingAssets",
  134. companyName: "DefaultCompany",
  135. productName: "SHIndustryMuseum",
  136. productVersion: "0.1",
  137. }
  138. // By default Unity keeps WebGL canvas render target size matched with
  139. // the DOM size of the canvas element (scaled by window.devicePixelRatio)
  140. // Set this to false if you want to decouple this synchronization from
  141. // happening inside the engine, and you would instead like to size up
  142. // the canvas DOM size and WebGL render target sizes yourself.
  143. // config.matchWebGLToCanvasSize = false;
  144. if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
  145. // Mobile device style: fill the whole browser client area with the game canvas:
  146. var meta = document.createElement('meta')
  147. meta.name = 'viewport'
  148. meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes'
  149. document.getElementsByTagName('head')[0].appendChild(meta)
  150. }
  151. var script = document.createElement("script")
  152. script.src = loaderUrl
  153. script.onload = () => {
  154. createUnityInstance(canvas, config, (paramProgress) => {
  155. progress.value = Math.round(paramProgress * 100)
  156. if (paramProgress > 0.95) {
  157. setTimeout(() => {
  158. isShowFadeInMask.value = false
  159. }, 1000)
  160. }
  161. }).then((unityInstance) => {
  162. window.gUnityInst = unityInstance
  163. utils.loadUnitySceneGeneral()
  164. }).catch((message) => {
  165. alert(message)
  166. })
  167. }
  168. window.onClickEnterprise = function (id) {
  169. if (window.handleClickEnterprise) {
  170. window.handleClickEnterprise(id)
  171. }
  172. }
  173. window.onClickPlanet = function (id) {
  174. if (window.handleClickPlanet) {
  175. window.handleClickPlanet(id)
  176. }
  177. }
  178. window.onMovedPlanet = function (id) {
  179. if (window.handleMovedPlanet) {
  180. window.handleMovedPlanet(id)
  181. }
  182. }
  183. document.body.appendChild(script)
  184. /**
  185. * end of unity
  186. */
  187. })
  188. const isShowNavBar = ref(true)
  189. const activeNavItemIdx = ref(0)
  190. return {
  191. isShowFadeInMask,
  192. progress,
  193. isShowNavBar,
  194. activeNavItemIdx,
  195. }
  196. },
  197. }
  198. </script>
  199. <style lang="less">
  200. html, body {
  201. // overscroll-behavior: none;
  202. // overflow: hidden;
  203. height: 100%;
  204. }
  205. #app {
  206. height: 100%;
  207. width: 100%;
  208. height: 100%;
  209. background-image: url(@/assets/images/main-bg.jpg);
  210. background-size: cover;
  211. background-repeat: no-repeat;
  212. background-position: center center;
  213. }
  214. // * {
  215. // user-select: none;
  216. // -webkit-touch-callout: none;
  217. // }
  218. // // 360浏览器不支持not()
  219. // input, textarea {
  220. // user-select: initial;
  221. // }
  222. // 字体
  223. @font-face {
  224. font-family: 'Source Han Serif CN-Regular';
  225. src: url('@/assets/style/SOURCEHANSANSCN-REGULAR.OTF');
  226. }
  227. @font-face {
  228. font-family: 'Source Han Serif CN-Bold';
  229. src: url('@/assets/style/SOURCEHANSANSCN-BOLD.OTF');
  230. }
  231. // i {
  232. // font-style: italic;
  233. // }
  234. // 滚动条
  235. // ::-webkit-scrollbar { background: #dddecc; width: 0.3rem; height: 0.3rem; } /*宽度是对垂直滚动条而言,高度是对水平滚动条而言*/
  236. // ::-webkit-scrollbar-thumb { background: #828a5b; border-radius: 0.15rem; }
  237. // ::-webkit-scrollbar-corner { background: #dddecc; }
  238. // vue组件过渡效果
  239. .fade-out-leave-active {
  240. transition: opacity 1s;
  241. }
  242. .fade-out-leave-to {
  243. opacity: 0;
  244. }
  245. // // 不断渐变显隐 animation
  246. // .animation-show-hide {
  247. // animation: show-hide 1.8s infinite;
  248. // }
  249. // @keyframes show-hide {
  250. // 0% {
  251. // opacity: 0;
  252. // }
  253. // 50% {
  254. // opacity: 1;
  255. // }
  256. // 100% {
  257. // opacity: 0;
  258. // }
  259. // }
  260. // // vue-viewer
  261. // .viewer-container {
  262. // background-color: rgba(0, 0, 0, 80%) !important;
  263. // }
  264. // 或者
  265. // .viewer-backdrop {
  266. // background-color: rgba(0, 0, 0, 90%) !important;
  267. // }
  268. </style>
  269. <style scoped lang="less">
  270. #app {
  271. >.fade-in-mask {
  272. z-index: 5;
  273. }
  274. >nav {
  275. position: absolute;
  276. left: 0;
  277. width: 100%;
  278. height: 112px;
  279. border-radius: 5px 5px 0 0;
  280. border-top: solid 1px #D2BD84;
  281. box-shadow: inset 0px 2px 2px 0px rgba(210,189,132,0.45), 0px -9px 24px 0px rgba(183,162,109,0.25);
  282. display: flex;
  283. justify-content: center;
  284. align-items: center;
  285. transition: all 0.5s;
  286. backdrop-filter: blur(5px);
  287. >button.tab-item {
  288. font-size: 30px;
  289. font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  290. font-weight: 400;
  291. color: #FFFFFF;
  292. margin-left: 200px;
  293. opacity: 0.5;
  294. position: relative;
  295. user-select: none;
  296. >img.decorator {
  297. display: none;
  298. }
  299. &:first-of-type {
  300. margin-left: initial;
  301. }
  302. &.active {
  303. opacity: initial;
  304. >img.decorator {
  305. display: initial;
  306. position: absolute;
  307. left: 50%;
  308. bottom: -15px;
  309. transform: translateX(-50%);
  310. width: 150%;
  311. }
  312. }
  313. }
  314. @media only screen and (max-width: 1400px) {
  315. >button.tab-item {
  316. margin-left: 100px;
  317. }
  318. }
  319. }
  320. >button.show-hide {
  321. position: absolute;
  322. right: 82px;
  323. bottom: 34px;
  324. width: 36px;
  325. height: 36px;
  326. background-size: cover;
  327. background-repeat: no-repeat;
  328. background-position: center center;
  329. }
  330. @media only screen and (max-width: 1400px) {
  331. >button.show-hide {
  332. right: 10px;
  333. }
  334. }
  335. }
  336. </style>