feat(message): add message destroyAll method (#687)

* feat: addd destroyAll

* feat(message): add destroyAll method

Co-authored-by: yugang.cao <yugang.cao@tusimple.ai>
This commit is contained in:
Yugang Cao 2021-07-27 23:30:49 +08:00 committed by GitHub
parent d535a6497d
commit 2501817488
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 1 deletions

View File

@ -1,5 +1,11 @@
# CHANGELOG # CHANGELOG
## Pending
### Feats
- `n-message` add `destroyAll` method.
## 2.15.8 (2021-07-27) ## 2.15.8 (2021-07-27)
### Feats ### Feats

View File

@ -1,5 +1,11 @@
# CHANGELOG # CHANGELOG
## Pending
### Feats
- `n-message` 增加 `destroyAll` 方法
## 2.15.8 (2021-07-27) ## 2.15.8 (2021-07-27)
### Feats ### Feats

View File

@ -62,6 +62,7 @@ multiple-line
| Name | Type | Description | | Name | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| destroyAll | `() => void` | Destroy all popup messages. |
| error | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | Use error type message. | | error | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | Use error type message. |
| info | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | Use info type message. | | info | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | Use info type message. |
| loading | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | Use loading type message. | | loading | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | Use loading type message. |

View File

@ -62,6 +62,7 @@ multiple-line
| 名称 | 类型 | 说明 | | 名称 | 类型 | 说明 |
| --- | --- | --- | | --- | --- | --- |
| destroyAll | `() => void` | 销毁所有弹出的信息 |
| error | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | 调用 error 类型的信息 | | error | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | 调用 error 类型的信息 |
| info | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | 调用 info 类型的信息 | | info | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | 调用 info 类型的信息 |
| loading | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | 调用 loading 类型的信息 | | loading | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | 调用 loading 类型的信息 |

View File

@ -36,6 +36,7 @@ export interface MessageApiInjection {
warning: (content: ContentType, options?: MessageOptions) => MessageReactive warning: (content: ContentType, options?: MessageOptions) => MessageReactive
error: (content: ContentType, options?: MessageOptions) => MessageReactive error: (content: ContentType, options?: MessageOptions) => MessageReactive
loading: (content: ContentType, options?: MessageOptions) => MessageReactive loading: (content: ContentType, options?: MessageOptions) => MessageReactive
destroyAll: () => void
} }
export const messageApiInjectionKey: InjectionKey<MessageApiInjection> = export const messageApiInjectionKey: InjectionKey<MessageApiInjection> =
@ -107,7 +108,8 @@ export default defineComponent({
}, },
loading (content: ContentType, options?: MessageOptions) { loading (content: ContentType, options?: MessageOptions) {
return create(content, { ...options, type: 'loading' }) return create(content, { ...options, type: 'loading' })
} },
destroyAll
} }
provide(messageProviderInjectionKey, { provide(messageProviderInjectionKey, {
props, props,
@ -137,6 +139,11 @@ export default defineComponent({
1 1
) )
} }
function destroyAll (): void {
Object.values(messageRefs.value).forEach((messageInstRef) => {
messageInstRef?.hide()
})
}
return Object.assign( return Object.assign(
{ {
mergedClsPrefix: mergedClsPrefixRef, mergedClsPrefix: mergedClsPrefixRef,