rt-sim-training-client/src/utils/auth.js
2022-09-22 17:03:13 +08:00

46 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SessionStorage from 'sessionstorage';
import store from '@/store/index';
const TokenKey = 'Admin-Token';
// 设置教学实训仿真系统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);
}
// 操作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);
}
// 操作LocalStorage
export function getLocalStorage(key) {
const idKey = getUserIdKey(key);
return localStorage.getItem(idKey);
}
export function setLocalStorage(key, value) {
const idKey = getUserIdKey(key);
return localStorage.setItem(idKey, value);
}
export function removeLocalStorage(key) {
const idKey = getUserIdKey(key);
return localStorage.removeItem(idKey);
}
export function getUserIdKey(key) {
const id = store.state.user.id;
const idKey = `${id}_${key}`;
return idKey;
}