瀏覽代碼

bug fix: 第二次进入swkk会有问题。所以要reload。

任一存 2 年之前
父節點
當前提交
b41b5bb090
共有 2 個文件被更改,包括 37 次插入23 次删除
  1. 9 11
      src/router/index.js
  2. 28 12
      src/views/SwkkView.vue

+ 9 - 11
src/router/index.js

@@ -140,16 +140,14 @@ const router = new VueRouter({
   routes
 })
 
-if (process.env.NODE_ENV === 'production') {
-  // 强制每次都从首页进入
-  router.beforeEach((to, from, next) => {
-    console.log(to, from, next)
-    if (!from.name && to.name !== 'HomeView') {
-      next('/')
-    } else {
-      next()
-    }
-  })
-}
+// 强制每次都从首页进入
+router.beforeEach((to, from, next) => {
+  console.log('beforeEach: ', to, from, next)
+  if (process.env.NODE_ENV === 'production' && !from.name && to.name !== 'HomeView' && !location.href.endsWith('autoReload=true')) {
+    next('/')
+  } else {
+    next()
+  }
+})
 
 export default router

+ 28 - 12
src/views/SwkkView.vue

@@ -1,5 +1,8 @@
 <template>
-  <div class="skww-view">
+  <div
+    v-show="canShow"
+    class="skww-view"
+  >
     <div
       class="swkk-wrap"
     />
@@ -167,6 +170,8 @@ export default {
   data() {
     //这里存放数据
     return {
+      canShow: false,
+
       kankan: null,
       isLoading: true,
 
@@ -226,19 +231,30 @@ export default {
       }
     }
   },
+  beforeCreate() {
+    if (!location.href.endsWith('autoReload=true')) {
+      location.href += '&autoReload=true'
+      location.reload()
+    } else {
+      location.href = location.href.substring(0, location.href.length - 16)
+    }
+  },
   beforeMount() {
-    this.$msgCenter.publish('show-loading')
   },
   mounted() {
-    let floor = this.$route.query.floor
-    this.floor = floor
-    let sceneCode = ''
-    if (floor === "1") sceneCode = process.env.VUE_APP_SCENE_CODE_FLOOR_1
-    else if (floor === "2") sceneCode = process.env.VUE_APP_SCENE_CODE_FLOOR_2
-    console.assert(sceneCode, 'no sceneCode!')
-
-    // 不等一秒,就会因为use了小地图而卡死?
     setTimeout(() => {
+      this.canShow = true
+
+      this.$msgCenter.publish('show-loading')
+      let floor = this.$route.query.floor
+      this.floor = floor
+      let sceneCode = ''
+      if (floor === "1") sceneCode = process.env.VUE_APP_SCENE_CODE_FLOOR_1
+      else if (floor === "2") sceneCode = process.env.VUE_APP_SCENE_CODE_FLOOR_2
+      console.assert(sceneCode, 'no sceneCode!')
+
+      // 不等一秒,就会因为use了小地图而卡死?
+      // setTimeout(() => {
       let kankan = new KanKan({
         dom: ".swkk-wrap",
         num: sceneCode,
@@ -398,8 +414,8 @@ export default {
       })
 
       this.kankan = kankan
-    }, 1000)
-
+      // }, 1000)
+    }, 500)
   },
   beforeDestroy() {
     this.stopAutoMoving()