From 1efdb465d6995b683fb0c1a169e6edc72122e213 Mon Sep 17 00:00:00 2001 From: dodobelieve <37918438+dodobelieve@users.noreply.github.com> Date: Sun, 19 May 2019 11:14:54 +0800 Subject: [PATCH 1/3] =?UTF-8?q?dialog.vue=E4=BF=AE=E6=94=B9(=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0clickCallback=E7=A4=BA=E4=BE=8B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加clickCallback示例 --- example/routers/dialog.vue | 195 ++++++++++++++++++------------------- 1 file changed, 97 insertions(+), 98 deletions(-) diff --git a/example/routers/dialog.vue b/example/routers/dialog.vue index 31bf643e..2270075a 100644 --- a/example/routers/dialog.vue +++ b/example/routers/dialog.vue @@ -1,113 +1,112 @@ From c35d0abfa951717bfb86dd8fcffc893b43606efd Mon Sep 17 00:00:00 2001 From: dodobelieve <37918438+dodobelieve@users.noreply.github.com> Date: Sun, 19 May 2019 11:21:50 +0800 Subject: [PATCH 2/3] =?UTF-8?q?dialog.notify=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、提示框notify组件添加点击事件回调(实际项目中有需要点击关闭的时候做不同的逻辑处理),点击回调会自动调用关闭回调。 2、解决多次点击后点击回调重复调用的问题(关闭时移除档次绑定的点击事件)。 --- src/components/dialog/src/notify/index.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/dialog/src/notify/index.js b/src/components/dialog/src/notify/index.js index 0b2d52af..59c39572 100644 --- a/src/components/dialog/src/notify/index.js +++ b/src/components/dialog/src/notify/index.js @@ -6,6 +6,11 @@ const instance = new NotifyConstructor({ el: document.createElement('div') }); +const notifyClicked = function () { + clearTimeout(timer); + instance.clickNotify(); +} + let timer = null; let lock = false; @@ -14,6 +19,7 @@ NotifyConstructor.prototype.closeNotify = function () { setTimeout(() => { const el = instance.$el; + el.removeEventListener("click", notifyClicked); el.parentNode && el.parentNode.removeChild(el); lock = false; }, 150); @@ -21,21 +27,24 @@ NotifyConstructor.prototype.closeNotify = function () { typeof this.callback === 'function' && this.callback(); }; +NotifyConstructor.prototype.clickNotify = function () { + typeof this.clickCallback === 'function' && this.clickCallback(); + instance.closeNotify(); +}; + const Notify = (options = {}) => { instance.classes = ''; instance.mes = options.mes; instance.timeout = ~~options.timeout || 5000; instance.callback = options.callback; + instance.clickCallback = options.clickCallback; - if (lock)return; + if (lock) return; lock = true; document.body.appendChild(instance.$el); - instance.$el.addEventListener('click', () => { - clearTimeout(timer); - instance.closeNotify(); - }); + instance.$el.addEventListener('click', notifyClicked); timer = setTimeout(() => { clearTimeout(timer); From 411322c8b285d6ff303b93db4b1b89f8e431da4b Mon Sep 17 00:00:00 2001 From: dodobelieve <37918438+dodobelieve@users.noreply.github.com> Date: Sun, 19 May 2019 11:22:55 +0800 Subject: [PATCH 3/3] =?UTF-8?q?dialog.notify=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、提示框notify组件添加点击事件回调(实际项目中有需要点击关闭的时候做不同的逻辑处理),点击回调会自动调用关闭回调。 2、解决多次点击后点击回调重复调用的问题(关闭时移除档次绑定的点击事件)。 --- src/components/dialog/src/notify/notify.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/dialog/src/notify/notify.vue b/src/components/dialog/src/notify/notify.vue index 32237a0e..f946fc00 100644 --- a/src/components/dialog/src/notify/notify.vue +++ b/src/components/dialog/src/notify/notify.vue @@ -12,7 +12,8 @@ props: { mes: String, timeout: Number, - callback: Function + callback: Function, + clickCallback: Function } }