Skip to content

Notification 通知 ​

四角定位的通知卡片,支持标题、描述、时长、类型、悬停暂停、优先级抢占与栈治理(折叠计数/层叠悬停展开)。

基础用法 ​

四种类型

信息成功警告错误

自定义时长 ​

自定义时长

8 秒不自动关闭

带进度条 ​

带进度条

进度条(底部)进度条(顶部)

长内容可滚动 ​

长内容可滚动

长内容

位置四角 ​

位置四角

左上右上左下右下

数量上限 ​

数量上限(超限丢最老)

连发 6 条(max=3)清空

悬停暂停 ​

悬停暂停(默认开启)

悬停暂停关闭悬停暂停

关闭回调 ​

关闭回调 onClose

无论自动关闭、点击 ✕ 还是命令式销毁,onClose 都会触发一次:

命令式销毁自动/手动关闭onClose 触发:0 次

点击回调 ​

点击回调 onClick(查看详情场景)

发出可点击通知onClick 触发:0 次

关闭开关 ​

关闭开关 closable

closable=false默认(可关闭)

图标插槽 ​

图标插槽 slot="icon" / slot="close-icon"

显示自定义图标通知移除

内容更新(key) ​

内容更新 key / update

模拟部署进度

进度条颜色 ​

进度条颜色 --oas-notification-progress-color

通知挂载到下方容器(container),容器上的颜色变量穿透生效——观察右上角进度条为危险色:

发出 danger 色进度条通知

偏移 ​

偏移 offset

offset=64默认 16

挂载容器 ​

挂载容器 container

通知栈挂到下方容器内(DOM 归属指定元素,视觉仍为视口四角定位);打开 devtools 可见栈容器在 div#notif-mount-host 内:

挂到下方容器
挂载目标容器(notif-mount-host)

footer 操作区(查看详情 / 撤销)

发出带操作区的通知

优先级 ​

优先级 priority(高优抢占)

先连发普通通知(max=5),再发高优:高优恒占最新侧,超限时低优先被挤出:

连发 4 条普通连发 2 条高优清空

栈治理 ​

栈治理 stackMode(折叠计数 / 层叠悬停)

折叠计数模式(+N 展开)层叠悬停模式(hover 展开)清空

loading 与 promise ​

loading 态与 promise 链

常驻 loadingpromise 成功promise 失败

富内容与尺寸 ​

富内容 content 与尺寸 size

小尺寸 + 代码块默认尺寸 + 代码块大尺寸 + 代码块

清空全部 ​

清空全部

连发三条清空全部

API ​

oas-notification ​

属性 ​

属性说明类型默认值
closable是否显示关闭按钮(默认 true;false 隐藏关闭钮)stringtrue
description描述内容string—
duration自动关闭时长(ms),0 表示不自动关闭string4500
pause-on-hover悬停暂停计时与进度条(默认开,mouseenter/leave 通道);移出恢复剩余时长stringtrue
progress-position进度条位置:bottom(默认)/ topstringbottom
scrollable描述内容超长时卡片内滚动,默认开启;传 false 关闭stringtrue
show-progress显示自动关闭倒计时进度条(动画时长与 duration 同步)boolean—
size尺寸档(配套 --oas-notification-width 变量)——
title标题文案(渲染进可见标题区;读取后即从宿主移除,不残留原生悬浮提示;清空传空串);富内容用 slot="title"string—
type通知类型:info/success/warning/errorstringinfo

事件 ​

事件说明
oas-click通知体点击时派发(「点击查看详情」场景)
oas-close通知关闭时派发,detail { source }:auto(时长到期)/ button(点击关闭钮)/ destroy(编程式销毁)/ evict(超上限被挤出)

插槽 ​

名称说明
close-icon自定义关闭图标,覆盖默认 ✕
content正文富内容插槽
footer底部操作区插槽(操作按钮/辅助行)
icon图标插槽,覆盖 type 默认图标
title标题富内容插槽,有内容时覆盖 title 属性文案

CSS 变量 ​

CSS 变量说明默认值
--oas-glass-blur—none
--oas-glass-refraction液态玻璃边缘折射滤镜(data-glass 生效,默认 none);局部停用覆盖为空值(--oas-glass-refraction: ;)——不得用 none(与 button 态的 brightness() 混排会使整条 filter 声明非法)none
--oas-glass-ring—transparent
--oas-notification-progress-color倒计时进度条颜色var(--oas-color-primary)
--oas-notification-width卡片宽度(尺寸档位内部引用)320px

方法 ​

方法说明
notification.info({ title, description?, content?, duration?, showProgress?, progressPosition?, scrollable?, position?, max?, offset?, container?, priority?, stackMode?, stackThreshold?, key?, onClose?, onClick?, closable?, pauseOnHover?, size?, icon?, closeIcon?, footer? })信息通知,返回 { close }
notification.success(...) / notification.warning(...) / notification.error(...)成功/警告/错误通知,options 同上
notification.loading(...)loading 态:spinner 图标、不自动关、不可手动关
notification.promise(p, { loading, success, error })promise 链:loading → 成功切 success(4500ms 自动关)/ 失败切 error
notification.update(key, { title?, description?, content?, duration?, type? })更新已存在通知(key 定位);key 不存在则新建
notification.destroy(key)关闭指定 key 的通知;不存在静默无操作
destroyAllNotification()清空全部通知(不触发 onClose)
  • position 四角:top-right(默认)/ top-left / bottom-right / bottom-left,每角独立栈容器。
  • max 同栈数量上限(默认 0 不限),超限丢最老——优先丢最老的 normal,全 high 才丢最老 high;被挤出同样触发 onClose(source: 'evict')。
  • offset 栈距视口边偏移(默认 16),作用于当前 position 方向;container 覆盖挂载目标(默认最近 app 宿主或 body)。
  • priority:high 恒占最新侧(后续 normal 插到其前),抢占语义由插入排序 + max 挤出策略共同实现。
  • stackMode 栈治理:collapsible(超过 stackThreshold 默认 3 折叠旧通知,"+N" 徽章点击展开/收起)/ peek(非最新卡收起为边缘条,hover 栈展开)。
  • onClose 关闭统一触发一次;onClick 通知体点击回调;closable 默认 true;pauseOnHover 默认开启(悬停暂停计时与进度条)。
  • title/icon/closeIcon/footer/content 支持 Node 富内容通道;footer 也接受 Node 数组。
  • 命令式创建的通知挂最近 oas-app 宿主(无则 body),role="region" + aria-label,右上角堆叠。

基于 MIT OR Apache-2.0 双许可发布