From 9e0a6bb984b87379b6a1504b9fa5284df18096c7 Mon Sep 17 00:00:00 2001 From: jiangruowei Date: Thu, 30 Mar 2017 17:23:38 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20=E7=AE=80=E5=8C=96toast=E4=B8=BA?= =?UTF-8?q?=E5=8D=95=E4=B8=AAintance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/examples-docs/toast.md | 5 +++++ packages/toast/src/toast.js | 17 +++++------------ packages/zanui-css/src/toast.css | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/examples-docs/toast.md b/docs/examples-docs/toast.md index 731b57245..b0ab7a54e 100644 --- a/docs/examples-docs/toast.md +++ b/docs/examples-docs/toast.md @@ -39,6 +39,11 @@ export default { message: leftSec.toString() }); window.setInterval(() => { + if (leftSec <= 0) { + window.clearInterval(); + toast.clear(); + return; + } if (leftSec <= 1) { window.clearInterval(); toast.message = '跳转中...' diff --git a/packages/toast/src/toast.js b/packages/toast/src/toast.js index 8e6674b9b..9743ff5f5 100644 --- a/packages/toast/src/toast.js +++ b/packages/toast/src/toast.js @@ -2,24 +2,18 @@ import Vue from 'vue'; import merge from 'src/utils/merge'; const ToastConstructor = Vue.extend(require('./toast.vue')); -let toastQueue = []; +let instance; const getInstance = () => { - if (toastQueue.length > 0) { - const instance = toastQueue[0]; - toastQueue.splice(0, 1); - return instance; + if (instance) { + instance.clear(); } - return new ToastConstructor({ + instance = new ToastConstructor({ el: document.createElement('div') }); + return instance; }; -const returnInstance = instance => { - if (instance) { - toastQueue.push(instance); - } -}; const removeDom = event => { if (event.target.parentNode) { @@ -31,7 +25,6 @@ var Toast = (options = {}) => { const duration = options.duration || 3000; let instance = getInstance(); - returnInstance(instance); instance.closed = false; clearTimeout(instance.timer); instance.type = options.type ? options.type : 'text'; diff --git a/packages/zanui-css/src/toast.css b/packages/zanui-css/src/toast.css index d59361425..bf030c483 100644 --- a/packages/zanui-css/src/toast.css +++ b/packages/zanui-css/src/toast.css @@ -44,7 +44,7 @@ } .zan-toast__text { - padding-bottom: 20px; + padding: 15px 0 20px; font-size: 14px; } } From e560cef31568aec1f307e916819a4b67d9ae50e5 Mon Sep 17 00:00:00 2001 From: jiangruowei Date: Thu, 30 Mar 2017 17:26:49 +0800 Subject: [PATCH 2/8] feat: add clear method --- docs/examples-docs/toast.md | 4 ++-- packages/toast/src/toast.js | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/examples-docs/toast.md b/docs/examples-docs/toast.md index b0ab7a54e..844030207 100644 --- a/docs/examples-docs/toast.md +++ b/docs/examples-docs/toast.md @@ -139,10 +139,10 @@ import { Toast } from 'src/index'; export default { methods: { showToast() { - this.toast = Toast('我是提示文案,建议不超过十五字~'); + Toast('我是提示文案,建议不超过十五字~'); }, closeToast() { - this.toast.clear(); + Toast.clear(); } } }; diff --git a/packages/toast/src/toast.js b/packages/toast/src/toast.js index 9743ff5f5..eba907550 100644 --- a/packages/toast/src/toast.js +++ b/packages/toast/src/toast.js @@ -5,9 +5,8 @@ const ToastConstructor = Vue.extend(require('./toast.vue')); let instance; const getInstance = () => { - if (instance) { - instance.clear(); - } + if (instance) instance.clear(); + instance = new ToastConstructor({ el: document.createElement('div') }); @@ -70,4 +69,8 @@ Toast.fail = (options) => { }, options)); }; +Toast.clear = () => { + if (instance) instance.clear(); +} + export default Toast; From b2886f88568cba4ddb94400c2896dbf73e737c95 Mon Sep 17 00:00:00 2001 From: jiangruowei Date: Thu, 30 Mar 2017 17:27:27 +0800 Subject: [PATCH 3/8] doc: update --- docs/examples-docs/toast.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples-docs/toast.md b/docs/examples-docs/toast.md index 844030207..0fe2db76c 100644 --- a/docs/examples-docs/toast.md +++ b/docs/examples-docs/toast.md @@ -217,5 +217,5 @@ export default { | forbidClick | 不允许背景点击 | Boolean | false | true, false| | duration | 时长(ms) | Number | 3000ms | -| -### instanceOfToast.clear() +### Toast.clear() 关闭toast。 From abbb41083ea1b6212b98fce5e19b047c4ef8ee15 Mon Sep 17 00:00:00 2001 From: jiangruowei Date: Thu, 30 Mar 2017 17:40:08 +0800 Subject: [PATCH 4/8] feat: add transition animation --- packages/toast/src/toast.vue | 2 +- packages/zanui-css/src/toast.css | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/toast/src/toast.vue b/packages/toast/src/toast.vue index 0e9c89035..fff1f45e0 100644 --- a/packages/toast/src/toast.vue +++ b/packages/toast/src/toast.vue @@ -1,5 +1,5 @@