Pārlūkot izejas kodu

:bug: 修复路由出现404的问题

smallchill 5 gadi atpakaļ
vecāks
revīzija
9ec5d8506a

+ 1 - 3
src/page/index/sidebar/index.vue

@@ -33,7 +33,7 @@
       return {};
     },
     created() {
-      this.index.openMenu(this.menuId);
+      this.index.openMenu();
     },
     computed: {
       ...mapGetters(["website", "menu", "tag", "keyCollapse", "screen", "menuId"]),
@@ -41,8 +41,6 @@
         return this.$router.$avueRouter.getValue(this.$route);
       }
     },
-    mounted() {
-    },
     methods: {}
   };
 </script>

+ 1 - 8
src/router/avue-router.js

@@ -26,7 +26,6 @@ RouterPlugin.install = function (vue, option = {}) {
   this.$router.$avueRouter = {
     //全局配置
     $website: this.$store.getters.website,
-    routerList: [],
     group: '',
     meta: {},
     safe: this,
@@ -110,8 +109,6 @@ RouterPlugin.install = function (vue, option = {}) {
       for (let i = 0; i < aMenu.length; i++) {
         // 取到当前要处理的一项
         const oMenu = aMenu[i];
-        // 判断this.routerList中是否已经存在该path,存在就跳出
-        if (this.routerList.includes(oMenu[propsDefault.path])) return;
         // 这一块的赋值 也就是取到返回的值
         let path = (() => {
             if (first) {
@@ -191,11 +188,7 @@ RouterPlugin.install = function (vue, option = {}) {
       // for循环结束
       // 这个first 卡的其实就是首路由
       if (first) {
-        window.console.log(aRouter)
-        if (!this.routerList.includes(aRouter[0][propsDefault.path])) {
-          this.safe.$router.addRoutes(aRouter)
-          this.routerList.push(aRouter[0][propsDefault.path])
-        }
+        this.safe.$router.addRoutes(aRouter)
       } else {
         // 这里返回的是子组件
         return aRouter

+ 16 - 27
src/store/modules/user.js

@@ -38,8 +38,8 @@ const user = {
     userInfo: getStore({name: 'userInfo'}) || [],
     permission: getStore({name: 'permission'}) || {},
     roles: [],
+    menuId: {},
     menu: getStore({name: 'menu'}) || [],
-    menuId: getStore({name: 'menuId'}) || [],
     menuAll: getStore({name: 'menuAll'}) || [],
     token: getStore({name: 'token'}) || '',
     refreshToken: getStore({name: 'refreshToken'}) || '',
@@ -134,8 +134,7 @@ const user = {
         logout().then(() => {
           commit('SET_TOKEN', '');
           commit('SET_MENU', []);
-          commit('SET_MENU_ID', {});
-          commit('SET_MENU_ALL', []);
+          commit('SET_MENU_ALL_NULL', []);
           commit('SET_ROLES', []);
           commit('SET_TAG_LIST', []);
           commit('DEL_ALL_TAG');
@@ -152,8 +151,7 @@ const user = {
     FedLogOut({commit}) {
       return new Promise(resolve => {
         commit('SET_TOKEN', '');
-        commit('SET_MENU_ID', {});
-        commit('SET_MENU_ALL', []);
+        commit('SET_MENU_ALL_NULL', []);
         commit('SET_MENU', []);
         commit('SET_ROLES', []);
         commit('SET_TAG_LIST', []);
@@ -208,33 +206,24 @@ const user = {
     },
     SET_MENU_ID(state, menuId) {
       state.menuId = menuId;
-      setStore({name: 'menuId', content: state.menuId})
     },
     SET_MENU_ALL: (state, menuAll) => {
-      state.menuAll = menuAll
-      setStore({name: 'menuAll', content: state.menuAll})
+      let menu = state.menuAll;
+      menuAll.forEach(ele => {
+        if (!menu.find(item => item.label === ele.label && item.path === ele.path)) {
+          menu.push(ele);
+        }
+      })
+      state.menuAll = menu
+      setStore({ name: 'menuAll', content: state.menuAll })
+    },
+    SET_MENU_ALL_NULL: (state) => {
+      state.menuAll = []
+      setStore({ name: 'menuAll', content: state.menuAll })
     },
     SET_MENU: (state, menu) => {
       state.menu = menu
-      setStore({name: 'menu', content: state.menu})
-      if (validatenull(menu)) return;
-      //合并动态路由去重
-      let menuAll = state.menuAll;
-      menuAll = menuAll.concat(menu).reverse();
-      let newMenu = [];
-      for (let item1 of menuAll) {
-        let flag = true;
-        for (let item2 of newMenu) {
-          if (item1.name === item2.name || item1.path === item2.path) {
-            flag = false;
-          }
-        }
-        if (flag) {
-          newMenu.push(item1);
-        }
-      }
-      state.menuAll = newMenu;
-      setStore({name: 'menuAll', content: state.menuAll})
+      setStore({ name: 'menu', content: state.menu })
     },
     SET_REFRESH_TOKEN: (state, refreshToken) => {
       setRefreshToken(refreshToken)