Bladeren bron

修复逻辑跳转错误

liyongli 3 jaren geleden
bovenliggende
commit
0e84609491
3 gewijzigde bestanden met toevoegingen van 65 en 63 verwijderingen
  1. 7 16
      src/components/tabs.vue
  2. 0 2
      src/main.js
  3. 58 45
      src/view/layout/index.vue

+ 7 - 16
src/components/tabs.vue

@@ -20,7 +20,6 @@
 </template>
 
 <script>
-
 import vanSticky from "vant/lib/sticky";
 import "vant/lib/sticky/style";
 export default {
@@ -44,14 +43,14 @@ export default {
   },
   computed: {
     showTitle() {
-      return (data) => {
+      return data => {
         let title = data.title;
         if (
           this.routerData.id !== data.id ||
           this.routerData.select === this.routerData.id
         )
           return title;
-        this.routerData.childList.map((v) => {
+        this.routerData.childList.map(v => {
           if (v.id == this.routerData.select) title = v.title;
         });
         return title;
@@ -63,20 +62,12 @@ export default {
   },
   methods: {
     showTabs() {
-      let title = this.$utils.getUrl("title") || "";
       let id = this.$utils.getUrl("id") || "";
-      let select =
-        this.$route.params.select >= 0 ? this.$route.params.select : undefined;
-      let isSecond =
-        this.$route.name === "secondTopic" ||
-        this.$route.name === "secondTopicIndex";
-      if (title === "" || (isSecond && !select))
-        return (this.routerData = this.topicOfConversation[0]);
-      let Data = this.topicOfConversation.find((v, i) => {
-        if (this.$route.name !== "secondTopic") return v.id == id;
-        else if (!select) return i === 0;
-        else return v.id == select;
-      }) || {};
+      let Data =
+        this.topicOfConversation.find((v, i) => {
+          if(id) return v.id == id;
+          if(!id) return i == 0;
+        }) || {};
 
       this.routerData = {
         title: Data.title,

+ 0 - 2
src/main.js

@@ -13,8 +13,6 @@ router.beforeEach((to, from, next) => {
   window.local_timeout && window.clearInterval(window.local_timeout);
   next();
 });
-let season = utils.getUrl("season")
-sessionStorage.setItem('season', season || "")
 new Vue({
   router,
   store,

+ 58 - 45
src/view/layout/index.vue

@@ -4,6 +4,7 @@
       v-if="topicOfConversation.length"
       :topicOfConversation="topicOfConversation"
       @toRouter="toRouter"
+      :key="routerKey+'/11'" 
     />
     <router-view class="basePage" :key="routerKey" />
   </div>
@@ -11,6 +12,7 @@
 
 <script>
 import { getBase } from "@/api/getList";
+import utils from "../../utils/utils";
 
 import Tabs from "../../components/tabs";
 export default {
@@ -24,59 +26,69 @@ export default {
       topicOfConversation: [],
     };
   },
-  created() {
-    let season = sessionStorage.getItem("season");
-    getBase({
-      season
-    }).then((res) => {
-      this.$store.commit("setTabList", res || []);
-      let list = [
-        {
-          title: "话题对比",
-          path: "/contrast",
-          id: -1,
-          childList: [],
-        },
-      ];
-      if(season == 2) list = [];
-      (res || []).map((v) => {
-        let childList = (v.child_list || []).map((val, i) => {
-          //   { title: "子集", path: "/topic", id: i + 1 + "-0", pId: i + 1 }
-          return {
-            title: val,
-            id: i,
-            pId: v.topic_id,
-          };
-        });
-
-        list.push({
-          title: v.alias_name,
-          real_title: v.topic_name,
-          path: "/topic",
-          id: v.topic_id,
-          childList,
-        });
-        this.topicOfConversation = list;
-      });
-      if(season == 2 && this.topicOfConversation && this.topicOfConversation.length) {
-        this.toRouter(this.topicOfConversation[0], this.topicOfConversation[0].id)
-      }else if (season == 1){
-        this.toRouter({
-          path: "/contrast"
-        })
-      }
-    });
-  },
+  created() {},
   mounted() {},
   computed: {
     routerKey() {
       let date = new Date();
-      return this.routerData.path + date.getTime();
+      let season = utils.getUrl("season");
+      let oriSeason = sessionStorage.getItem("season");
+      if(season != oriSeason || !this.topicOfConversation.length){
+        sessionStorage.setItem("season", season || 1);
+        this.init(); // 路由变化时更新tabs
+      }
+      return this.$route.name + date.getTime();
     },
   },
   methods: {
+    init() {
+      let season = sessionStorage.getItem("season");
+      getBase({
+        season,
+      }).then(res => {
+        this.$store.commit("setTabList", res || []);
+        let list = [];
+        if (season == 1)
+          list.push({
+            title: "话题对比",
+            path: "/contrast",
+            id: -1,
+            childList: [],
+          });
+        (res || []).map(v => {
+          let childList = (v.child_list || []).map((val, i) => {
+            return {
+              title: val,
+              id: i,
+              pId: v.topic_id,
+            };
+          });
+
+          list.push({
+            title: v.alias_name,
+            real_title: v.topic_name,
+            path: "/topic",
+            id: v.topic_id,
+            childList,
+          });
+          this.topicOfConversation = list;
+        });
+        if (season == 1 && this.$route.name != "contrast") {
+          this.toRouter(
+            this.topicOfConversation[0],
+            this.topicOfConversation[0].id
+          );
+        }
+        if (season == 2 && this.$route.name != "topic") {
+          this.toRouter(
+            this.topicOfConversation[0],
+            this.topicOfConversation[0].id
+          );
+        }
+      });
+    },
     toRouter(params, id) {
-      console.log(params,id)
+      let season = sessionStorage.getItem("season");
       let sonlist =
         params.childList && params.childList.length
           ? JSON.stringify(params.childList || [])
@@ -88,6 +100,7 @@ export default {
           id,
           title: params.real_title,
           sonlist,
+          season,
         },
       });
     },