/* * 中間就可以進行封裝操作 * mui就代表mui,owner就代表window的app屬性,就是一個傳值 */ (function(mui,owner) { /** * 獲取當前狀態 **/ owner.getState = function() { var stateText = plus ...
/*
* 中間就可以進行封裝操作
* mui就代表mui,owner就代表window的app屬性,就是一個傳值
*/
(function(mui,owner)
{
/**
* 獲取當前狀態
**/
owner.getState = function() {
var stateText = plus.storage.getItem('$state');
if(stateText != null && stateText != undefined) {
var s = JSON.parse(stateText);
if(new Date() > new Date(s.TokenTimeOut)) {
stateText = "";
}
}
stateText = stateText || '{"ID":0,"Ticket":"","UserName":""}';
return JSON.parse(stateText);
};
/**
* 設置當前狀態
**/
owner.setState = function(state) {
state = state || {
Ticket: "",
UserName:""
//TokenTimeOut: "1970-1-1"
};
plus.storage.setItem('$state', JSON.stringify(state));
};
/**
* 獲取應用本地配置
**/
owner.setSettings = function(settings) {
settings = settings || {};
plus.storage.setItem('$settings', JSON.stringify(settings));
}
/**
* 設置應用本地配置
**/
owner.getSettings = function() {
var settingsText = plus.storage.getItem('$settings') || "{}";
return JSON.parse(settingsText);
}
}(mui, window.app = {}));
View Code
使用方法
引用JS <script src="js/api.js"></script>
//存儲緩存
var postData = {
AccountName: "管理員",
Pwd: "12345678",
Company: "bao"
};//聲明對象
app.setState(data);存儲到緩存中
//獲取緩存
var _user = app.getState();//獲取存儲對象
var Ticke = _user.Ticket //得到票據