/*
  * 中间就可以进行封装操作
  * 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 //得到票据

posted on 2018-12-04 17:55  asp恒心  阅读(2308)  评论(0编辑  收藏  举报