88 lines
2.3 KiB
JavaScript
88 lines
2.3 KiB
JavaScript
import SessionStorage from 'sessionstorage';
|
||
import { LoginParams } from '@/utils/login';
|
||
|
||
const TokenKey = 'Admin-Token';
|
||
|
||
const TokenScreenKey = 'Screen-Token';
|
||
|
||
const TokenPlanKey = 'Plan-Token';
|
||
|
||
// 设置教学,实训,仿真系统token
|
||
export function getToken() {
|
||
return SessionStorage.getItem(TokenKey);
|
||
}
|
||
export function setToken(token) {
|
||
return SessionStorage.setItem(TokenKey, token);
|
||
}
|
||
export function removeToken() {
|
||
return SessionStorage.removeItem(TokenKey);
|
||
}
|
||
// 设置大屏token
|
||
export function getScreenToken() {
|
||
return SessionStorage.getItem(TokenScreenKey);
|
||
}
|
||
export function setScreenToken(token) {
|
||
return SessionStorage.setItem(TokenScreenKey, token);
|
||
}
|
||
export function removeScreenToken() {
|
||
return SessionStorage.removeItem(TokenScreenKey);
|
||
}
|
||
|
||
// 设置琏计划token
|
||
export function getPlanToken() {
|
||
return SessionStorage.getItem(TokenPlanKey);
|
||
}
|
||
export function setPlanToken(token) {
|
||
return SessionStorage.setItem(TokenPlanKey, token);
|
||
}
|
||
export function removePlanToken() {
|
||
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);
|
||
}
|
||
|
||
// 根据路径判断获取token
|
||
export function handleToken() {
|
||
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();
|
||
}
|
||
}
|
||
|
||
// 根据路径清除token
|
||
export function handleRemoveToken() {
|
||
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();
|
||
}
|
||
}
|
||
|
||
// 根据route路径判断系统类型
|
||
export function gainClientId() {
|
||
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;
|
||
}
|
||
|
||
return clientId;
|
||
}
|