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
+31 -3
View File
@@ -242,7 +242,16 @@
</div>
</div>
<!-- 14. 交互特性 -->
<!-- 14. 错误回调 -->
<div class="card">
<div class="label">🛡️ onError 错误捕获 <span style="color:#34d399;font-size:10px;">v0.1.2</span></div>
<div class="btn-row">
<button class="btn c-e" onclick="demoOnError()">演示 onError</button>
<button class="btn c-w" onclick="demoOnErrorReset()">重置回调</button>
</div>
</div>
<!-- 15. 交互特性 -->
<div class="card">
<div class="label">✋ 交互特性</div>
<div class="btn-row">
@@ -254,7 +263,7 @@
</div>
</div>
<!-- 15. 国际化切换 -->
<!-- 16. 国际化切换 -->
<div class="card">
<div class="label">🌍 国际化 & 格式化</div>
<div class="btn-row">
@@ -264,7 +273,7 @@
</div>
</div>
<!-- 16. 107种预设图标 -->
<!-- 17. 107种预设图标 -->
<div class="card" style="grid-column:1/-1;">
<div class="label">🎨 107种预设图标 — 点击任意图标发送Toast</div>
<div class="btn-row" id="icon-grid" style="max-height:300px;overflow-y:auto;padding:4px 0;"></div>
@@ -387,6 +396,25 @@
});
}
// === onError ===
function demoOnError() {
MeToast.configure({
onError: function(info) {
MeToast.error('⚠️ 捕获错误: ' + (info.hook || info.source), { duration: 3000, position: 'bottom-center' });
}
});
MeToast.info('已启用 onError 监控(钩子/定时器异常将被捕获)', { duration: 3000 });
// 触发一个钩子错误来演示
var badFn = function() { throw new Error('demo-error'); };
Toast.on('afterShow', badFn);
MeToast.success('这条消息会触发错误', { duration: 2000 });
setTimeout(function() { Toast.off('afterShow', badFn); }, 3000);
}
function demoOnErrorReset() {
MeToast.configure({ onError: null });
MeToast.info('onError 已重置为 null');
}
// === i18n ===
function switchLocale(loc) {
try{MeToast.i18n.switchLocale(loc);MeToast.configure({locale:loc});MeToast.success(loc==='zh-CN'?'已切换到中文':'Switched to English',{theme:'dark'});}
+2 -1
View File
@@ -443,7 +443,8 @@ MeToast.<span class="fn">use</span>(<span class="s">'accessibility'</span>); <sp
<tr><td>onShow</td><td>(toast: ToastInstance) => void</td><td>Toast DOM 创建并播放入场动画后</td></tr>
<tr><td>onClose</td><td>(toast: ToastInstance) => void</td><td>Toast DOM 被移除后(离场动画完成时)</td></tr>
<tr><td>onClick</td><td>(toast: ToastInstance) => void</td><td>Toast 被点击时(closeOnClick 为 true 时还会自动关闭)</td></tr>
<tr><td>onUpdate</td><td>(toast: ToastInstance) => void</td><td>Toast 内容通过 update() 更新后</td></tr>
<tr><td>onUpdate</td><td>(toast: ToastInstance) => void</td><td>Toast 内容通过 update() 更新后</td></tr>
<tr><td>onError</td><td>({ hook, source, error, toast }) => void</td><td>钩子回调或定时器发生异常时(全局配置,适用于接入错误监控)</td></tr>
</table>
<h2 id="animations">动画列表</h2>
+11 -1
View File
@@ -129,10 +129,20 @@
<h3>零依赖</h3>
<p>纯原生 JavaScript 实现,无需任何运行时依赖。兼容所有现代浏览器。</p>
</div>
<div class="feature">
<div class="feature-icon">🛡️</div>
<h3>错误捕获</h3>
<p>全局 <code>onError</code> 回调可捕获钩子异常和定时器错误,方便接入 Sentry、DataDog 等监控系统。</p>
</div>
<div class="feature">
<div class="feature-icon">⏱️</div>
<h3>暂停恢复</h3>
<p>悬停自动暂停、拖拽临时暂停、手动 pause/resume,剩余时间精确保持,不丢失进度。</p>
</div>
<div class="feature">
<div class="feature-icon">📘</div>
<h3>TypeScript</h3>
<p>完整类型定义,智能提示全覆盖<code>MeToast.success()</code><code>.confirm()</code><code>.action()</code> 全部有类型。</p>
<p>完整类型定义,与实现严格对齐零 phantom 方法<code>MeToast.success()</code><code>.confirm()</code><code>.action()</code> 全部有类型。</p>
</div>
</div>
</main>