Bladeren bron

修改路由bug

huangbin 4 jaren geleden
bovenliggende
commit
086d0d5dc9
2 gewijzigde bestanden met toevoegingen van 30 en 23 verwijderingen
  1. 1 1
      src/layout/components/menu.vue
  2. 29 22
      src/layout/components/top.vue

+ 1 - 1
src/layout/components/menu.vue

@@ -99,7 +99,7 @@ export default defineComponent({
                     secondeIndex = 0;
                 for (let i = 0; i < list.length; i++) {
                     for (let j = 0; j < list[i].children.length; j++) {
-                        if (window.location.hash.includes(list[i].children[j].code)) {
+                        if (window.location.hash === list[i].children[j].code) {
                             firstIndex = i;
                             secondeIndex = j;
                             break;

+ 29 - 22
src/layout/components/top.vue

@@ -1,32 +1,31 @@
 <template>
-    <a-layout class="layout-top">
-        <a-layout-header class="m-layout-header">
-            <Header />
-        </a-layout-header>
-        <a-layout class="middleLayout">
-            <a-layout-sider
-                class="m-layout-left"
-                width="180"
-                v-model:collapsed="collapsed"
-                @collapse="collapse"
-                collapsible
-            >
-                <Menu @chooseMenu="chooseMenu" :collapsed="collapsed" />
-            </a-layout-sider>
-            <a-layout-content :style="{ background: '#0E0E0F', flex: 1 }">
-                <!-- <Drawer :title="'挂牌'" :visible="visible"></Drawer> -->
-                <!-- <Main /> -->
-                <router-view />
-            </a-layout-content>
-        </a-layout>
+  <a-layout class="layout-top">
+    <a-layout-header class="m-layout-header">
+      <Header />
+    </a-layout-header>
+    <a-layout class="middleLayout">
+      <a-layout-sider class="m-layout-left"
+                      width="180"
+                      v-model:collapsed="collapsed"
+                      @collapse="collapse"
+                      collapsible>
+        <Menu @chooseMenu="chooseMenu"
+              :collapsed="collapsed" />
+      </a-layout-sider>
+      <a-layout-content :style="{ background: '#0E0E0F', flex: 1 }">
+        <!-- <Drawer :title="'挂牌'" :visible="visible"></Drawer> -->
+        <!-- <Main /> -->
+        <router-view />
+      </a-layout-content>
     </a-layout>
+  </a-layout>
 </template>
 <script lang="ts">
 import { defineComponent, ref, provide } from 'vue';
 
 import CapitalInfo from '@/common/components/capitalInfo/index.vue';
 import SecondMenu from '@/common/components/secondeMenu/index.vue';
-import { useRouter } from 'vue-router';
+import { useRoute, useRouter } from 'vue-router';
 import Drawer from '@/common/components/drawer/index.vue';
 import Header from './header.vue';
 import Menu from './menu.vue';
@@ -45,6 +44,7 @@ export default defineComponent({
     },
     setup(props, context) {
         const router = useRouter();
+        const route = useRoute();
         const list = ref<OperationTabMenu[]>([]); // 右边tab栏 需要的列表数据
         const index = ref<string[]>(['0']); // 右边tab栏 具体选中的哪一个数据 默认第一个
         // 配置是否显示下半部分
@@ -55,7 +55,14 @@ export default defineComponent({
         }
         // 选中菜单
         function chooseMenu(value: OperationTabMenu) {
-            const temp = router.currentRoute.value.name;
+            const matched = route.matched;
+            const len = matched.length;
+            let temp = 'home';
+            if (matched.length > 2) {
+                temp = matched[2].name as string;
+            } else {
+                temp = matched[len - 1].name as string;
+            }
             let name = temp;
             if (temp === 'home') {
                 // 第一次进入项目