From bc4adf3d2a168363e45acce4874375f45d9baed4 Mon Sep 17 00:00:00 2001 From: Yao Date: Tue, 2 May 2017 14:44:54 +0800 Subject: [PATCH] fix toptips bug (#21) #20 --- dist/toptips/index.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/dist/toptips/index.js b/dist/toptips/index.js index a45d4fbf..af5104ea 100644 --- a/dist/toptips/index.js +++ b/dist/toptips/index.js @@ -1,11 +1,10 @@ -var timer = undefined; - module.exports = { showZanTopTips(content = '', options = {}) { + let zanTopTips = this.data.zanTopTips || {}; // 如果已经有一个计时器在了,就清理掉先 - if (timer) { - clearTimeout(timer); - timer = undefined; + if (zanTopTips.timer) { + clearTimeout(zanTopTips.timer); + zanTopTips.timer = undefined; } if (typeof options === 'number') { @@ -19,21 +18,22 @@ module.exports = { duration: 3000 }, options); + // 设置定时器,定时关闭topTips + let timer = setTimeout(() => { + this.setData({ + 'zanTopTips.show': false, + 'zanTopTips.timer': undefined + }); + }, options.duration); + // 展示出topTips this.setData({ zanTopTips: { show: true, content, - options + options, + timer } }); - - // 设置定时器,定时关闭topTips - timer = setTimeout(() => { - this.setData({ - 'zanTopTips.show': false - }); - timer = undefined; - }, options.duration); } };