|
@@ -5,6 +5,7 @@ import { findIndex } from "lodash-unified";
|
|
|
import type { StorageConfigs } from "/#/index";
|
|
|
import { useMultiTagsStoreHook } from "/@/store/modules/multiTags";
|
|
|
import { usePermissionStoreHook } from "/@/store/modules/permission";
|
|
|
+import { useNav } from "../layout/hooks/nav";
|
|
|
import {
|
|
|
Router,
|
|
|
RouteMeta,
|
|
@@ -29,7 +30,8 @@ import {
|
|
|
isUrl,
|
|
|
storageSession
|
|
|
} from "@pureadmin/utils";
|
|
|
-
|
|
|
+const { logout, onPanel, toggleSideBar, pureApp, username, avatarsStyle } =
|
|
|
+ useNav();
|
|
|
import pptRouter from "./modules/ppt";
|
|
|
import homeRouter from "./modules/home";
|
|
|
import ableRouter from "./modules/able";
|
|
@@ -131,76 +133,83 @@ router.beforeEach((to: toRouteType, _from, next) => {
|
|
|
} else {
|
|
|
// 刷新
|
|
|
if (usePermissionStoreHook().wholeMenus.length === 0)
|
|
|
- initRouter().then((router: Router) => {
|
|
|
- if (!useMultiTagsStoreHook().getMultiTagsCache) {
|
|
|
- const handTag = (
|
|
|
- path: string,
|
|
|
- parentPath: string,
|
|
|
- name: RouteRecordName,
|
|
|
- meta: RouteMeta
|
|
|
- ): void => {
|
|
|
- useMultiTagsStoreHook().handleTags("push", {
|
|
|
- path,
|
|
|
- parentPath,
|
|
|
- name,
|
|
|
- meta
|
|
|
- });
|
|
|
- };
|
|
|
- // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对静态路由)
|
|
|
- if (to.meta?.refreshRedirect) {
|
|
|
- const routes = router.options.routes;
|
|
|
- const { refreshRedirect } = to.meta;
|
|
|
- const { name, meta } = findRouteByPath(refreshRedirect, routes);
|
|
|
- handTag(
|
|
|
- refreshRedirect,
|
|
|
- getParentPaths(refreshRedirect, routes)[1],
|
|
|
- name,
|
|
|
- meta
|
|
|
- );
|
|
|
- return router.push(refreshRedirect);
|
|
|
- } else {
|
|
|
- const { path } = to;
|
|
|
- const index = findIndex(remainingRouter, v => {
|
|
|
- return v.path == path;
|
|
|
- });
|
|
|
- const routes =
|
|
|
- index === -1
|
|
|
- ? router.options.routes[0].children
|
|
|
- : router.options.routes;
|
|
|
- const route = findRouteByPath(path, routes);
|
|
|
- const routePartent = getParentPaths(path, routes);
|
|
|
- // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对动态路由)
|
|
|
- if (
|
|
|
- path !== routes[0].path &&
|
|
|
- route?.meta?.rank !== 0 &&
|
|
|
- routePartent.length === 0
|
|
|
- ) {
|
|
|
- if (!route?.meta?.refreshRedirect) return;
|
|
|
- const { name, meta } = findRouteByPath(
|
|
|
- route.meta.refreshRedirect,
|
|
|
- routes
|
|
|
- );
|
|
|
+ initRouter()
|
|
|
+ .then((router: Router) => {
|
|
|
+ console.log(router);
|
|
|
+ if (!useMultiTagsStoreHook().getMultiTagsCache) {
|
|
|
+ const handTag = (
|
|
|
+ path: string,
|
|
|
+ parentPath: string,
|
|
|
+ name: RouteRecordName,
|
|
|
+ meta: RouteMeta
|
|
|
+ ): void => {
|
|
|
+ useMultiTagsStoreHook().handleTags("push", {
|
|
|
+ path,
|
|
|
+ parentPath,
|
|
|
+ name,
|
|
|
+ meta
|
|
|
+ });
|
|
|
+ };
|
|
|
+ // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对静态路由)
|
|
|
+ if (to.meta?.refreshRedirect) {
|
|
|
+ const routes = router.options.routes;
|
|
|
+ const { refreshRedirect } = to.meta;
|
|
|
+ const { name, meta } = findRouteByPath(refreshRedirect, routes);
|
|
|
handTag(
|
|
|
- route.meta?.refreshRedirect,
|
|
|
- getParentPaths(route.meta?.refreshRedirect, routes)[0],
|
|
|
+ refreshRedirect,
|
|
|
+ getParentPaths(refreshRedirect, routes)[1],
|
|
|
name,
|
|
|
meta
|
|
|
);
|
|
|
- return router.push(route.meta?.refreshRedirect);
|
|
|
+ return router.push(refreshRedirect);
|
|
|
} else {
|
|
|
- handTag(
|
|
|
- route.path,
|
|
|
- routePartent[routePartent.length - 1],
|
|
|
- route.name,
|
|
|
- route.meta
|
|
|
- );
|
|
|
- return router.push(path);
|
|
|
+ const { path } = to;
|
|
|
+ const index = findIndex(remainingRouter, v => {
|
|
|
+ return v.path == path;
|
|
|
+ });
|
|
|
+ const routes =
|
|
|
+ index === -1
|
|
|
+ ? router.options.routes[0].children
|
|
|
+ : router.options.routes;
|
|
|
+ const route = findRouteByPath(path, routes);
|
|
|
+ const routePartent = getParentPaths(path, routes);
|
|
|
+ // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对动态路由)
|
|
|
+ if (
|
|
|
+ path !== routes[0].path &&
|
|
|
+ route?.meta?.rank !== 0 &&
|
|
|
+ routePartent.length === 0
|
|
|
+ ) {
|
|
|
+ if (!route?.meta?.refreshRedirect) return;
|
|
|
+ const { name, meta } = findRouteByPath(
|
|
|
+ route.meta.refreshRedirect,
|
|
|
+ routes
|
|
|
+ );
|
|
|
+ handTag(
|
|
|
+ route.meta?.refreshRedirect,
|
|
|
+ getParentPaths(route.meta?.refreshRedirect, routes)[0],
|
|
|
+ name,
|
|
|
+ meta
|
|
|
+ );
|
|
|
+ return router.push(route.meta?.refreshRedirect);
|
|
|
+ } else {
|
|
|
+ handTag(
|
|
|
+ route.path,
|
|
|
+ routePartent[routePartent.length - 1],
|
|
|
+ route.name,
|
|
|
+ route.meta
|
|
|
+ );
|
|
|
+ return router.push(path);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- router.push(to.fullPath);
|
|
|
- });
|
|
|
- next();
|
|
|
+ router.push(to.fullPath);
|
|
|
+ next();
|
|
|
+ })
|
|
|
+ .catch(s => {
|
|
|
+ logout();
|
|
|
+ console.log(s);
|
|
|
+ // next({ path: "/login" });
|
|
|
+ });
|
|
|
}
|
|
|
} else {
|
|
|
if (to.path !== "/login") {
|