From ba20e7a96be0896fd8effd13e15f8af9d6cfb050 Mon Sep 17 00:00:00 2001 From: v_zhangzp Date: Thu, 31 Aug 2023 17:03:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=96=B9=E6=B3=95Date.now()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/auth/token.js | 2 +- src/utils/storage/storage.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/auth/token.js b/src/utils/auth/token.js index 463d54d..348df18 100644 --- a/src/utils/auth/token.js +++ b/src/utils/auth/token.js @@ -23,7 +23,7 @@ export async function refreshAccessToken() { } const { time } = tokenItem // token生成或者刷新后30分钟内不执行刷新 - if (new Date().getTime() - time <= 1000 * 60 * 30) return + if (Date.now() - time <= 1000 * 60 * 30) return try { const res = await api.refreshToken() setToken(res.data.token) diff --git a/src/utils/storage/storage.js b/src/utils/storage/storage.js index c59f971..9a15345 100644 --- a/src/utils/storage/storage.js +++ b/src/utils/storage/storage.js @@ -14,7 +14,7 @@ class Storage { const stringData = JSON.stringify({ value, time: Date.now(), - expire: !isNullOrUndef(expire) ? new Date().getTime() + expire * 1000 : null, + expire: !isNullOrUndef(expire) ? Date.now() + expire * 1000 : null, }) this.storage.setItem(this.getKey(key), stringData) } @@ -30,7 +30,7 @@ class Storage { try { const data = JSON.parse(val) const { value, time, expire } = data - if (isNullOrUndef(expire) || expire > new Date().getTime()) { + if (isNullOrUndef(expire) || expire > Date.now()) { return { value, time } } this.remove(key)