refactor(storage): ♻️ 简化缓存管理方式,统一使用Storage类直接操作token和缓存

This commit is contained in:
Ray.Hao
2025-05-19 14:09:46 +08:00
parent a6d76d17d8
commit 2a3d2543ee
10 changed files with 71 additions and 47 deletions

View File

@@ -1,6 +1,7 @@
import type { NavigationGuardNext, RouteLocationNormalized, RouteRecordRaw } from "vue-router";
import NProgress from "@/utils/nprogress";
import { getAccessToken } from "@/utils/auth";
import { Storage } from "@/utils/storage";
import { ACCESS_TOKEN_KEY } from "@/constants/cache-keys";
import router from "@/router";
import { usePermissionStore, useUserStore } from "@/store";
@@ -11,7 +12,7 @@ export function setupPermission() {
router.beforeEach(async (to, from, next) => {
NProgress.start();
const isLogin = !!getAccessToken(); // 判断是否登录
const isLogin = !!Storage.get(ACCESS_TOKEN_KEY, ""); // 判断是否登录
if (isLogin) {
if (to.path === "/login") {
// 已登录,访问登录页,跳转到首页