//函数封装过期控制代码 根据时间控制缓存
function setSession(key, value) {
var curTime = new Date().getTime();
window.sessionStorage.setItem(key, JSON.stringify({
data: value,
time: curTime
}));
}
function getSession(key, exp) {
var data = window.sessionStorage.getItem(key);
var dataObj = JSON.parse(data);
if (dataObj != null) {
if (new Date().getTime() - dataObj.time > exp) {
console.log('信息已过期');
} else {
var dataObjDatatoJson = dataObj.data;
return dataObjDatatoJson;
}
}
}