wetoast.js
1.07 KB
"use strict";function WeToastClass(){function t(){var t=getCurrentPages(),e=t[t.length-1];return this.__page=e,this.__timeout=null,e.wetoast=this}return t.prototype.toast=function(e){try{e?this.show(e):this.hide()}catch(t){e&&"function"==typeof e.fail&&e.fail(e)}finally{e&&"function"==typeof e.complete&&e.complete(e)}},t.prototype.show=function(e){var t=this,o=this.__page;clearTimeout(this.__timeout),o.setData({"__wetoast__.reveal":!0}),setTimeout(function(){var t=wx.createAnimation();t.opacity(1).step(),e.animationData=t.export(),e.reveal=!0,o.setData({__wetoast__:e})},30),0===e.duration?setTimeout(function(){"function"==typeof e.success&&e.success(e)},430):this.__timeout=setTimeout(function(){t.toast(),"function"==typeof e.success&&e.success(e)},(e.duration||1500)+400)},t.prototype.hide=function(){var t=this.__page;if(clearTimeout(this.__timeout),t.data.__wetoast__.reveal){var e=wx.createAnimation();e.opacity(0).step(),t.setData({"__wetoast__.animationData":e.export()}),setTimeout(function(){t.setData({__wetoast__:{reveal:!1}})},400)}},new t}module.exports={WeToast:WeToastClass};