mirror of
https://gitee.com/chu1204505056/vue-admin-beautiful.git
synced 2025-04-06 03:58:00 +08:00
67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
import { storage, tokenTableName } from "@/config/settings";
|
||
import cookie from "js-cookie";
|
||
|
||
/**
|
||
* @author chuzhixin 1204505056@qq.com (不想保留author可删除)
|
||
* @description 获取accessToken
|
||
* @returns {string|ActiveX.IXMLDOMNode|Promise<any>|any|IDBRequest<any>|MediaKeyStatus|FormDataEntryValue|Function|Promise<Credential | null>}
|
||
*/
|
||
export function getAccessToken() {
|
||
if (storage) {
|
||
if ("localStorage" === storage) {
|
||
return localStorage.getItem(tokenTableName);
|
||
} else if ("sessionStorage" === storage) {
|
||
return sessionStorage.getItem(tokenTableName);
|
||
} else if ("cookie" === storage) {
|
||
return cookie.get(tokenTableName);
|
||
} else {
|
||
return localStorage.getItem(tokenTableName);
|
||
}
|
||
} else {
|
||
return localStorage.getItem(tokenTableName);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @author chuzhixin 1204505056@qq.com (不想保留author可删除)
|
||
* @description 存储accessToken
|
||
* @param accessToken
|
||
* @returns {void|*}
|
||
*/
|
||
export function setAccessToken(accessToken) {
|
||
if (storage) {
|
||
if ("localStorage" === storage) {
|
||
return localStorage.setItem(tokenTableName, accessToken);
|
||
} else if ("sessionStorage" === storage) {
|
||
return sessionStorage.setItem(tokenTableName, accessToken);
|
||
} else if ("cookie" === storage) {
|
||
return cookie.set(tokenTableName, accessToken);
|
||
} else {
|
||
return localStorage.setItem(tokenTableName, accessToken);
|
||
}
|
||
} else {
|
||
return localStorage.setItem(tokenTableName, accessToken);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @author chuzhixin 1204505056@qq.com (不想保留author可删除)
|
||
* @description 移除accessToken
|
||
* @returns {void|Promise<void>}
|
||
*/
|
||
export function removeAccessToken() {
|
||
if (storage) {
|
||
if ("localStorage" === storage) {
|
||
return localStorage.removeItem(tokenTableName);
|
||
} else if ("sessionStorage" === storage) {
|
||
return sessionStorage.clear();
|
||
} else if ("cookie" === storage) {
|
||
return cookie.remove(tokenTableName);
|
||
} else {
|
||
return localStorage.removeItem(tokenTableName);
|
||
}
|
||
} else {
|
||
return localStorage.removeItem(tokenTableName);
|
||
}
|
||
}
|