notify
notify 使你的应用能够打开和 PingCode 风格一致的通知信息。
导入:
typescript
import { notify } from "@pc-nexus/capabilities";内置方法:
| API | 描述 |
|---|---|
show | 用于显示自定义配置的系统消息 |
success | 用于显示「成功」类的系统消息 |
info | 用于显示「消息」类的系统消息 |
warning | 用于显示「警告」类的系统消息 |
error | 用于显示「错误」类的系统消息 |
show
show 方法可以显示自定义配置的系统消息。
函数签名
typescript
function show(options: NotifyOptions): Promise<NotifyRef>;
interface NotifyOptions {
type: NotifyType;
title?: string;
description?: string;
detail?: string | NotifyDetail;
actions?: NotifyAction[];
isAutoClose?: boolean;
}
interface NotifyRef {
readonly close: () => void;
}
enum NotifyType {
Success = "success",
Error = "error",
Warning = "warning",
Info = "info",
}
interface NotifyDetail {
link?: string;
content?: string;
}
interface NotifyAction {
text: string;
icon?: string;
onClick: (event?: Event) => void;
}参数
| 名称 | 描述 |
|---|---|
options | 通知的配置选项,类型是 NotifyOptions (见下方详细说明) |
NotifyOptions 类型定义如下:
| 名称 | 描述 |
|---|---|
type | 通知类型,可选值: success 、 error 、 warning 、 info |
title | 通知标题 |
description | 通知的简要描述 |
detail | 通知的详细内容说明,用于补充描述信息,类型是 string | NotifyDetail (见下方详细说明) |
isAutoClose | 是否自动关闭通知,默认为 true ,4.5 秒后关闭 |
actions | 通知操作按钮数组,类型是 NotifyAction (见下方详细说明) |
NotifyDetail 类型定义如下:
| 名称 | 描述 |
|---|---|
link | 链接名称 |
content | 详情描述内容 |
NotifyAction 类型定义如下:
| 名称 | 描述 |
|---|---|
text | 按钮文本 |
icon | 按钮图标 |
onClick | 按钮点击事件回调 |
返回值
返回值类型为 NotifyRef ,表示通知实例的引用对象:
| 名称 | 描述 |
|---|---|
close | 关闭当前通知。调用该方法后,将立即关闭对应的通知实例 |
示例
typescript
import { notify, NotifyOptions, NotifyType } from "@pc-nexus/capabilities";
const options: NotifyOptions = {
type: NotifyType.Success,
title: 'Notify show success',
description: 'Hello World',
isAutoClose: false,
detail: {
link: 'View',
content: 'View content',
},
actions: [
{
text: 'Close',
icon: 'close',
onClick: () => this.closeNotify(),
},
{
text: 'Confirm',
icon: 'check',
onClick: () => this.closeNotify(),
},
],
}
const notifyRef = await notify.show(options);success
success 方法可以显示「成功」类的系统消息。
函数签名
typescript
function success(options: Omit<NotifyOptions, "type">): Promise<NotifyRef>;参数
类型为 Omit<NotifyOptions, "type"> 同上方 show 方法参数。
返回值
类型为 NotifyRef ,同上方 show 方法返回值。
示例
typescript
import { notify, NotifyOptions } from "@pc-nexus/capabilities";
const options: NotifyOptions = {
title: 'Success title',
description: 'Success description',
detail: {
link: 'View',
content: 'View content',
},
};
const notifyRef = await notify.success(options);info
info 方法可以显示「信息」类的系统消息。
函数签名
typescript
function info(options: Omit<NotifyOptions, "type">): Promise<NotifyRef>;参数
类型为 Omit<NotifyOptions, "type"> 同上方 show 方法参数。
返回值
类型为 NotifyRef ,同上方 show 方法返回值。
示例
typescript
import { notify, NotifyOptions } from "@pc-nexus/capabilities";
const options: NotifyOptions = {
title: 'Info title',
description: 'Info description',
detail: {
link: 'View',
content: 'View content',
},
};
const notifyRef = await notify.info(options);warning
warning 方法可以显示「警告」类的系统消息。
函数签名
typescript
function warning(options: Omit<NotifyOptions, "type">): Promise<NotifyRef>;参数
类型为 Omit<NotifyOptions, "type"> 同上方 show 方法参数。
返回值
类型为 NotifyRef ,同上方 show 方法返回值。
示例
typescript
import { notify, NotifyOptions } from "@pc-nexus/capabilities";
const options: NotifyOptions = {
title: 'Warning title',
description: 'Warning description',
detail: {
link: 'View',
content: 'View content',
},
};
const notifyRef = await notify.warning(options);error
error 方法可以显示「错误」类的系统消息。
函数签名
typescript
function error(options: Omit<NotifyOptions, "type">): Promise<NotifyRef>;参数
类型为 Omit<NotifyOptions, "type"> 同上方 show 方法参数。
返回值
类型为 NotifyRef ,同上方 show 方法返回值。
示例
typescript
import { notify, NotifyOptions } from "@pc-nexus/capabilities";
const options: NotifyOptions = {
title: 'Error title',
description: 'Error description',
detail: {
link: 'View',
content: 'View content',
},
};
const notifyRef = await notify.error(options);