1
0
Pārlūkot izejas kodu

修复菜单切换后刷新页面展示错误

baiyanting 1 gadu atpakaļ
vecāks
revīzija
f318327686
4 mainītis faili ar 125 papildinājumiem un 66 dzēšanām
  1. 8 0
      src/store/index.js
  2. 36 8
      src/views/layout/Header.vue
  3. 50 33
      src/views/layout/HeaderD.vue
  4. 31 25
      src/views/layout/Menu.vue

+ 8 - 0
src/store/index.js

@@ -14,6 +14,7 @@ const state = {
   menuData: [],
   windturbineMap: {},
   moudleName: localStorage.getItem("ModuleName") || "",
+  activeIndex: localStorage.getItem("activeIndex") || "0",
   isFixed: JSON.parse(localStorage.getItem("isFixed")) || true,
   boosterList: localStorage.getItem("boosterList")
     ? JSON.parse(localStorage.getItem("boosterList"))
@@ -158,6 +159,9 @@ const mutations = {
   changeModuleName(state, newData) {
     state.moudleName = newData;
   },
+  changeActiveIndex(state, newData) {
+    state.activeIndex = newData;
+  },
   changeMenuState(state) {
     state.menuState++;
   },
@@ -180,6 +184,10 @@ const actions = {
     context.commit("changeModuleName", str);
     localStorage.setItem("ModuleName", str);
   },
+  changeActiveIndex(context, str) {
+    context.commit("changeActiveIndex", str);
+    localStorage.setItem("activeIndex", str);
+  },
   changeMenuState(state, data) {
     context.commit("changeMenuState");
   },

+ 36 - 8
src/views/layout/Header.vue

@@ -38,7 +38,18 @@
           </template>
         </el-dropdown>
       </li>
-      <li class="header-menu-user-title"></li>
+      <li class="header-menu-user-title">
+        <el-tooltip
+          effect="dark"
+          content="后台管理系统"
+          placement="bottom"
+          popper-class="admin-set-tooltip"
+        >
+          <i class="svg-icon svg-icon-white svg-icon-sm" @click="goToAdmin">
+            <SvgIcon svgid="svg-admin-set"></SvgIcon>
+          </i>
+        </el-tooltip>
+      </li>
     </ul>
   </div>
 </template>
@@ -119,6 +130,11 @@ export default {
     };
   },
   components: { SvgIcon },
+  created() {
+    if (this.$store.state.activeIndex || this.$store.state.activeIndex == 0) {
+      this.activeIndex = Number(this.$store.state.activeIndex);
+    }
+  },
   mounted() {
     // let that = this;
     // $(document).keydown((event) => {
@@ -204,6 +220,7 @@ export default {
       } else if (data.id === "home") {
         this.$emit("changeShowSisView", true);
         this.activeIndex = index;
+        this.$store.dispatch("changeActiveIndex", index);
         this.$router.push(data.path);
         const ActiveModule = this.currMenu.find((ele) => {
           return ele.path === data.path;
@@ -213,7 +230,9 @@ export default {
         }
         return;
       }
+      this.$emit("changeShowSisView", false);
       this.activeIndex = index;
+      this.$store.dispatch("changeActiveIndex", index);
       this.$router.push(data.path);
       const ActiveModule = this.currMenu.find((ele) => {
         return ele.path === data.path;
@@ -262,15 +281,24 @@ export default {
     $route: {
       handler: function (val, oldVal) {
         if (this.currMenu.length) {
-          this.currMenu.some((t, index) => {
+          //   this.currMenu.some((t, index) => {
+          //     if (val.path.includes(t.id)) {
+          //       this.activeIndex = index;
+          //       this.$store.dispatch("changeActiveIndex", index);
+          //       const ActiveModule = this.currMenu.find((ele) => {
+          //         return ele.path === t.path;
+          //       });
+          //       if (ActiveModule) {
+          //         this.$store.dispatch("changeModuleName", ActiveModule.text);
+          //       }
+          //     }
+          //   });
+          this.currMenu.forEach((t, index) => {
             if (val.path.includes(t.id)) {
               this.activeIndex = index;
-              const ActiveModule = this.currMenu.find((ele) => {
-                return ele.path === t.path;
-              });
-              if (ActiveModule) {
-                this.$store.dispatch("changeModuleName", ActiveModule.text);
-              }
+              this.$store.dispatch("changeActiveIndex", index);
+              this.$emit("changeShowSisView", t.path == "/home" ? true : false);
+              this.$store.dispatch("changeModuleName", t.text);
             }
           });
         }

+ 50 - 33
src/views/layout/HeaderD.vue

@@ -89,6 +89,13 @@ export default {
           path: "/health",
           isActive: false,
         },
+        {
+          id: "powerGenerating",
+          text: "发电能力分析",
+          // path: '/sandtable',
+          path: "/powerGenerating",
+          isActive: false,
+        },
         // {
         //   id: "decision",
         //   text: "决策支持",
@@ -130,6 +137,11 @@ export default {
   },
   components: { SvgIcon },
   mounted() {},
+  created() {
+    if (this.$store.state.activeIndex || this.$store.state.activeIndex == 0) {
+      this.activeIndex = Number(this.$store.state.activeIndex);
+    }
+  },
   computed: {
     userName() {
       return getCookie("username") || this.$store.state.user.username;
@@ -156,11 +168,11 @@ export default {
         //   text: "综合报警",
         //   path: "",
         // });
-        currMenu.splice(5, 0, {
-          id: "fdfx",
-          text: "发电能力分析",
-          path: "",
-        });
+        // currMenu.splice(5, 0, {
+        //   id: "fdfx",
+        //   text: "发电能力分析",
+        //   path: "",
+        // });
         // currMenu.push();
         return currMenu;
       } else {
@@ -170,29 +182,30 @@ export default {
   },
   methods: {
     click(index, data) {
-      if (data.id === "zhbj") {
-        let jiami = encrypt(getCookie("jiami")).replace(/\+/g, " ");
+      //   if (data.id === "zhbj") {
+      //     let jiami = encrypt(getCookie("jiami")).replace(/\+/g, " ");
 
-        // let url = `http://192.168.1.117:3002/#/check?username=${getCookie(
-        //   "username"
-        // )}&jiami=${jiami}`;
-        let url = `http://10.81.3.154:8083/#/check?username=${getCookie(
-          "username"
-        )}&jiami=${jiami}`;
-        window.open(url);
-        return;
-      } else if (data.id === "fdfx") {
-        let jiami = encrypt(getCookie("jiami")).replace(/\+/g, " ");
+      //     // let url = `http://192.168.1.117:3002/#/check?username=${getCookie(
+      //     //   "username"
+      //     // )}&jiami=${jiami}`;
+      //     let url = `http://10.81.3.154:8083/#/check?username=${getCookie(
+      //       "username"
+      //     )}&jiami=${jiami}`;
+      //     window.open(url);
+      //     return;
+      //   } else if (data.id === "fdfx") {
+      //     let jiami = encrypt(getCookie("jiami")).replace(/\+/g, " ");
 
-        // let url = `http://192.168.1.117:3002/#/check?username=${getCookie(
-        //   "username"
-        // )}&jiami=${jiami}`;
-        let url = `http://10.81.3.155:8083/dlfx/#/check?username=${getCookie(
-          "username"
-        )}&jiami=${jiami}`;
-        window.open(url);
-        return;
-      } else if (data.id === "stateMonitor") {
+      //     // let url = `http://192.168.1.117:3002/#/check?username=${getCookie(
+      //     //   "username"
+      //     // )}&jiami=${jiami}`;
+      //     let url = `http://10.81.3.155:8083/dlfx/#/check?username=${getCookie(
+      //       "username"
+      //     )}&jiami=${jiami}`;
+      //     window.open(url);
+      //     return;
+      //   } else
+      if (data.id === "stateMonitor") {
         this.$emit("changeShowSisView", false);
         this.menuUrl = "/stateMonitor/factoryMonitor/windPowerPlant/windhome";
       } else if (data.id === "integratedAlarm") {
@@ -205,8 +218,15 @@ export default {
       } else if (data.id === "health") {
         this.$emit("changeShowSisView", false);
         this.menuUrl = "/health/healthManagement/first";
+      } else if (data.id === "powerGenerating") {
+        this.$emit("changeShowSisView", false);
+        this.menuUrl = "/powerGenerating/dataFilter/prepare";
+      } else if (data.id === "home") {
+        this.$emit("changeShowSisView", true);
+        this.menuUrl = "/home";
       }
       this.activeIndex = index;
+      this.$store.dispatch("changeActiveIndex", index);
       this.$router.push(this.menuUrl);
       const ActiveModule = this.currMenu.find((ele) => {
         return ele.path === data.path;
@@ -254,15 +274,12 @@ export default {
     $route: {
       handler: function (val, oldVal) {
         if (this.currMenu.length) {
-          this.currMenu.some((t, index) => {
+          this.currMenu.forEach((t, index) => {
             if (val.path.includes(t.id)) {
               this.activeIndex = index;
-              const ActiveModule = this.currMenu.find((ele) => {
-                return ele.path === t.path;
-              });
-              if (ActiveModule) {
-                this.$store.dispatch("changeModuleName", ActiveModule.text);
-              }
+              this.$store.dispatch("changeActiveIndex", index);
+              this.$emit("changeShowSisView", t.path == "/home" ? true : false);
+              this.$store.dispatch("changeModuleName", t.text);
             }
           });
         }

+ 31 - 25
src/views/layout/Menu.vue

@@ -275,7 +275,7 @@ export default {
     },
     fillterMenuRoutes,
     click(index) {
-    //   this.reFresh = false;
+      //   this.reFresh = false;
       this.activeIndex = index;
       this.subIndex = index + "" + 0;
     },
@@ -296,7 +296,13 @@ export default {
       this.isShowSubMenu = false;
     },
   },
-
+  created() {
+    if (this.$store.state.moudleName) {
+      this.currRoot = this.menuData.find(
+        (i) => i.text == this.$store.state.moudleName
+      )?.id;
+    }
+  },
   computed: {
     currentMenu() {
       let stateRoutes = JSON.parse(
@@ -389,33 +395,33 @@ export default {
     $route: {
       handler: function (val, oldVal) {
         // if (this.reFresh) {
-          this.menuData.some((element, index) => {
-            if (val.path.includes(element.id)) {
+        this.menuData.some((element, index) => {
+          if (val.path.includes(element.id)) {
+            this.$nextTick(() => {
+              this.currRoot = element.id;
               this.$nextTick(() => {
-                this.currRoot = element.id;
-                this.$nextTick(() => {
-                  this.currentMenu.forEach((element, index) => {
-                    if (val.path.includes(element.fullPath)) {
-                      this.activeIndex = index;
-                      element.children &&
-                        element.children.forEach((i, inx) => {
-                          if (val.path == i.path) {
-                            this.subIndex = index + "" + inx;
-                          }
-                        });
-                      return true;
-                    }
-                  });
+                this.currentMenu.forEach((element, index) => {
+                  if (val.path.includes(element.fullPath)) {
+                    this.activeIndex = index;
+                    element.children &&
+                      element.children.forEach((i, inx) => {
+                        if (val.path == i.path) {
+                          this.subIndex = index + "" + inx;
+                        }
+                      });
+                    return true;
+                  }
                 });
               });
-              return true;
-            }
-          });
-          if (val.path.includes("/home")) {
-            this.currRoot = "home";
-            this.activeIndex = 0;
-            return;
+            });
+            return true;
           }
+        });
+        if (val.path.includes("/home")) {
+          this.currRoot = "home";
+          this.activeIndex = 0;
+          return;
+        }
         // }
         // this.reFresh = true;
         const someRes = this.rePagePath.some((path) => {