|
@@ -1,12 +1,27 @@
|
|
|
import storage from "@/core/utils/storages"
|
|
import storage from "@/core/utils/storages"
|
|
|
|
|
+import configs from "../config/Index"
|
|
|
const ID_TOKEN_KEY = "id_token" as string
|
|
const ID_TOKEN_KEY = "id_token" as string
|
|
|
const ID_TENANT_KEY = "id_tenant" as string
|
|
const ID_TENANT_KEY = "id_tenant" as string
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @description 获取令牌
|
|
* @description 获取令牌
|
|
|
*/
|
|
*/
|
|
|
-export const getToken = (): string | null => {
|
|
|
|
|
- return storage.getItem(ID_TOKEN_KEY)
|
|
|
|
|
|
|
+export const getToken = (isCheck = true): string | null | undefined => {
|
|
|
|
|
+ const arr = storage.getItem(ID_TOKEN_KEY)?.split("@@")
|
|
|
|
|
+ let token
|
|
|
|
|
+ if (arr && arr.length == 2) {
|
|
|
|
|
+ if (isCheck) {
|
|
|
|
|
+ const diff = new Date().getTime() - Number(arr[0])
|
|
|
|
|
+ const expire = configs.AUTH_EXPIRE_MINUTES * 60 * 1000
|
|
|
|
|
+ token = arr[1]
|
|
|
|
|
+ if (diff > expire) {
|
|
|
|
|
+ console.error("AUTH过期,请重新登录")
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+ saveToken(token)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return token
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -14,7 +29,7 @@ export const getToken = (): string | null => {
|
|
|
* @param token: string
|
|
* @param token: string
|
|
|
*/
|
|
*/
|
|
|
export const saveToken = (token: string): void => {
|
|
export const saveToken = (token: string): void => {
|
|
|
- storage.setItem(ID_TOKEN_KEY, token)
|
|
|
|
|
|
|
+ storage.setItem(ID_TOKEN_KEY, `${new Date().getTime()}@@${token}`)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|