---
url: /reference/interface/capabilities/notify.md
---

# notify

`notify` 使你的应用能够打开和 PingCode 风格一致的通知信息。

导入：

```typescript
import { notify } from "@pc-nexus/capabilities";
```

内置方法：

## 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;
}
```

### 参数

`NotifyOptions` 类型定义如下：

`NotifyDetail` 类型定义如下：

`NotifyAction` 类型定义如下：

### 返回值

返回值类型为 `NotifyRef` ，表示通知实例的引用对象：

### 示例

```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);
```
