App.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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.isShow3DMap"
  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. :style="{
  24. bottom: isShowNavBar ? '0' : '-112px',
  25. }"
  26. >
  27. <button
  28. class="tab-item"
  29. :class="{
  30. active: $route.name === 'GeneralView'
  31. }"
  32. @click="$router.push({name: 'GeneralView'})"
  33. >
  34. 概述总览
  35. <img
  36. class="decorator"
  37. src="@/assets/images/nav-item-active-decorator.png"
  38. alt=""
  39. draggable="false"
  40. >
  41. </button>
  42. <button
  43. class="tab-item"
  44. :class="{
  45. active: $route.name === 'HistoryView'
  46. }"
  47. @click="$router.push({name: 'HistoryView'})"
  48. >
  49. 历史回顾
  50. <img
  51. class="decorator"
  52. src="@/assets/images/nav-item-active-decorator.png"
  53. alt=""
  54. draggable="false"
  55. >
  56. </button>
  57. <button
  58. class="tab-item"
  59. :class="{
  60. active: $route.name === 'TreasureView'
  61. }"
  62. @click="$router.push({name: 'TreasureView'})"
  63. >
  64. 国之重器
  65. <img
  66. class="decorator"
  67. src="@/assets/images/nav-item-active-decorator.png"
  68. alt=""
  69. draggable="false"
  70. >
  71. </button>
  72. <button
  73. class="tab-item"
  74. :class="{
  75. active: $route.name === 'MetaverseView'
  76. }"
  77. @click="$router.push({name: 'MetaverseView'})"
  78. >
  79. 工业元宇宙
  80. <img
  81. class="decorator"
  82. src="@/assets/images/nav-item-active-decorator.png"
  83. alt=""
  84. draggable="false"
  85. >
  86. </button>
  87. </nav>
  88. <button
  89. class="show-hide"
  90. :style="{
  91. backgroundImage: isShowNavBar ? `url(${require(`@/assets/images/arrow-down.png`)})` : `url(${require(`@/assets/images/arrow-up.png`)})`,
  92. }"
  93. @click="isShowNavBar = !isShowNavBar"
  94. />
  95. </div>
  96. </template>
  97. <script>
  98. import HomeFadeIn from "@/components/HomeFadeIn.vue"
  99. import {
  100. computed,
  101. onMounted,
  102. reactive,
  103. ref,
  104. } from 'vue'
  105. export default {
  106. components: {
  107. HomeFadeIn,
  108. },
  109. setup () {
  110. console.log('setup!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
  111. const isShowFadeInMask = ref(process.env.VUE_APP_CLI_MODE === 'dev' ? false : true)
  112. const progress = ref(0)
  113. onMounted(() => {
  114. console.log('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_1.9.loader.js"
  129. var config = {
  130. dataUrl: buildUrl + "/SHIndustryMuseum_1.9.data.unityweb",
  131. frameworkUrl: buildUrl + "/SHIndustryMuseum_1.9.framework.js.unityweb",
  132. codeUrl: buildUrl + "/SHIndustryMuseum_1.9.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. for (let index = 1; index <= 36; index++) {
  164. unityInstance.SendMessage('Panel1', 'ShowEnterprise', index) //显示id为index的企业
  165. // unityInstance.SendMessage('Panel1', 'HideEnterprise', index); //隐藏id为index的企业
  166. }
  167. }).catch((message) => {
  168. alert(message)
  169. })
  170. }
  171. window.onClickEnterprise = function (id) {
  172. if (window.onCorpOnMapClicked) {
  173. window.onCorpOnMapClicked(id)
  174. }
  175. }
  176. document.body.appendChild(script)
  177. /**
  178. * end of unity
  179. */
  180. })
  181. const isShowNavBar = ref(true)
  182. const activeNavItemIdx = ref(0)
  183. return {
  184. isShowFadeInMask,
  185. progress,
  186. isShowNavBar,
  187. activeNavItemIdx,
  188. }
  189. },
  190. }
  191. </script>
  192. <style lang="less">
  193. html, body {
  194. // overscroll-behavior: none;
  195. // overflow: hidden;
  196. height: 100%;
  197. }
  198. #app {
  199. height: 100%;
  200. width: 100%;
  201. height: 100%;
  202. background-image: url(@/assets/images/main-bg.jpg);
  203. background-size: cover;
  204. background-repeat: no-repeat;
  205. background-position: center center;
  206. }
  207. // * {
  208. // user-select: none;
  209. // -webkit-touch-callout: none;
  210. // }
  211. // // 360浏览器不支持not()
  212. // input, textarea {
  213. // user-select: initial;
  214. // }
  215. // 字体
  216. // @font-face {
  217. // font-family: 'Source Han Serif CN';
  218. // src: url('@/assets/style/SourceHanSerifCN-Regular.otf');
  219. // }
  220. // @font-face {
  221. // font-family: 'Source Han Serif CN-Bold';
  222. // src: url('@/assets/style/SourceHanSerifCN-Bold.otf');
  223. // }
  224. // i {
  225. // font-style: italic;
  226. // }
  227. // 滚动条
  228. // ::-webkit-scrollbar { background: #dddecc; width: 0.3rem; height: 0.3rem; } /*宽度是对垂直滚动条而言,高度是对水平滚动条而言*/
  229. // ::-webkit-scrollbar-thumb { background: #828a5b; border-radius: 0.15rem; }
  230. // ::-webkit-scrollbar-corner { background: #dddecc; }
  231. // vue组件过渡效果
  232. .fade-out-leave-active {
  233. transition: opacity 1s;
  234. }
  235. .fade-out-leave-to {
  236. opacity: 0;
  237. }
  238. // // 不断渐变显隐 animation
  239. // .animation-show-hide {
  240. // animation: show-hide 1.8s infinite;
  241. // }
  242. // @keyframes show-hide {
  243. // 0% {
  244. // opacity: 0;
  245. // }
  246. // 50% {
  247. // opacity: 1;
  248. // }
  249. // 100% {
  250. // opacity: 0;
  251. // }
  252. // }
  253. // // vue-viewer
  254. // .viewer-container {
  255. // background-color: rgba(0, 0, 0, 80%) !important;
  256. // }
  257. // 或者
  258. // .viewer-backdrop {
  259. // background-color: rgba(0, 0, 0, 90%) !important;
  260. // }
  261. </style>
  262. <style scoped lang="less">
  263. #app {
  264. >.fade-in-mask {
  265. z-index: 5;
  266. }
  267. >nav {
  268. position: absolute;
  269. left: 0;
  270. width: 100%;
  271. height: 112px;
  272. border-radius: 5px 5px 0 0;
  273. border-top: solid 1px #D2BD84;
  274. box-shadow: inset 0px 2px 2px 0px rgba(210,189,132,0.45), 0px -9px 24px 0px rgba(183,162,109,0.25);
  275. display: flex;
  276. justify-content: center;
  277. align-items: center;
  278. transition: all 0.5s;
  279. backdrop-filter: blur(5px);
  280. >button.tab-item {
  281. font-size: 30px;
  282. font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  283. font-weight: 400;
  284. color: #FFFFFF;
  285. margin-left: 200px;
  286. opacity: 0.5;
  287. position: relative;
  288. user-select: none;
  289. >img.decorator {
  290. display: none;
  291. }
  292. &:first-of-type {
  293. margin-left: initial;
  294. }
  295. &.active {
  296. opacity: initial;
  297. >img.decorator {
  298. display: initial;
  299. position: absolute;
  300. left: 50%;
  301. bottom: -15px;
  302. transform: translateX(-50%);
  303. width: 150%;
  304. }
  305. }
  306. }
  307. @media only screen and (max-width: 1400px) {
  308. >button.tab-item {
  309. margin-left: 100px;
  310. }
  311. }
  312. }
  313. >button.show-hide {
  314. position: absolute;
  315. right: 82px;
  316. bottom: 34px;
  317. width: 36px;
  318. height: 36px;
  319. background-size: cover;
  320. background-repeat: no-repeat;
  321. background-position: center center;
  322. }
  323. @media only screen and (max-width: 1400px) {
  324. >button.show-hide {
  325. right: 10px;
  326. }
  327. }
  328. }
  329. </style>