|
@@ -1,7 +1,9 @@
|
|
|
+import Cookies from 'js-cookie';
|
|
|
+
|
|
|
const TokenKey = 'GCLS_Token';
|
|
|
|
|
|
export function getSessionID() {
|
|
|
- const token = localStorage.getItem(TokenKey);
|
|
|
+ const token = Cookies.get(TokenKey) || sessionStorage.getItem(TokenKey) || localStorage.getItem(TokenKey);
|
|
|
if (token) {
|
|
|
return JSON.parse(token)['session_id'];
|
|
|
}
|
|
@@ -9,7 +11,7 @@ export function getSessionID() {
|
|
|
}
|
|
|
|
|
|
export function getToken() {
|
|
|
- const token = localStorage.getItem(TokenKey);
|
|
|
+ const token = Cookies.get(TokenKey) || sessionStorage.getItem(TokenKey) || localStorage.getItem(TokenKey);
|
|
|
if (token) {
|
|
|
return { token: JSON.parse(token), isHas: true };
|
|
|
}
|
|
@@ -19,17 +21,21 @@ export function getToken() {
|
|
|
export function setToken(token) {
|
|
|
const _token = typeof token === 'object' ? JSON.stringify(token) : '';
|
|
|
localStorage.setItem(TokenKey, _token);
|
|
|
+ sessionStorage.setItem(TokenKey, _token);
|
|
|
+ Cookies.set(TokenKey, _token);
|
|
|
}
|
|
|
|
|
|
export function removeToken() {
|
|
|
localStorage.removeItem(TokenKey);
|
|
|
+ sessionStorage.removeItem(TokenKey);
|
|
|
+ Cookies.remove(TokenKey);
|
|
|
}
|
|
|
|
|
|
// 系统信息
|
|
|
const ConfigKey = 'GCLS_Config';
|
|
|
|
|
|
export function getConfig() {
|
|
|
- const token = localStorage.getItem(ConfigKey);
|
|
|
+ const token = Cookies.get(ConfigKey) || sessionStorage.getItem(ConfigKey) || localStorage.getItem(ConfigKey);
|
|
|
if (token) {
|
|
|
return { token: JSON.parse(token), isHas: true };
|
|
|
}
|
|
@@ -39,8 +45,12 @@ export function getConfig() {
|
|
|
export function setConfig(value) {
|
|
|
let _val = typeof value === 'object' ? JSON.stringify(value) : '';
|
|
|
localStorage.setItem(ConfigKey, _val);
|
|
|
+ sessionStorage.setItem(ConfigKey, _val);
|
|
|
+ Cookies.set(ConfigKey, _val);
|
|
|
}
|
|
|
|
|
|
export function removeConfig() {
|
|
|
localStorage.removeItem(ConfigKey);
|
|
|
+ sessionStorage.removeItem(ConfigKey);
|
|
|
+ Cookies.remove(ConfigKey);
|
|
|
}
|