index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import HomeView from '../views/HomeView.vue'
  4. import RelicsAppr from "@/views/RelicsAppr.vue"
  5. import RelicDetail from "@/components/RelicDetail.vue"
  6. import SwkkFadeIn from "@/views/SwkkFadeIn.vue"
  7. import SwkkView from "@/views/SwkkView.vue"
  8. import ObliqueView from "@/views/ObliqueView.vue"
  9. import PanoView from "@/views/PanoView.vue"
  10. import PanoList from "@/components/PanoList.vue"
  11. import TestView from "@/components/TestView.vue"
  12. Vue.use(VueRouter)
  13. const routes = [
  14. {
  15. path: '/',
  16. name: 'HomeView',
  17. component: HomeView,
  18. beforeEnter (to, from, next) {
  19. const audioNode = document.getElementById('global-audio')
  20. // audioNode.pause()
  21. if (from.name && audioNode.src !== require(`@/assets/audios/${globalConfig.audioName.homeView}.mp3`)) {
  22. audioNode.src = require(`@/assets/audios/${globalConfig.audioName.homeView}.mp3`)
  23. audioNode.play()
  24. }
  25. if (!from.name) {
  26. globalApi.recordVisit()
  27. }
  28. next()
  29. }
  30. },
  31. {
  32. path: '/test-view',
  33. name: 'TestView',
  34. component: TestView,
  35. },
  36. {
  37. path: '/swkk-fade-in',
  38. name: 'SwkkFadeIn',
  39. component: SwkkFadeIn,
  40. meta: {
  41. isShowBottomBar: false,
  42. canFullScreen: false,
  43. }
  44. },
  45. {
  46. path: '/swkk-view',
  47. name: 'SwkkView',
  48. component: SwkkView,
  49. meta: {
  50. isShowBottomBar: true,
  51. canFullScreen: true,
  52. },
  53. beforeEnter (to, from, next) {
  54. if (from.name === 'HomeView') {
  55. // 从首页过来的,需要reload。此时location还没有变。
  56. let shabi = to.fullPath
  57. location.hash = shabi
  58. location.reload()
  59. } else {
  60. // 无论是从首页还是从不同楼层过来,导致reload。
  61. const audioNode = document.getElementById('global-audio')
  62. if (audioNode.src !== require(`@/assets/audios/${globalConfig.audioName.swkkView}.mp3`)) {
  63. audioNode.src = require(`@/assets/audios/${globalConfig.audioName.swkkView}.mp3`)
  64. audioNode.play()
  65. }
  66. next()
  67. }
  68. },
  69. },
  70. {
  71. path: '/oblique-view',
  72. name: 'ObliqueView',
  73. component: ObliqueView,
  74. meta: {
  75. isShowBottomBar: true,
  76. canFullScreen: true,
  77. isSpecialStyle: true,
  78. },
  79. children: [
  80. {
  81. path: 'pano-list',
  82. name: 'PanoListInOblique',
  83. component: PanoList,
  84. meta: {
  85. isShowBottomBar: false,
  86. canFullScreen: false,
  87. },
  88. beforeEnter(to, from, next) {
  89. const audioNode = document.getElementById('global-audio')
  90. if (audioNode.src !== require(`@/assets/audios/${globalConfig.audioName.obliqueAndPano}.mp3`)) {
  91. audioNode.src = require(`@/assets/audios/${globalConfig.audioName.obliqueAndPano}.mp3`)
  92. audioNode.play()
  93. }
  94. next()
  95. }
  96. },
  97. ],
  98. },
  99. {
  100. path: '/pano-view',
  101. name: 'PanoView',
  102. component: PanoView,
  103. meta: {
  104. isShowBottomBar: true,
  105. canFullScreen: true,
  106. },
  107. children: [
  108. {
  109. path: 'pano-list',
  110. name: 'PanoListInPano',
  111. component: PanoList,
  112. meta: {
  113. isShowBottomBar: false,
  114. canFullScreen: false,
  115. }
  116. },
  117. ],
  118. },
  119. {
  120. path: '/relics-appr',
  121. name: 'RelicsAppr',
  122. component: RelicsAppr,
  123. meta: {
  124. isShowBottomBar: true,
  125. canFullScreen: false,
  126. },
  127. children: [
  128. {
  129. path: 'relic-detail',
  130. name: 'RelicDetail',
  131. component: RelicDetail,
  132. meta: {
  133. isShowBottomBar: true,
  134. canFullScreen: false,
  135. }
  136. },
  137. ],
  138. beforeEnter (to, from, next) {
  139. const audioNode = document.getElementById('global-audio')
  140. if (audioNode.src !== require(`@/assets/audios/${globalConfig.audioName.relicsAppr}.mp3`)) {
  141. audioNode.src = require(`@/assets/audios/${globalConfig.audioName.relicsAppr}.mp3`)
  142. audioNode.play()
  143. }
  144. next()
  145. },
  146. },
  147. {
  148. path: '/about',
  149. name: 'about',
  150. // route level code-splitting
  151. // this generates a separate chunk (about.[hash].js) for this route
  152. // which is lazy-loaded when the route is visited.
  153. component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  154. }
  155. ]
  156. const router = new VueRouter({
  157. mode: 'hash',
  158. base: process.env.BASE_URL,
  159. routes
  160. })
  161. router.beforeEach((to, from, next) => {
  162. console.log('beforeEach: ', to, from, next)
  163. // 强制每次都从首页进入
  164. if (process.env.NODE_ENV === 'production' && !from.name && to.name !== 'HomeView' && to.name !== 'SwkkView') {
  165. next('/')
  166. } else {
  167. next()
  168. }
  169. })
  170. export default router