refactor(storage): ♻️ 简化缓存管理方式,统一使用Storage类直接操作token和缓存
This commit is contained in:
@@ -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") {
|
||||
// 已登录,访问登录页,跳转到首页
|
||||
|
||||
0
src/plugins/permission.ts.bak
Normal file
0
src/plugins/permission.ts.bak
Normal file
@@ -1,5 +1,6 @@
|
||||
import { useDictSync } from "@/hooks/websocket/services/useDictSync";
|
||||
import { getAccessToken } from "@/utils/auth";
|
||||
import { Storage } from "@/utils/storage";
|
||||
import { ACCESS_TOKEN_KEY } from "@/constants/cache-keys";
|
||||
|
||||
// 用于防止重复初始化的状态标记
|
||||
let isInitialized = false;
|
||||
@@ -24,7 +25,7 @@ export function setupWebSocket() {
|
||||
}
|
||||
|
||||
// 检查token是否存在
|
||||
const token = getAccessToken();
|
||||
const token = Storage.get(ACCESS_TOKEN_KEY, "");
|
||||
if (!token) {
|
||||
console.warn(
|
||||
"[WebSocketPlugin] 未找到访问令牌,WebSocket初始化已跳过。用户登录后将自动重新连接。"
|
||||
|
||||
Reference in New Issue
Block a user