Notification/Message: return instance for manual close (#1033)

pull/1045/head
杨奕 2016-11-13 20:03:17 +08:00 committed by FuryBean
parent 1208ef520c
commit c08c6f1769
10 changed files with 34 additions and 7 deletions

View File

@ -9,6 +9,7 @@
- Fixed Loading locks scroll of `body` in specific scenarios, #968 - Fixed Loading locks scroll of `body` in specific scenarios, #968
- `span` of Col is no longer a required attribute, and its default value is `24` if omitted - `span` of Col is no longer a required attribute, and its default value is `24` if omitted
- DatePicker: add `disabled` and `editable` attribute. - DatePicker: add `disabled` and `editable` attribute.
- Added `close` method for Message and Notification to manually close an instance
#### Breaking change #### Breaking change
- DatePicker: can't change value when `readonly` is true, setting `editable` to false if you want to disabled input. #976 - DatePicker: can't change value when `readonly` is true, setting `editable` to false if you want to disabled input. #976

View File

@ -8,6 +8,7 @@
- 修复 Loading 在某些情况下错误地锁定 `body` 滚动的问题,#968 - 修复 Loading 在某些情况下错误地锁定 `body` 滚动的问题,#968
- Col 组件的 `span` 属性不再是必填属性,在省略的情况下其默认值为 `24` - Col 组件的 `span` 属性不再是必填属性,在省略的情况下其默认值为 `24`
- DatePicker 新增 `disabled``editable` - DatePicker 新增 `disabled``editable`
- 新增 Message 和 Notification 的 `close` 方法,用于手动关闭实例
#### 非兼容性更新 #### 非兼容性更新
- DatePicker 的 `readonly` 为完全只读,新增的 `editable` 属性设置为 false 可禁止输入但是可通过弹框选择,#976 - DatePicker 的 `readonly` 为完全只读,新增的 `editable` 属性设置为 false 可禁止输入但是可通过弹框选择,#976

View File

@ -200,3 +200,9 @@ In this case you should call `Message(options)`. We have also registered methods
| duration | display duration, millisecond. If set to 0, it will not turn off automatically | number | — | 3000 | | duration | display duration, millisecond. If set to 0, it will not turn off automatically | number | — | 3000 |
| showClose | whether to show a close button | boolean | — | false | | showClose | whether to show a close button | boolean | — | false |
| onClose | callback function when closed with the message instance as the parameter | function | — | — | | onClose | callback function when closed with the message instance as the parameter | function | — | — |
### Methods
`Message` and `this.$message` returns the current Message instance. To manually close the instance, you can call `close` on it.
| Method | Description |
| ---- | ---- |
| close | close the Message |

View File

@ -188,3 +188,8 @@ In this case you should call `Notification(options)`. We have also registered me
| duration | duration before close. It will not automatically close if set 0 | number | — | 4500 | | duration | duration before close. It will not automatically close if set 0 | number | — | 4500 |
| onClose | callback function when closed | function | — | — | | onClose | callback function when closed | function | — | — |
### Methods
`Notification` and `this.$notify` returns the current Message instance. To manually close the instance, you can call `close` on it.
| Method | Description |
| ---- | ---- |
| close | close the Notification |

View File

@ -200,3 +200,9 @@ import { Message } from 'element-ui';
| duration | 显示时间, 毫秒。设为 0 则不会自动关闭 | number | — | 3000 | | duration | 显示时间, 毫秒。设为 0 则不会自动关闭 | number | — | 3000 |
| showClose | 是否显示关闭按钮 | boolean | — | false | | showClose | 是否显示关闭按钮 | boolean | — | false |
| onClose | 关闭时的回调函数, 参数为被关闭的 message 实例 | function | — | — | | onClose | 关闭时的回调函数, 参数为被关闭的 message 实例 | function | — | — |
### 方法
调用 `Message``this.$message` 会返回当前 Message 的实例。如果需要手动关闭实例,可以调用它的 `close` 方法。
| 方法名 | 说明 |
| ---- | ---- |
| close | 关闭当前的 Message |

View File

@ -188,3 +188,9 @@ import { Notification } from 'element-ui';
| type | 主题样式,如果不在可选值内将被忽略 | string | success/warning/info/error | — | | type | 主题样式,如果不在可选值内将被忽略 | string | success/warning/info/error | — |
| duration | 显示时间, 毫秒。设为 0 则不会自动关闭 | number | — | 4500 | | duration | 显示时间, 毫秒。设为 0 则不会自动关闭 | number | — | 4500 |
| onClose | 关闭时的回调函数 | function | — | — | | onClose | 关闭时的回调函数 | function | — | — |
### 方法
调用 `Notification``this.$notify` 会返回当前 Notification 的实例。如果需要手动关闭实例,可以调用它的 `close` 方法。
| 方法名 | 说明 |
| ---- | ---- |
| close | 关闭当前的 Notification |

View File

@ -30,6 +30,7 @@ var Message = function(options) {
instance.dom = instance.vm.$el; instance.dom = instance.vm.$el;
instance.dom.style.zIndex = PopupManager.nextZIndex(); instance.dom.style.zIndex = PopupManager.nextZIndex();
instances.push(instance); instances.push(instance);
return instance.vm;
}; };
['success', 'warning', 'info', 'error'].forEach(type => { ['success', 'warning', 'info', 'error'].forEach(type => {

View File

@ -4,7 +4,7 @@
<img class="el-message__icon" :src="typeImg" alt=""> <img class="el-message__icon" :src="typeImg" alt="">
<div class="el-message__group"> <div class="el-message__group">
<p>{{ message }}</p> <p>{{ message }}</p>
<div v-if="showClose" class="el-message__closeBtn el-icon-close" @click="handleClose"></div> <div v-if="showClose" class="el-message__closeBtn el-icon-close" @click="close"></div>
</div> </div>
</div> </div>
</transition> </transition>
@ -47,7 +47,7 @@
this.$el.parentNode.removeChild(this.$el); this.$el.parentNode.removeChild(this.$el);
}, },
handleClose() { close() {
this.closed = true; this.closed = true;
if (typeof this.onClose === 'function') { if (typeof this.onClose === 'function') {
this.onClose(this); this.onClose(this);
@ -62,7 +62,7 @@
if (this.duration > 0) { if (this.duration > 0) {
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
if (!this.closed) { if (!this.closed) {
this.handleClose(); this.close();
} }
}, this.duration); }, this.duration);
} }

View File

@ -32,6 +32,7 @@ var Notification = function(options) {
topDist += 16; topDist += 16;
instance.top = topDist; instance.top = topDist;
instances.push(instance); instances.push(instance);
return instance.vm;
}; };
['success', 'warning', 'info', 'error'].forEach(type => { ['success', 'warning', 'info', 'error'].forEach(type => {

View File

@ -5,7 +5,7 @@
<div class="el-notification__group" :style="{ 'margin-left': typeClass ? '55px' : '0' }"> <div class="el-notification__group" :style="{ 'margin-left': typeClass ? '55px' : '0' }">
<span>{{ title }}</span> <span>{{ title }}</span>
<p>{{ message }}</p> <p>{{ message }}</p>
<div class="el-notification__closeBtn el-icon-close" @click="handleClose()"></div> <div class="el-notification__closeBtn el-icon-close" @click="close"></div>
</div> </div>
</div> </div>
</transition> </transition>
@ -56,7 +56,7 @@
this.$el.parentNode.removeChild(this.$el); this.$el.parentNode.removeChild(this.$el);
}, },
handleClose() { close() {
this.closed = true; this.closed = true;
if (typeof this.onClose === 'function') { if (typeof this.onClose === 'function') {
this.onClose(); this.onClose();
@ -71,7 +71,7 @@
if (this.duration > 0) { if (this.duration > 0) {
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
if (!this.closed) { if (!this.closed) {
this.handleClose(); this.close();
} }
}, this.duration); }, this.duration);
} }
@ -82,7 +82,7 @@
if (this.duration > 0) { if (this.duration > 0) {
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
if (!this.closed) { if (!this.closed) {
this.handleClose(); this.close();
} }
}, this.duration); }, this.duration);
} }