fix(tag): 删除非当前激活tag时不切换tag (#60)

* fix(tag): 删除非当前激活tag时不切换tag

* fix(tag): 修复在激活菜单时选择关闭左侧标签后当前激活的菜单非选择菜单

* perf: 自定义去重函数更改为lodash-es的uniqBy
This commit is contained in:
Ten-K 2021-10-19 13:58:17 +08:00 committed by GitHub
parent b2c05e4397
commit 639a69d579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 8 deletions

View File

@ -174,9 +174,6 @@ function deleteDynamicTag(obj: any, current: any, tag?: string) {
routerArrays.splice(start, end);
relativeStorage.routesInStorage = routerArrays;
}
router.push(obj.path);
//
handleAliveRoute(route.matched, "delete");
};
if (tag === "other") {
@ -189,15 +186,32 @@ function deleteDynamicTag(obj: any, current: any, tag?: string) {
//
spliceRoute(valueIndex, 1);
}
if (current === obj.path) {
let newRoute: any = routerArrays.slice(-1);
if (current === route.path) {
//
handleAliveRoute(route.matched, "delete");
// tagtag
let newRoute: any = routerArrays.slice(-1);
if (tag === "left") return;
nextTick(() => {
router.push({
path: newRoute[0].path
});
});
} else {
//
let oldPath = route.path;
router.push(obj.path);
//
handleAliveRoute(route.matched, "delete");
if (!routerArrays.length) return;
let isHasOldPath = routerArrays.some(item => {
return item.path === oldPath;
});
isHasOldPath
? router.push(oldPath)
: router.push({
path: newRoute[0].path
});
}
}

View File

@ -5,7 +5,7 @@ import {
createWebHashHistory,
RouteRecordNormalized
} from "vue-router";
import { split } from "lodash-es";
import { split, uniqBy } from "lodash-es";
import { i18n } from "/@/plugins/i18n";
import { openLink } from "/@/utils/link";
import NProgress from "/@/utils/progress";
@ -228,7 +228,10 @@ router.beforeEach((to, _from, next) => {
}
});
});
storageLocal.setItem("responsive-routesInStorage", newLocalRoutes);
storageLocal.setItem(
"responsive-routesInStorage",
uniqBy(newLocalRoutes, "path")
);
});
next();
}