Files
jiang13-bbs/frontend/lib/toast.ts
freefire 1eaf3903d4 feat: 新增大量社区功能与基础组件,优化站点整体体验
- 新增事件总线式toast通知系统
- 新增头像、阅读进度、404/500错误页等基础组件
- 重构页脚、布局、分页、点赞按钮等现有组件
- 新增用户个人页、通知中心、帖子编辑/发布/置顶/推荐管理功能
- 优化登录注册页面样式与交互
- 修复路径类型文件引用,更新站点元信息与字体配置
2026-09-12 04:30:02 +08:00

18 lines
490 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 零依赖的事件总线式 toast,避免在每个交互组件里包 Context
export type ToastVariant = "error" | "ok";
export interface ToastDetail {
id: number;
message: string;
variant: ToastVariant;
}
export function toast(message: string, variant: ToastVariant = "error") {
if (typeof window === "undefined") return;
window.dispatchEvent(
new CustomEvent<ToastDetail>("j13-toast", {
detail: { id: Date.now() + Math.random(), message, variant },
})
);
}