> For the complete documentation index, see [llms.txt](https://ak-scripts.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ak-scripts.gitbook.io/docs/yi-lai/markdown/ui-mo-kuai-dao-chu/tong-zhi-notify.md).

# 通知（Notify）

## 🔔 Notify（通知）模块导出文档

### 📋 概述

Notify 模块是 ak-lib 的通知系统，支持多种通知类型、动态堆叠、时长配置、音效控制等功能。

### 🚀 导出方式

#### 客户端

```lua
exports['ak-lib']:Notify(data)
```

#### 服务端

```lua
exports['ak-lib']:Notify(target, data)
exports['ak-lib']:NotifyAll(data)
```

### 📖 可用导出

#### 客户端

| 导出                  | 说明     | 参数             | 返回值                  |
| ------------------- | ------ | -------------- | -------------------- |
| `Notify(data)`      | 显示通知   | `data` (table) | string (通知 ID) / nil |
| `HideNotify(id)`    | 隐藏指定通知 | `id` (string)  | boolean              |
| `HideAllNotifies()` | 隐藏所有通知 | -              | boolean              |

#### 服务端

| 导出                     | 说明        | 参数                                | 返回值 |
| ---------------------- | --------- | --------------------------------- | --- |
| `Notify(target, data)` | 向指定玩家显示通知 | `target` (number), `data` (table) | nil |
| `NotifyAll(data)`      | 向所有玩家显示通知 | `data` (table)                    | nil |

### 💡 使用示例

#### 客户端：基础使用

```lua
-- 只有内容
exports['ak-lib']:Notify({
    message = "余额不足！",
    type = "error"
})

-- 只有标题（会自动转为正文）
exports['ak-lib']:Notify({
    title = "操作已完成",
    type = "success"
})

-- 带标题 + 内容
exports['ak-lib']:Notify({
    title = "警告",
    message = "你已进入安全区！",
    type = "warning"
})

-- 自定义时长
exports['ak-lib']:Notify({
    title = "信息",
    message = "服务器将在 5 分钟后重启",
    type = "info",
    duration = 5000  -- 显示时长（毫秒）
})

-- 自定义位置
exports['ak-lib']:Notify({
    title = "成功",
    message = "你获得了 $100",
    type = "success",
    position = "top-center"  -- 九宫格位置
})

-- 自定义图标
exports['ak-lib']:Notify({
    title = "车辆信息",
    message = "你的车辆已修复",
    type = "success",
    icon = "fa-solid fa-car"  -- FontAwesome 图标
})

-- 自定义图标颜色
exports['ak-lib']:Notify({
    title = "爱心提示",
    message = "感谢你的支持",
    type = "info",
    icon = "fa-solid fa-heart",
    iconColor = "#ff0000"
})

-- 通知 ID 管理
local notifyId = exports['ak-lib']:Notify({
    id = "my-notification",  -- 指定 ID
    title = "重要通知",
    message = "这个通知可以被管理",
    type = "warning",
    duration = 10000
})

-- 手动关闭通知
exports['ak-lib']:HideNotify(notifyId)

-- 关闭所有通知
exports['ak-lib']:HideAllNotifies()

-- 关闭回调
exports['ak-lib']:Notify({
    title = "任务完成",
    message = "3秒后自动关闭",
    type = "success",
    duration = 3000,
    onClose = function()
        print("通知已关闭")
    end
})
```

#### 服务端：向玩家发送通知

```lua
-- 向指定玩家发送通知
exports['ak-lib']:Notify(source, {
    title = "欢迎",
    message = "欢迎来到服务器！",
    type = "success"
})

-- 向所有玩家发送通知
exports['ak-lib']:NotifyAll({
    title = "服务器公告",
    message = "服务器将在 5 分钟后重启",
    type = "info",
    duration = 10000
})
```

### 📝 参数说明

#### data 参数（table）

| 字段            | 类型       | 说明                                                    | 必需  | 默认值                      |
| ------------- | -------- | ----------------------------------------------------- | --- | ------------------------ |
| `title`       | string   | 通知标题                                                  | 否   | -                        |
| `message`     | string   | 通知内容（支持 description）                                  | 否\* | -                        |
| `description` | string   | 通知内容（message 的别名）                                     | 否\* | -                        |
| `type`        | string   | 通知类型：`'info'` / `'success'` / `'error'` / `'warning'` | 否   | `'info'`                 |
| `icon`        | string   | FontAwesome 图标类名                                      | 否   | -                        |
| `iconColor`   | string   | 图标颜色（CSS 颜色值）                                         | 否   | -                        |
| `duration`    | number   | 显示时长（毫秒）                                              | 否   | `Config.Notify.Duration` |
| `position`    | string   | 位置（九宫格）                                               | 否   | `Config.Notify.Position` |
| `sound`       | boolean  | 是否播放音效                                                | 否   | `Config.Notify.Sound`    |
| `volume`      | number   | 音量（0.0 \~ 1.0）                                        | 否   | `Config.Notify.Volume`   |
| `id`          | string   | 通知 ID（用于管理）                                           | 否   | 自动生成                     |
| `onClose`     | function | 关闭时的回调函数                                              | 否   | -                        |

**注意：** `title` 和 `message` 至少需要提供一个。如果只有 `title`，会自动转换为 `message`。

#### 位置选项（position）

支持九宫格位置：

* `'top-left'` - 左上角
* `'top-center'` - 顶部中间
* `'top-right'` - 右上角
* `'middle-left'` - 左边中间
* `'middle-center'` - 屏幕中央
* `'middle-right'` - 右边中间
* `'bottom-left'` - 左下角
* `'bottom-center'` - 底部中间
* `'bottom-right'` - 右下角

#### 通知类型（type）

* `'info'` - 信息（蓝色）
* `'success'` - 成功（绿色）
* `'error'` - 错误（红色）
* `'warning'` - 警告（黄色）

也支持旧版类型：`'inform'`, `'primary'`（会自动转换为 `'info'`）

### ⚠️ 注意事项

1. **内容要求**：必须提供 `title` 或 `message`（或 `description`）至少一个。
2. **智能堆叠**：相同内容的通知会自动合并显示，避免重复通知。
3. **通知 ID**：如果不指定 `id`，系统会根据内容自动生成一个哈希 ID。
4. **关闭回调**：`onClose` 回调函数在通知关闭时（自动关闭或手动关闭）会被调用。
5. **服务端调用**：服务端调用时需要提供 `target` 参数（玩家服务器 ID），使用 `-1` 表示所有玩家（使用 `NotifyAll`）。
6. **返回値**：客户端 `Notify()` 返回通知 ID（string），可用于后续管理。
7. **音效控制**：可以通过 `sound` 参数控制是否播放音效，通过 `volume` 参数控制音量。

### 🔗 相关文档

* 通知说明


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ak-scripts.gitbook.io/docs/yi-lai/markdown/ui-mo-kuai-dao-chu/tong-zhi-notify.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
