docs: 更新 README.md 和 site/ 文档页

README.md:
- 特性列表: 80+ → 107 种图标类型,新增全局错误回调和暂停恢复说明
- 全局配置: 添加 onError 示例
- Toast 管理: 添加 getAll() 方法
- 回调: 新增 onError 全局错误回调示例

site/index.html:
- 新增「错误捕获」和「暂停恢复」特性卡片
- TypeScript 卡片更新为「零 phantom 方法」

site/docs.html:
- 回调表添加 onError 条目

site/demo.html:
- 新增 onError 错误捕获演示卡片(含 JS 实现)
This commit is contained in:
2026-07-24 14:59:11 +08:00
parent 5c5627179a
commit ee2b685f64
4 changed files with 63 additions and 10 deletions
+19 -5
View File
@@ -9,13 +9,14 @@
## 特性
- **零依赖** — 纯原生 JavaScriptgzip 后不到 10KB
- **80+ 图标类型** — success/error/warning/info/loading 及更多扩展类型
- **107 种图标类型** — success/error/warning/info/loading 及更多扩展类型,覆盖所有常见场景
- **11 种动画** — slide/fade/scale/bounce/flip/rotate/zoom/slideUp/slideDown/slideLeft/slideRight,每种效果明显不同
- **主题系统** — light/dark/auto/warm 四种内置主题,支持 `registerTheme()` 注册自定义主题
- **国际化** — 内置 zh-CN / en-US 完整翻译,可通过 `addTranslations()` 扩展
- **国际化** — 内置 zh-CN / en-US 完整翻译(去重优化),可通过 `addTranslations()` 扩展
- **插件系统** — 3 款预设插件 (keyboard/persistence/accessibility) + 自定义插件
- **可拖拽关闭** — 拖动 Toast 任意方向即可关闭
- **TypeScript** — 完整类型定义
- **TypeScript** — 完整类型定义,已对齐实际实现无 phantom 方法
- **全局错误回调** — `onError` 捕获所有钩子异常和定时器错误,方便接入监控系统
## 安装
@@ -107,6 +108,9 @@ MeToast.configure({
showProgress: true, // 显示进度条
draggable: true, // 允许拖拽关闭
locale: 'zh-CN', // 语言
onError: ({ hook, error, toast }) => { // 全局错误回调(钩子/定时器异常)
console.error('Toast error:', hook, error);
},
});
```
@@ -229,12 +233,13 @@ MeToast.i18n.formatCurrency(99, 'CNY'); // "¥99.00"
```javascript
MeToast.count(); // 当前数量
MeToast.getToasts(); // 获取所有实例
MeToast.getAll(); // 获取原生 Map<id, ToastInstance>
MeToast.getToasts(); // 获取所有实例数组
MeToast.dismiss(); // 关闭所有
MeToast.dismiss(id); // 关闭指定
MeToast.pauseAll(); // 暂停所有计时
MeToast.resumeAll(); // 恢复所有计时
MeToast.destroy(); // 完全销毁
MeToast.destroy(); // 完全销毁(支持重复调用)
```
## 回调
@@ -245,6 +250,15 @@ MeToast.success({
onShow: (toast) => console.log('显示:', toast.id),
onClose: (toast) => console.log('关闭:', toast.id),
onClick: (toast) => console.log('点击:', toast.id),
onUpdate: (toast) => console.log('更新:', toast.id),
});
// 全局错误回调 — 捕获钩子异常和定时器错误
MeToast.configure({
onError: ({ hook, source, error, toast }) => {
// 接入监控系统 (Sentry, DataDog 等)
reportError(error, { hook, source, toastId: toast?.id });
},
});
```