@94ai-plus/nf-notification
v1.0.0
Published
Vue 3 notification with four-corner stacks, action callbacks and dual themes
Maintainers
Readme
@94ai-plus/nf-notification
HomePage
Vue 3 通知,保留旧版四角定位、独立堆叠、定时关闭、鼠标暂停及取消/确认按钮。支持 Chalk/OEM 主题、八语言关闭标签、文本/VNode/可信 HTML 和类型化实例。
Installation
yarn add @94ai-plus/nf-notification @94ai-plus/nf-theme-chalk vueUsage
import NfNotification, { Notification } from '@94ai-plus/nf-notification'
import '@94ai-plus/nf-theme-chalk/nf-notification.css'
app.use(NfNotification) // Options API: this.$openNotify.success('Saved')
Notification.success({ title: 'Saved', message: 'Success' })
const handler = Notification({
title: 'Review', message: 'Persistent notification', duration: 0,
position: 'bottom-right', confirmButtonText: 'Confirm',
onConfirm: () => handler.close(),
})
Notification.close(handler.id)
Notification.closeAll()默认导出是组件插件,可调用服务是具名 Notification。总包提供相同导出。setup 内使用 useNotification() 继承当前 provider 的语言/注入并在卸载时清理;createNotification(appContext) 创建应用专属服务,其 close/closeAll 只处理自身通知。直接服务不隐式绑定其他应用,可通过第二参数传入 appContext。
API
title/message 默认空字符串;message 支持 VNode。type 默认为空,可设 success/warning/info/error;四个同名快捷方法接受字符串、VNode 或 options。duration 默认 4500ms(<=0 常驻),showClose 默认 true,position 默认 top-right,支持 top-left/bottom-right/bottom-left。offset 默认 0,另加 16px 边距;同角通知间距 16px。zIndex 从 3001 自动递增。
iconClass/customClass/cancelButtonText/confirmButtonText 默认空字符串;dangerouslyUseHTMLString 默认 false,仅用于可信 HTML。有效 type 图标优先于 iconClass。onClick/onCancel/onConfirm 均无参数,取消/确认仅回调,不自动关闭,也不触发卡片点击。onClose(handler) 只执行一次。
返回 NotificationHandler:id、position、el/$el/dom、visible、closed、close(),不暴露 Vue 2 私有实例。SSR 返回 closed=true 的空操作 handler。悬停暂停,移出重新完整计时;Delete/Backspace 暂停,其他按键重新计时,Escape 关闭。默认插槽优先于 message,声明式组件不参与服务堆叠。通知挂载到 body,主题跟随根 data-nf-theme。
Build outputs
包含 ESM、CJS、browser ES/UMD、类型与 CSS,UMD 全局名 NfNotification,Vue external。同仓运行依赖已打包,browser 产物无需 Element Plus 运行时。独立主题含 nf-notification.css 和 SCSS;OEM 使用 @94ai-plus/nf-theme-oem/nf-notification.css。
全局默认配置
通过总包的 NfConfigProvider 的 nfNotification 配置项设置默认属性。支持响应式更新和嵌套继承,优先级为组件显式属性 → 最近一层配置 → 外层配置 → 组件原有默认值。undefined 继续继承,false、0 和空字符串保留;按属性合并,数组、对象和函数整体替换,不深度合并。初始化选项仍按组件原有生命周期生效,事件、插槽和原生 attributes 在组件上设置,必填业务数据仍需显式提供。详见全局配置文档。
在 Provider 后代组件的 setup 中调用 useNotification(),由返回的服务继承当前 Provider 的默认属性与语言;单次调用传入的选项优先,组件卸载时清理该服务创建的弹层。无应用/组件上下文的直接服务调用不读取组件树配置。
import { useNotification } from '@94ai-plus/nf-notification'
// 在 Provider 后代组件的 setup 中执行
const notification = useNotification()
notification({ title: '提示', message: '数据已更新' })Contributors
感谢每一位参与项目建设的贡献者!
以上为随本版本发布的贡献者统计快照,统计日期与分支见图中说明;仅统计 Git 非合并提交,头像使用姓名首字母,不是 GitLab 个人照片。
License
本项目采用 MIT License 开源许可。
Copyright (c) 2026-present Jiahe Zou, 94 Intelligent Technology Co., Ltd.
