使用JavaScript定义一个微信小程序插件样例

var wxTimer = new wxTimer({
  beginTime: "00:00:20",
  complete: function () {
    wx.redirectTo({
      url: './game'
    })
  }
})

wxTimer.start(this);

-----------------------------------------------------------

var wxTimer = function (initObj){
    initObj = initObj || {};
    this.beginTime = initObj.beginTime || "00:00:00";    //开始时间
    this.interval = initObj.interval || 0;                //间隔时间
    this.complete = initObj.complete;                    //结束任务
}

wxTimer.prototype = {
    //开始
    start:function(self){    
        var that = this;
        function begin(){
            self.setData({
                wxTimerList:wxTimerList
            });
          
            //结束执行函数
            if(wxTimerSecond <= 0){
                if(that.complete){
                    that.complete();
                }
                that.stop();
            }
        }
        begin();
        this.intervarID = setInterval(begin,1000);
    },
    //结束
    stop:function(){
        clearInterval(this.intervarID);
    },
    //校准
    calibration:function(){
        this.endTime = this.endSystemTime - Date.now();
    }
}

module.exports = wxTimer;

猜你喜欢

转载自www.cnblogs.com/znsongshu/p/9426206.html