rt-sim-training-client/src/utils/auth.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-07-05 10:18:17 +08:00
import SessionStorage from 'sessionstorage';
2022-09-22 17:03:13 +08:00
import store from '@/store/index';
2019-07-02 16:29:52 +08:00
const TokenKey = 'Admin-Token';
2019-09-23 17:47:54 +08:00
2019-11-14 13:59:33 +08:00
// 设置教学实训仿真系统token, 设置城市轨道交通设计平台token
2019-07-02 16:29:52 +08:00
export function getToken() {
2019-11-05 16:40:36 +08:00
return SessionStorage.getItem(TokenKey);
2019-07-02 16:29:52 +08:00
}
export function setToken(token) {
2019-11-05 16:40:36 +08:00
return SessionStorage.setItem(TokenKey, token);
2019-07-02 16:29:52 +08:00
}
export function removeToken() {
2019-11-05 16:40:36 +08:00
return SessionStorage.removeItem(TokenKey);
2019-07-02 16:29:52 +08:00
}
// 操作sessionStorage
export function getSessionStorage(key) {
2019-11-05 16:40:36 +08:00
return SessionStorage.getItem(key);
}
export function setSessionStorage(key, value) {
2019-11-05 16:40:36 +08:00
return SessionStorage.setItem(key, value);
}
export function removeSessionStorage(key) {
2019-11-05 16:40:36 +08:00
return SessionStorage.removeItem(key);
2019-07-02 16:29:52 +08:00
}
2022-09-22 17:03:13 +08:00
// 操作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;
}