mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-24 19:02:26 +08:00
feat: 完善仪表盘最近访问区块内容(来自 @Bull-BCLS)
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import {
|
||||
createRouter,
|
||||
createWebHistory,
|
||||
RouteRecordNormalized,
|
||||
} from 'vue-router';
|
||||
import { useAppStore } from '@/store';
|
||||
import NProgress from 'nprogress'; // progress bar
|
||||
import 'nprogress/nprogress.css';
|
||||
|
||||
import { DashboardRecentlyVisitedRecord } from '@/api/common/dashboard';
|
||||
import { appRoutes, fixedRoutes, demoRoutes } from './routes';
|
||||
import { REDIRECT_MAIN, NOT_FOUND_ROUTE } from './routes/base';
|
||||
import createRouteGuard from './guard';
|
||||
@@ -36,4 +42,47 @@ const router = createRouter({
|
||||
|
||||
createRouteGuard(router);
|
||||
|
||||
router.afterEach((to) => {
|
||||
const allMenuList = useAppStore().appAsyncMenusAll as RouteRecordNormalized[];
|
||||
const toMenu = allMenuList.find((m) => to.path === m.path) || undefined;
|
||||
if (toMenu === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const recentlyVisitedList = window.localStorage.getItem('recently-visited');
|
||||
let copyRecentlyVisitedList: DashboardRecentlyVisitedRecord[];
|
||||
if (recentlyVisitedList === null) {
|
||||
copyRecentlyVisitedList = [];
|
||||
} else {
|
||||
copyRecentlyVisitedList = JSON.parse(recentlyVisitedList);
|
||||
}
|
||||
|
||||
// 是否有重复点击的菜单
|
||||
copyRecentlyVisitedList.forEach(
|
||||
(item: DashboardRecentlyVisitedRecord, index: number) => {
|
||||
if (item.path === to.path) {
|
||||
copyRecentlyVisitedList.splice(index, 1);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// 最多存储 3 个
|
||||
const menuMeta = toMenu?.meta;
|
||||
const recentlyVisited: DashboardRecentlyVisitedRecord = {
|
||||
title: menuMeta?.locale,
|
||||
path: to.path,
|
||||
icon: menuMeta?.icon,
|
||||
};
|
||||
copyRecentlyVisitedList.reverse();
|
||||
copyRecentlyVisitedList.push(recentlyVisited);
|
||||
copyRecentlyVisitedList.reverse();
|
||||
if (copyRecentlyVisitedList.length >= 4) {
|
||||
copyRecentlyVisitedList = copyRecentlyVisitedList.splice(0, 3);
|
||||
}
|
||||
window.localStorage.setItem(
|
||||
'recently-visited',
|
||||
JSON.stringify(copyRecentlyVisitedList)
|
||||
);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
Reference in New Issue
Block a user