From 47e5839630a0d8656e22edfc745edaa78d28a0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Mon, 19 Sep 2016 16:13:50 +0800 Subject: [PATCH] message components bug fixed message components bug fixed --- components/base/notification/index.js | 3 +++ components/base/notification/notification.vue | 2 +- components/message/index.js | 12 ++++++++++++ local/routers/msg.vue | 14 ++++++++------ package.json | 2 +- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/components/base/notification/index.js b/components/base/notification/index.js index 3bcd1692..2c7170e4 100644 --- a/components/base/notification/index.js +++ b/components/base/notification/index.js @@ -24,6 +24,9 @@ Notification.newInstance = properties => { notice (noticeProps) { notification.add(noticeProps); }, + remove (key) { + notification.close(key); + }, component: notification, destroy () { document.body.removeChild(div); diff --git a/components/base/notification/notification.vue b/components/base/notification/notification.vue index 1e4aa1dc..78cd2636 100644 --- a/components/base/notification/notification.vue +++ b/components/base/notification/notification.vue @@ -63,7 +63,7 @@ }, methods: { add (notice) { - const key = getUuid(); + const key = notice.key || getUuid(); let _notice = Object.assign({ style: { diff --git a/components/message/index.js b/components/message/index.js index 1ba4c492..2d78272c 100644 --- a/components/message/index.js +++ b/components/message/index.js @@ -2,11 +2,13 @@ import Notification from '../base/notification'; const prefixCls = 'ivu-message'; const iconPrefixCls = 'ivu-icon'; +const prefixKey = 'ivu_message_key_'; let defaultDuration = 1.5; let top; let messageInstance; +let key = 1; const iconTypes = { 'info': 'information-circled', @@ -42,6 +44,7 @@ function notice (content, duration = defaultDuration, type, onClose) { let instance = getMessageInstance(); instance.notice({ + key: `${prefixKey}${key}`, duration: duration, style: {}, content: ` @@ -52,6 +55,15 @@ function notice (content, duration = defaultDuration, type, onClose) { `, onClose: onClose }); + + // 用于手动消除 + return (function () { + let target = key++; + + return function () { + instance.remove(`${prefixKey}${target}`); + } + })(); } export default { diff --git a/local/routers/msg.vue b/local/routers/msg.vue index 11a94fbd..bcb66b2d 100644 --- a/local/routers/msg.vue +++ b/local/routers/msg.vue @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/package.json b/package.json index af0cf7da..8732405a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iview", - "version": "0.0.7", + "version": "0.0.8", "title": "iView", "description": "A high quality UI components Library with Vue.js", "homepage": "http://www.iviewui.com",