index.js 4.4 KB

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