2016-05-06 23:14:40 +08:00
|
|
|
|
|
|
|
import window from 'window';
|
|
|
|
|
|
|
|
const STORAGE_KEY = '__rlA';
|
|
|
|
|
|
|
|
class RainLoopStorage
|
|
|
|
{
|
|
|
|
s = null;
|
|
|
|
t = null;
|
|
|
|
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
this.s = window.sessionStorage || null;
|
|
|
|
this.t = window.top || window;
|
|
|
|
}
|
|
|
|
|
|
|
|
getHash() {
|
|
|
|
let result = null;
|
|
|
|
if (this.s)
|
|
|
|
{
|
|
|
|
result = this.s.getItem(STORAGE_KEY) || null;
|
|
|
|
}
|
|
|
|
else if (this.t && JSON)
|
|
|
|
{
|
|
|
|
const data = this.t.name && '{' === this.t.name.toString().substr(0, 1) ? JSON.parse(this.t.name.toString()) : null;
|
|
|
|
result = data ? (data[STORAGE_KEY] || null) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
setHash() {
|
|
|
|
const
|
|
|
|
key = 'AuthAccountHash',
|
2016-05-20 08:04:15 +08:00
|
|
|
appData = window.__rlah_data()
|
2016-05-06 23:14:40 +08:00
|
|
|
;
|
|
|
|
if (this.s)
|
|
|
|
{
|
|
|
|
this.s.setItem(STORAGE_KEY, appData && appData[key] ? appData[key] : '');
|
|
|
|
}
|
|
|
|
else if (this.t && JSON)
|
|
|
|
{
|
|
|
|
let data = {};
|
|
|
|
data[STORAGE_KEY] = appData && appData[key] ? appData[key] : '';
|
|
|
|
|
|
|
|
this.t.name = JSON.stringify(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clearHash() {
|
|
|
|
if (this.s)
|
|
|
|
{
|
|
|
|
this.s.setItem(STORAGE_KEY, '');
|
|
|
|
}
|
|
|
|
else if (this.t)
|
|
|
|
{
|
|
|
|
this.t.name = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = new RainLoopStorage();
|