2019-07-05 10:18:17 +08:00
|
|
|
|
import SessionStorage from 'sessionstorage';
|
2019-07-02 16:29:52 +08:00
|
|
|
|
import { LoginParams } from '@/utils/login';
|
|
|
|
|
|
|
|
|
|
const TokenKey = 'Admin-Token';
|
|
|
|
|
|
|
|
|
|
const TokenScreenKey = 'Screen-Token';
|
|
|
|
|
|
|
|
|
|
const TokenPlanKey = 'Plan-Token';
|
|
|
|
|
|
|
|
|
|
// 设置教学,实训,仿真系统token
|
|
|
|
|
export function getToken() {
|
2019-07-31 18:24:28 +08:00
|
|
|
|
return SessionStorage.getItem(TokenKey);
|
2019-07-02 16:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
export function setToken(token) {
|
2019-07-31 18:24:28 +08:00
|
|
|
|
return SessionStorage.setItem(TokenKey, token);
|
2019-07-02 16:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
export function removeToken() {
|
2019-07-31 18:24:28 +08:00
|
|
|
|
return SessionStorage.removeItem(TokenKey);
|
2019-07-02 16:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
// 设置大屏token
|
|
|
|
|
export function getScreenToken() {
|
2019-07-31 18:24:28 +08:00
|
|
|
|
return SessionStorage.getItem(TokenScreenKey);
|
2019-07-02 16:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
export function setScreenToken(token) {
|
2019-07-31 18:24:28 +08:00
|
|
|
|
return SessionStorage.setItem(TokenScreenKey, token);
|
2019-07-02 16:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
export function removeScreenToken() {
|
2019-07-31 18:24:28 +08:00
|
|
|
|
return SessionStorage.removeItem(TokenScreenKey);
|
2019-07-02 16:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置琏计划token
|
|
|
|
|
export function getPlanToken() {
|
2019-07-31 18:24:28 +08:00
|
|
|
|
return SessionStorage.getItem(TokenPlanKey);
|
2019-07-02 16:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
export function setPlanToken(token) {
|
2019-07-31 18:24:28 +08:00
|
|
|
|
return SessionStorage.setItem(TokenPlanKey, token);
|
2019-07-02 16:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
export function removePlanToken() {
|
2019-07-31 18:24:28 +08:00
|
|
|
|
return SessionStorage.removeItem(TokenPlanKey);
|
|
|
|
|
}
|
|
|
|
|
// 操作sessionStorage
|
|
|
|
|
export function getSessionStorage(key) {
|
|
|
|
|
return SessionStorage.getItem(key);
|
|
|
|
|
}
|
|
|
|
|
export function setSessionStorage(key, value) {
|
|
|
|
|
return SessionStorage.setItem(key, value);
|
|
|
|
|
}
|
|
|
|
|
export function removeSessionStorage(key) {
|
|
|
|
|
return SessionStorage.removeItem(key);
|
2019-07-02 16:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据路径判断获取token
|
|
|
|
|
export function handleToken() {
|
2019-07-31 18:24:28 +08:00
|
|
|
|
const path = window.location.href;
|
|
|
|
|
if (path.includes('/dp/') || path.includes('/display/dp')) {
|
|
|
|
|
return getScreenToken();
|
|
|
|
|
} else if (path.includes('/plan') || path.includes('/display/plan')) {
|
|
|
|
|
return getPlanToken();
|
|
|
|
|
} else {
|
|
|
|
|
return getToken();
|
|
|
|
|
}
|
2019-07-02 16:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据路径清除token
|
|
|
|
|
export function handleRemoveToken() {
|
2019-07-31 18:24:28 +08:00
|
|
|
|
const path = window.location.href;
|
|
|
|
|
if (path.includes('/dp/') || path.includes('/display/dp')) {
|
|
|
|
|
return removeScreenToken();
|
|
|
|
|
} else if (path.includes('/plan') || path.includes('/display/plan')) {
|
|
|
|
|
return removePlanToken();
|
|
|
|
|
} else {
|
|
|
|
|
return removeToken();
|
|
|
|
|
}
|
2019-07-02 16:29:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据route路径判断系统类型
|
|
|
|
|
export function gainClientId() {
|
2019-07-31 18:24:28 +08:00
|
|
|
|
const path = window.location.href;
|
|
|
|
|
let clientId = null;
|
|
|
|
|
if (path.includes('/dp/') || path.includes('/display/dp')) {
|
|
|
|
|
clientId = LoginParams.DaPing.clientId;
|
|
|
|
|
} else if (path.includes('/plan') || path.includes('/display/plan')) {
|
|
|
|
|
clientId = LoginParams.LianJiHua.clientId;
|
|
|
|
|
}
|
2019-07-02 16:29:52 +08:00
|
|
|
|
|
2019-07-31 18:24:28 +08:00
|
|
|
|
return clientId;
|
2019-07-05 10:18:17 +08:00
|
|
|
|
}
|