Files
aurora-admin/site/m/component/mobile-message.html
T
aurora-admin 5ee5d829a4
Regression / regression (push) Canceled after 0s
refactor(详情页+S8): 详情页减重(导航互斥/入口去重/i18n去重) + 品牌标识入库
本提交含两条并行工作线,因互相咬合(package.json scripts、regression.yml、
npm run build 链)无法按文件干净拆分,故合并为一次自洽提交。

## 详情页减重(本轮主任务:修复「AI 干太重」)

- 导航收敛:宽屏只用右侧目录、≤1200px 只用页内 sticky 导航,纯 CSS 媒体查询
  实现(不引入 JS 宽度监听)。此前两套导航同时可见,active 状态互相打架。
- 入口去重:标题区由「查看示例/在线测试/契约 JSON」三个减为「在线测试」一个;
  契约 JSON 归入实现资源;删除示例底部重复的「在线测试」。
- 示例工具栏:删除与目录锚点重复的示例下拉选择器;「全部展开代码」只在
  示例数 >1 时出现(103 个组件里 49 个仅 1 个示例,此前恒显示)。
- 重复文案:示例区两句同义导语合并为一句。
- 首页 CTA 由 5 个减为 2 个(浏览组件/快速开始),测试总览入口挂到已有的
  通过率统计卡上,不再另占 Hero 按钮。
- 统一详情取数:抽出 fetchDetail/loadDetail 作为 details/*.json 的唯一路径,
  FAQ 不再自行 fetch 一遍,与组件页共用缓存与失败兜底。

## i18n

- 删除 12 组重复键(含整段 FAQ 说明),字典 604 → 585 唯一键。
- 删除本次改动产生的 6 个死键。
- verify-i18n.mjs 新增 `unique dictionary keys` 断言:重复键在对象字面量里
  是静默的后值覆盖,此前无从发现;现由门禁拦住。

## 文档事实修正(实测为准)

- TESTING/CONTRIBUTING:79 → 103 组件;旧断言数改为回指 tests/report.json。
- PLATFORMS:移动端 108 文件/18 端 → 282 文件/47 端;契约 5 → 47;
  令牌 17 → 15;uni-app SFC 21 → 50。
- AGENTS:断言 1405/18 页 → 1464/103 页(PC)、807/47 页(移动端)。
- package.json:YOUR-ACCOUNT 占位 → gitea 实址与 kole-ui.mymoyu.top。

## 品牌标识(并行会话成果,一并入库)

- brand-mark.json 收归真源,build:brand 生成 favicon 与单色 SVG;
  PC 与移动端共用资产,verify:brand 24 条断言。
- regression.yml 增加 verify:brand 步骤。

## 门禁与验收

新增工具:verify-component-page.mjs(86 条真实浏览器断言,随详情页改造同步
更新为「只允许一套导航可见」)、verify-brand-mark.mjs、lib/i18n-dead-keys.mjs
(只读诊断)。

回归:PC 100%(1464/1464,103 页,N/A 50)· 移动端 100%(807/807,47 页)。
门禁:component-page 86 · i18n 17 · brand 24 · routes all · smoke all ·
theme OK · isolation 31 · nav all · examples 9 · api-docs 10 · mobile-docs 12。

已知未做:i18n 另有约 44 条历史死键(非本次产生),已记为 ROADMAP S8-P6;
顶栏与悬浮区的两个主题入口为刻意设计(verify-theme 断言其互斥),未删。
2026-09-22 23:56:05 +08:00

1731 lines
91 KiB
HTML
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.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
(function () {
var m = 'auto';
try { var v = localStorage.getItem('kole-mode'); if (v === 'light' || v === 'dark' || v === 'auto') m = v; } catch (e) {}
var dark = m === 'dark' || (m === 'auto' && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches);
document.documentElement.classList.toggle('kole-dark', !!dark);
document.documentElement.style.colorScheme = dark ? 'dark' : 'light';
})();
</script>
<link rel="icon" href="../../assets/kole-mark.svg">
<meta name="theme-color" content="#FFFFFF" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#1C1F26" media="(prefers-color-scheme: dark)">
<title>消息通知 Message — Kole UI Mobile</title>
<meta name="description" content="消息通知 Message:移动端组件(6 端实现:CSS / H5 原生 / React / Vue 2 / Vue 3 / uni-app)。与 PC 端物理隔离:类名 kole-m-、令牌 --kole-m-。规格来源:移动端规格 42 · 消息通知 Message。">
<link rel="stylesheet" href="../../../.design_library/kole-ui-mobile/colors_and_type.css">
<link rel="stylesheet" href="../style.css">
</head>
<body>
<header class="m-top">
<div class="m-top-inner">
<a class="m-logo" href="../index.html">
<span class="m-logo-mark" data-brand-mark="mono" aria-hidden="true"></span>
<span class="m-logo-text">Kole UI<em>移动端</em></span>
</a>
<div class="m-ver-picker" id="m-ver-picker">
<button id="m-ver-trigger" class="m-ver-trigger" type="button" data-single="1" aria-haspopup="listbox" aria-expanded="false" aria-label="选择版本" title="文档版本(清单来自部署根的 versions.json)">
<span id="m-ver">v1.0.0</span>
<svg class="m-ver-caret" width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg>
</button>
<div id="m-ver-menu" class="m-ver-menu hidden" role="listbox" aria-label="文档版本">
<div class="m-ver-menu-head" id="m-ver-head">文档版本</div>
</div>
</div>
<nav class="m-nav"> <a href="../index.html" class="active" aria-current="page">组件总览</a>
<a href="../guide.html">快速开始</a>
<a href="../design.html">设计规范</a>
<a href="../faq.html">常见问题</a>
<a href="../changelog.html">更新日志</a></nav>
<div class="m-mode">
<button id="m-mode-trigger" class="m-mode-trigger" type="button" aria-haspopup="listbox" aria-expanded="false" aria-label="主题模式" title="主题模式">
<svg class="m-mode-icon" id="m-icon-moon" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/></svg>
<svg class="m-mode-icon" id="m-icon-sun" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"/></svg>
<svg class="m-mode-icon" id="m-icon-auto" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><rect x="3" y="4" width="18" height="13" rx="2"/><path d="M8 21h8M12 17v4"/></svg>
<span id="m-mode-cur">自动模式</span>
<svg class="m-mode-caret" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg>
</button>
<div id="m-mode-menu" class="m-menu hidden" role="listbox" aria-label="主题模式">
<div class="m-menu-head">主题模式</div>
<button class="m-menu-opt" type="button" role="option" data-mode="light" aria-selected="false"><span data-mode-label="light">日间模式</span></button>
<button class="m-menu-opt" type="button" role="option" data-mode="dark" aria-selected="false"><span data-mode-label="dark">夜间模式</span></button>
<button class="m-menu-opt" type="button" role="option" data-mode="auto" aria-selected="true"><span data-mode-label="auto">自动模式</span></button>
</div>
</div>
</div>
</header>
<div class="m-body">
<details class="m-side" open>
<summary><span>移动端导航</span><span class="cur">消息通知</span></summary>
<nav>
<div class="m-side-section"><span>平台</span></div>
<a class="m-side-link m-side-platform" href="../../index.html"><span class="sp-top"><span class="sp-name">PC 端组件</span></span><span class="sp-sub">103 个中后台组件 · 5 端</span></a>
<a class="m-side-link m-side-platform" href="../index.html"><span class="sp-top"><span class="sp-name">移动端组件</span><span class="sp-badge">当前</span></span><span class="sp-sub">47 个组件 · 6 端 · 含 uni-app</span></a>
<div class="m-side-section"><span>开发指南</span></div>
<a class="m-side-link" href="../index.html">组件总览</a>
<a class="m-side-link" href="../guide.html">快速开始</a>
<a class="m-side-link" href="../design.html">设计规范</a>
<a class="m-side-link" href="../faq.html">常见问题</a>
<a class="m-side-link" href="../changelog.html">更新日志</a>
<a class="m-side-link" href="../platform.html">平台与端<em>移动端</em></a>
<a class="m-side-link" href="../../../tests/mobile/index.html" target="_blank">测试与回归<em>移动端</em></a>
<div class="m-side-section"><span>组件</span><span class="cnt">47</span></div>
<div class="m-side-group"><span>通用</span><span class="cnt">5</span></div>
<a class="m-side-link" href="mobile-button.html">按钮<em>Button</em></a>
<a class="m-side-link" href="mobile-divider.html">分割线<em>Divider</em></a>
<a class="m-side-link" href="mobile-icon.html">图标<em>Icon</em></a>
<a class="m-side-link" href="mobile-layout.html">布局<em>Layout</em></a>
<a class="m-side-link" href="mobile-link.html">链接<em>Link</em></a>
<div class="m-side-group"><span>导航</span><span class="cnt">6</span></div>
<a class="m-side-link" href="navbar.html">顶部导航栏<em>NavBar</em></a>
<a class="m-side-link" href="tabbar.html">底部标签栏<em>TabBar</em></a>
<a class="m-side-link" href="mobile-grid.html">宫格<em>Grid</em></a>
<a class="m-side-link" href="mobile-steps.html">步骤条<em>Steps</em></a>
<a class="m-side-link" href="mobile-segmented.html">分段器<em>Segmented</em></a>
<a class="m-side-link" href="mobile-sticky.html">吸顶容器<em>Sticky</em></a>
<div class="m-side-group"><span>数据录入</span><span class="cnt">16</span></div>
<a class="m-side-link" href="mobile-numberkeyboard.html">数字键盘<em>NumberKeyboard</em></a>
<a class="m-side-link" href="mobile-datepicker.html">日期选择器<em>DatePicker</em></a>
<a class="m-side-link" href="mobile-input.html">输入框<em>Input</em></a>
<a class="m-side-link" href="mobile-search.html">搜索框<em>Search</em></a>
<a class="m-side-link" href="mobile-stepper.html">步进器<em>Stepper</em></a>
<a class="m-side-link" href="mobile-switch.html">开关<em>Switch</em></a>
<a class="m-side-link" href="mobile-textarea.html">多行文本框<em>Textarea</em></a>
<a class="m-side-link" href="mobile-checkbox.html">多选框<em>Checkbox</em></a>
<a class="m-side-link" href="mobile-form.html">表单<em>Form</em></a>
<a class="m-side-link" href="mobile-radio.html">单选框<em>Radio</em></a>
<a class="m-side-link" href="mobile-rate.html">评分<em>Rate</em></a>
<a class="m-side-link" href="mobile-slider.html">滑动选择器<em>Slider</em></a>
<a class="m-side-link" href="mobile-cascader.html">级联选择器<em>Cascader</em></a>
<a class="m-side-link" href="mobile-colorpicker.html">颜色选择器<em>ColorPicker</em></a>
<a class="m-side-link" href="mobile-picker.html">选择器<em>Picker</em></a>
<a class="m-side-link" href="mobile-upload.html">上传<em>Upload</em></a>
<div class="m-side-group"><span>数据展示</span><span class="cnt">8</span></div>
<a class="m-side-link" href="cell.html">单元格<em>Cell</em></a>
<a class="m-side-link" href="mobile-badge.html">徽标<em>Badge</em></a>
<a class="m-side-link" href="mobile-tag.html">标签<em>Tag</em></a>
<a class="m-side-link" href="mobile-avatar.html">头像<em>Avatar</em></a>
<a class="m-side-link" href="mobile-list.html">列表<em>List</em></a>
<a class="m-side-link" href="mobile-collapse.html">折叠面板<em>Collapse</em></a>
<a class="m-side-link" href="mobile-table.html">表格<em>Table</em></a>
<a class="m-side-link" href="mobile-typography.html">排版<em>Typography</em></a>
<div class="m-side-group"><span>反馈</span><span class="cnt">12</span></div>
<a class="m-side-link" href="actionsheet.html">动作面板<em>ActionSheet</em></a>
<a class="m-side-link" href="pullrefresh.html">下拉刷新<em>PullRefresh</em></a>
<a class="m-side-link" href="swipecell.html">滑动单元格<em>SwipeCell</em></a>
<a class="m-side-link" href="mobile-popup.html">弹出层<em>Popup</em></a>
<a class="m-side-link" href="mobile-toast.html">轻提示<em>Toast</em></a>
<a class="m-side-link" href="mobile-dialog.html">对话框<em>Dialog</em></a>
<a class="m-side-link" href="mobile-noticebar.html">通知栏<em>NoticeBar</em></a>
<a class="m-side-link" href="mobile-loading.html">加载<em>Loading</em></a>
<a class="m-side-link" href="mobile-progress.html">进度条<em>Progress</em></a>
<a class="m-side-link is-active" href="mobile-message.html" aria-current="page">消息通知<em>Message</em></a>
<a class="m-side-link" href="mobile-overlay.html">遮罩层<em>Overlay</em></a>
<a class="m-side-link" href="mobile-popover.html">弹出气泡<em>Popover</em></a>
</nav>
</details>
<main class="m-main">
<section class="m-hero">
<h1>消息通知<span class="en" style="font-family: var(--kole-font-family-num); font-size: 14px; color: var(--kole-color-text-secondary); margin-left: 8px;">Message</span></h1>
<p>在页面顶部给一条不打断操作的结果提示(提交成功、网络异常、库存告警、操作回执)</p>
<p style="margin-top: 8px;" class="m-chips">
<span class="m-chip m">反馈</span>
<span class="m-chip">规格 42 · 消息通知 Message</span>
<span class="m-chip">6 端实现</span>
<span class="m-chip">触摸优先</span>
</p>
<div class="m-code" style="margin-top: var(--kole-space-12);">
<div class="m-code-head"><span>引入(H5 原生;其余 5 端见「快速开始」)</span><button class="m-copy" type="button" data-copy="code-import">复制</button></div>
<pre id="code-import"><code>&lt;!-- ① 令牌:PC 令牌 + 移动端 --kole-m-* 合成单文件,引一次 --&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;kole-ui/mobile/tokens.css&quot;&gt;
&lt;!-- ② 本组件样式(全量则用 kole-ui/mobile/components/index.css) --&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;kole-ui/mobile/components/mobile-message.css&quot;&gt;
&lt;!-- ③ 结构照抄下方任一演示块(类名与 6 端实现一致) --&gt;</code></pre>
</div>
</section>
<section class="m-block">
<h2 id="demo">演示</h2>
<p class="m-sub">每个演示都是真实渲染:预览帧加载 <code>frameworks-mobile/Message.html?demo=&lt;id&gt;</code>(只显示该演示块),代码是该演示块在演示页里的原文,可复制。全部演示同屏可看 <a href="../../../frameworks-mobile/Message.html" target="_blank">演示页 ↗</a>。</p>
<h3 class="m-demo-group">01 组件类型</h3>
<div class="m-demo" id="demo-tones">
<div class="m-demo-head"><span class="m-demo-title">四种语气</span><span class="m-chip">tone=info|success|warning|error</span></div>
<p class="m-demo-desc">信息 / 成功 / 警告 / 错误:图标与侧边描边同族变化,文字保持正文色以保证对比度不随语气波动。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Message.html?demo=tones" title="消息通知 Message · 四种语气" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 40 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Message.html · tones</span><button class="m-copy" type="button" data-copy="code-demo-1">复制</button></div>
<pre id="code-demo-1"><code>&lt;section class=&quot;demo-block&quot; data-demo=&quot;tones&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;四种语气(tone=info / success / warning / error:图标与侧边描边同族,文字保持正文色)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;message-tones&quot;&gt;
&lt;div class=&quot;demo-frame__body&quot;&gt;
&lt;div class=&quot;demo-actions&quot;&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-info-trigger&quot;
data-behavior=&quot;click-toggles-class:#msg-info|is-open&quot;&gt;信息&lt;/button&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-success-trigger&quot;
data-behavior=&quot;click-toggles-class:#msg-success|is-open&quot;&gt;成功&lt;/button&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-warning-trigger&quot;
data-behavior=&quot;click-toggles-class:#msg-warning|is-open&quot;&gt;警告&lt;/button&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-error-trigger&quot;
data-behavior=&quot;click-toggles-class:#msg-error|is-open&quot;&gt;错误&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message&quot;&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--info&quot; id=&quot;msg-info&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;ℹ&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;已为你切换到最近使用的收货地址&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--success&quot; id=&quot;msg-success&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;✓&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;提交成功,预计 2 小时内审核完成&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--warning&quot; id=&quot;msg-warning&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;⚠&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;库存仅剩 2 件,下单后可能延迟发货&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--error&quot; id=&quot;msg-error&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;✕&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;网络异常,请检查连接后重试&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p class=&quot;demo-hint&quot;&gt;四条消息同一层并列,各自独立开关;点一次展开、再点一次收起。&lt;/p&gt;
&lt;/section&gt;</code></pre></div>
</details>
</div>
<div class="m-demo" id="demo-closable">
<div class="m-demo-head"><span class="m-demo-title">可关闭</span><span class="m-chip">closable=true</span></div>
<p class="m-demo-desc">closable=true:右侧 × 是原生 button、热区 44px;需要用户读完的长文案给一条显式关闭路径。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Message.html?demo=closable" title="消息通知 Message · 可关闭" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 17 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Message.html · closable</span><button class="m-copy" type="button" data-copy="code-demo-2">复制</button></div>
<pre id="code-demo-2"><code>&lt;section class=&quot;demo-block&quot; data-demo=&quot;closable&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;可关闭(closable=true:右侧 × 是原生 button,热区 44px,点它立即收起)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;message-closable&quot;&gt;
&lt;div class=&quot;demo-frame__body&quot;&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-closable-trigger&quot;
data-behavior=&quot;click-toggles-class:#msg-closable|is-open&quot;&gt;显示可关闭消息&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message&quot;&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--info&quot; id=&quot;msg-closable&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;ℹ&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;本次更新包含 3 项改进,点右侧 ✕ 立即收起&lt;/span&gt;
&lt;button class=&quot;kole-m-message__close&quot; type=&quot;button&quot; aria-label=&quot;关闭消息&quot;&gt;✕&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;</code></pre></div>
</details>
</div>
<h3 class="m-demo-group">02 组件状态</h3>
<div class="m-demo" id="demo-duration">
<div class="m-demo-head"><span class="m-demo-title">自动消失</span><span class="m-chip">duration=3000</span></div>
<p class="m-demo-desc">duration 到点回传 close 由宿主收起;计时归宿主 —— 组件不持有默认时长以外的隐式行为。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Message.html?demo=duration" title="消息通知 Message · 自动消失" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 17 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Message.html · duration</span><button class="m-copy" type="button" data-copy="code-demo-3">复制</button></div>
<pre id="code-demo-3"><code>&lt;section class=&quot;demo-block&quot; data-demo=&quot;duration&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;自动消失(duration=3000:到点回传 close 由宿主收起;duration=0 时不自动收)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;message-duration&quot;&gt;
&lt;div class=&quot;demo-frame__body&quot;&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-duration-trigger&quot;
data-behavior=&quot;click-sets-attr:#msg-duration|data-open|true&quot;&gt;显示并在 3 秒后自动收起&lt;/button&gt;
&lt;p class=&quot;demo-hint&quot; id=&quot;msg-duration-tip&quot;&gt;计时归宿主:组件只负责显示态,到点回传 close&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message&quot;&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--success&quot; id=&quot;msg-duration&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;✓&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;已保存,3 秒后这条消息自动收起&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;</code></pre></div>
</details>
</div>
<div class="m-demo" id="demo-stack">
<div class="m-demo-head"><span class="m-demo-title">多条并列</span><span class="m-chip">多条同时 open</span></div>
<p class="m-demo-desc">消息层纵向排列,多条同时在场各自独立;同屏条数上限与合并策略由宿主决定。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Message.html?demo=stack" title="消息通知 Message · 多条并列" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 16 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Message.html · stack</span><button class="m-copy" type="button" data-copy="code-demo-4">复制</button></div>
<pre id="code-demo-4"><code>&lt;section class=&quot;demo-block&quot; data-demo=&quot;stack&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;多条并列(消息层纵向排列:新消息追加在下方,可同时在场)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;message-stack&quot;&gt;
&lt;div class=&quot;demo-frame__body&quot;&gt;两条消息同时在场,各自语气独立。&lt;/div&gt;
&lt;div class=&quot;kole-m-message&quot;&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--success is-open&quot; data-open=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;✓&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;图片上传完成(1/2)&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--warning is-open&quot; data-open=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;⚠&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;第 2 张超出 5MB,已跳过&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;</code></pre></div>
</details>
</div>
<div class="m-demo" id="demo-plain">
<div class="m-demo-head"><span class="m-demo-title">默认形态</span><span class="m-chip">closable=false</span></div>
<p class="m-demo-desc">不带关闭按钮也不阻断操作:消息层自身 pointer-events: none,下方页面仍可正常点击与滚动。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Message.html?demo=plain" title="消息通知 Message · 默认形态" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 17 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Message.html · plain</span><button class="m-copy" type="button" data-copy="code-demo-5">复制</button></div>
<pre id="code-demo-5"><code>&lt;section class=&quot;demo-block&quot; data-demo=&quot;plain&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;默认形态(不带关闭按钮、不阻断操作:消息层自身 pointer-events: none)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;message-plain&quot;&gt;
&lt;div class=&quot;demo-frame__body&quot;&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-plain-trigger&quot;
data-behavior=&quot;click-sets-attr:#msg-plain|data-open|true&quot;&gt;显示默认消息&lt;/button&gt;
&lt;p class=&quot;demo-hint&quot;&gt;消息浮在顶部,下面这行文字仍然可以正常选中与点击。&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message&quot;&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--info&quot; id=&quot;msg-plain&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;ℹ&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;已复制到剪贴板&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;</code></pre></div>
</details>
</div>
</section>
<section class="m-block">
<h2 id="api">API</h2>
<p class="m-sub">props / events / slots 为 6 端实现的公共接口(说明文字取自规格对应小节)。字段名与各端源码逐名核对:node tools/verify-mobile-docs.mjs</p>
<h3 class="m-h3">Props</h3>
<table class="m-table">
<thead><tr><th>名称</th><th>类型</th><th>默认值</th><th>说明</th><th>必传</th></tr></thead>
<tbody>
<tr><td><code>tone</code></td><td><code>'info' | 'success' | 'warning' | 'error'</code></td><td><code>'info'</code></td><td>变体 tone:语气配色与图标形态(规格 §42.3)</td><td>N</td></tr>
<tr><td><code>open</code></td><td><code>boolean</code></td><td><code>false</code></td><td>状态 open:展开可见(规格 §42.4)</td><td>N</td></tr>
<tr><td><code>text</code></td><td><code>string</code></td><td><code>''</code></td><td>消息文字;与默认插槽二选一,text 优先(规格 §42.2 text)</td><td>N</td></tr>
<tr><td><code>duration</code></td><td><code>number</code></td><td><code>3000</code></td><td>自动关闭时长(毫秒);0 表示不自动关闭(规格 §42.5)</td><td>N</td></tr>
<tr><td><code>closable</code></td><td><code>boolean</code></td><td><code>false</code></td><td>变体 closable:是否显示右侧关闭按钮(规格 §42.3)</td><td>N</td></tr>
</tbody>
</table>
<p class="m-note">「必传」按严格定义:实现里**没有默认值**时才为 Y(本门禁逐条核对 props 与各端源码的默认值,防止契约与实现脱节)。</p>
<h3 class="m-h3">事件</h3>
<table class="m-table">
<thead><tr><th>名称</th><th>参数</th><th>说明</th></tr></thead>
<tbody>
<tr><td><code>close</code></td><td><code>—</code></td><td>点关闭按钮或 duration 到点时触发;是否收起由宿主决定(规格 §42.5)</td></tr>
</tbody>
</table>
<h3 class="m-h3">插槽</h3>
<table class="m-table">
<thead><tr><th>名称</th><th>说明</th></tr></thead>
<tbody>
<tr><td><code>default</code></td><td>消息内容(与 text 二选一;text 优先)</td></tr>
</tbody>
</table>
<h3 class="m-h3">CSS 变量</h3>
<p class="m-sub">组件级变量(在组件样式表里定义)。业务侧可在自己的作用域内覆盖,不必改组件源码。</p>
<table class="m-table">
<thead><tr><th>名称</th><th>默认值</th><th>说明</th></tr></thead>
<tbody>
<tr><td><code>--kole-m-message-duration</code></td><td><code>240ms</code></td><td>组件内部默认值,可在业务侧覆盖</td></tr>
<tr><td><code>--kole-m-message-gap</code></td><td><code>var(--kole-space-8)</code></td><td>组件内部默认值,可在业务侧覆盖</td></tr>
</tbody>
</table>
</section>
<section class="m-block">
<h2 id="usage">何时使用</h2>
<ul>
<li>在页面顶部给一条不打断操作的结果提示(提交成功、网络异常、库存告警、操作回执)</li>
<li>触屏上页面就是有限的可视区域,所以消息浮在内容之上(fixed)且不吃手势(pointer-events: none),页面不跳</li>
<li>与 Toast 的分工:Toast 占据视口中央用于「结果就是你此刻唯一关心的事」,Message 贴顶部一条用于「要告诉你但不该拦着你」</li>
<li>组件形态:受控 open + 内容 props;duration 到点回传 close,由宿主决定是否收起</li>
<li>命令式调用由宿主侧组装 —— 命令式 API 需要单例容器与跨端定时器治理,组件不提供全局方法</li>
</ul>
</section>
<section class="m-block">
<h2 id="interaction">交互与触控</h2>
<ul>
<li>消息层不吃手势(根 pointer-events: none),只有关闭按钮自己接收手势</li>
<li>自动消失时长由宿主决定:duration=0 表示不自动关闭</li>
<li>入场从上滑下并淡入 240ms(--kole-m-duration-slide),减少动态偏好下瞬时切换</li>
<li>多条并列时纵向排列,新的追加在下方;同屏条数上限由宿主决定</li>
</ul>
</section>
<section class="m-block">
<h2 id="a11y">无障碍</h2>
<ul>
<li>每条消息 role=&quot;status&quot; + aria-live=&quot;polite&quot;:读屏朗读一次,不打断用户当前操作</li>
<li>语气图标 aria-hidden=&quot;true&quot;,语义全部由文字承担(颜色不是唯一的信息通道)</li>
<li>关闭按钮是原生 button 并带 aria-label,可用 Tab 聚焦、Enter 触发</li>
<li>消息不抢焦点:出现时不移动焦点,用户正在输入的内容不受影响</li>
</ul>
</section>
<section class="m-block">
<h2 id="related">相似组件</h2>
<p class="m-sub">从「该用哪一个」的角度区分;PC 端的对应实现见 <a href="../../index.html">PC 文档站</a>。</p>
<table class="m-table">
<thead><tr><th>组件</th><th>何时用它而不是本组件</th></tr></thead>
<tbody>
<tr><td><a href="mobile-toast.html">轻提示</a><em style="font-family: var(--kole-font-family-num); font-style: normal; font-size: 11px; color: var(--kole-color-text-placeholder); margin-left: 6px;">Toast</em></td><td>需要占据视口中央、让用户只看结果时用轻提示;顶部一条且不打断操作用消息通知</td></tr>
<tr><td><a href="mobile-noticebar.html">通知栏</a><em style="font-family: var(--kole-font-family-num); font-style: normal; font-size: 11px; color: var(--kole-color-text-placeholder); margin-left: 6px;">NoticeBar</em></td><td>常驻在页面里、随内容滚动的提醒用通知栏;消息通知浮在顶部且会消失</td></tr>
<tr><td><a href="mobile-dialog.html">对话框</a><em style="font-family: var(--kole-font-family-num); font-style: normal; font-size: 11px; color: var(--kole-color-text-placeholder); margin-left: 6px;">Dialog</em></td><td>需要用户先做决定再继续时用对话框,消息通知从不阻断操作</td></tr>
</tbody>
</table>
</section>
<section class="m-block">
<h2 id="gaps">规格未定 / 禁止发明</h2>
<table class="m-table">
<thead><tr><th>类别</th><th>条目</th></tr></thead>
<tbody>
<tr><td><span class="m-chip">禁止发明</span></td><td>自动关闭的默认时长与「超时后是否保留」的策略</td></tr>
<tr><td><span class="m-chip">禁止发明</span></td><td>多条消息的排队、合并、去重与同屏上限</td></tr>
<tr><td><span class="m-chip">禁止发明</span></td><td>命令式全局方法(Message.success() 这类)与其单例容器</td></tr>
<tr><td><span class="m-chip">禁止发明</span></td><td>消息内的操作按钮与跳转链接(需要动作时请用通知栏或对话框)</td></tr>
<tr><td><span class="m-chip">规格未定</span></td><td>tone=warning 与 error 是否需要不同的停留时长(当前统一由宿主传 duration)</td></tr>
<tr><td><span class="m-chip">规格未定</span></td><td>顶部多条同时出现时是否该限制为最多两条(当前不限,由宿主控制)</td></tr>
<tr><td><span class="m-chip">规格未定</span></td><td>是否需要在消息层上提供「点整条跳详情」的交互(当前只有可选的关闭按钮可点)</td></tr>
</tbody>
</table>
</section>
<section class="m-block">
<h2 id="anatomy">结构(anatomy)</h2>
<table class="m-table">
<thead><tr><th>字段</th><th>说明</th></tr></thead>
<tbody>
<tr><td><code>message</code></td><td>消息层根元素,顶部固定的纵向列表容器;pointer-events: none 让下方页面照常可点</td></tr>
<tr><td><code>item</code></td><td>单条消息,一行「图标 + 文字(+ 可选关闭)」,带 role=&quot;status&quot; 与 aria-live=&quot;polite&quot;</td></tr>
<tr><td><code>icon</code></td><td>语气图标(装饰),aria-hidden=&quot;true&quot;,语义由文字承担</td></tr>
<tr><td><code>text</code></td><td>消息文字,超长换行,不截断</td></tr>
<tr><td><code>close</code></td><td>可选的关闭按钮(原生 button,热区 44px)</td></tr>
</tbody>
</table>
</section>
<section class="m-block">
<h2 id="variants">变体维度与类名映射</h2>
<p class="m-sub">类名映射由构建脚本从契约 <code>variantClasses</code> 生成,并被 <code>verify:mobile-docs</code> 逐条对照组件 CSS 校验(类/变量必须真实存在)。</p>
<table class="m-table">
<thead><tr><th>维度</th><th>取值</th><th>对应类名 / 变量</th></tr></thead>
<tbody>
<tr><td><code>tone</code></td><td>info / success / warning / error</td><td><div><b>info</b> <span class="m-cls">.kole-m-message__item--info</span></div><div><b>success</b> <span class="m-cls">.kole-m-message__item--success</span></div><div><b>warning</b> <span class="m-cls">.kole-m-message__item--warning</span></div><div><b>error</b> <span class="m-cls">.kole-m-message__item--error</span></div></td></tr>
<tr><td><code>closable</code></td><td>false / true</td><td><div><b>false</b> <span class="m-none">(由数据驱动,无专属类)</span></div><div><b>true</b> <span class="m-cls">.kole-m-message__close</span></div></td></tr>
</tbody>
</table>
</section>
<section class="m-block">
<h2 id="rep-variants">代表变体</h2>
<table class="m-table">
<thead><tr><th>变体</th><th>标签</th></tr></thead>
<tbody>
<tr><td><code>tone=info · closable=false</code></td><td>信息(默认形态)</td></tr>
<tr><td><code>tone=success · closable=false</code></td><td>成功</td></tr>
<tr><td><code>tone=warning · closable=true</code></td><td>警告(需要用户读完,带关闭)</td></tr>
<tr><td><code>tone=error · closable=true</code></td><td>错误(带关闭)</td></tr>
</tbody>
</table>
</section>
<section class="m-block">
<h2 id="tokens">用到的令牌</h2>
<p class="m-sub">构建时从本组件样式表扫描得出。蓝色为移动端自有令牌,绿色为继承的 PC 令牌(改一处两端生效)。</p>
<div class="m-chips">
<span class="m-chip m" title="">--kole-m-ease-slide</span>
<span class="m-chip m" title="正文 / 列表项">--kole-m-font-size-body</span>
<span class="m-chip m" title="次级说明">--kole-m-font-size-label</span>
<span class="m-chip m" title="页面左右留白">--kole-m-gutter</span>
<span class="m-chip m" title="顶部安全区;支持 env() 时由 @supports 覆盖为 env(safe-area-inset-top)">--kole-m-safe-top</span>
<span class="m-chip m" title="可点区域最小边长">--kole-m-touch-target</span>
<span class="m-chip inherit" title="分割线/边框">--kole-color-border</span>
<span class="m-chip inherit" title="卡片背景">--kole-color-card-bg</span>
<span class="m-chip inherit" title="错误色 · 5.57:1(原 #F5222D 仅 4.08:1)">--kole-color-error</span>
<span class="m-chip inherit" title="输入框聚焦外发光">--kole-color-focus-ring</span>
<span class="m-chip inherit" title="信息色 · 5.00:1(原 #1890FF 仅 3.24:1)">--kole-color-info</span>
<span class="m-chip inherit" title="成功色 · 5.18:1(原 #52C41A 仅 2.27:1)">--kole-color-success</span>
<span class="m-chip inherit" title="表头背景">--kole-color-table-header-bg</span>
<span class="m-chip inherit" title="正文文字 · 14.0:1">--kole-color-text-body</span>
<span class="m-chip inherit" title="次要文字 · 5.10:1(原 #8C8C8C 仅 3.36:1)">--kole-color-text-secondary</span>
<span class="m-chip inherit" title="警告色 · 5.87:1(原 #FAAD14 仅 1.90:1)">--kole-color-warning</span>
<span class="m-chip inherit" title="">--kole-font-family</span>
<span class="m-chip inherit" title="">--kole-icon-size-16</span>
<span class="m-chip inherit" title="按钮、输入框、选择器">--kole-radius-base</span>
<span class="m-chip inherit" title="卡片悬停、下拉菜单、Popover">--kole-shadow-medium</span>
<span class="m-chip inherit" title="">--kole-space-12</span>
<span class="m-chip inherit" title="">--kole-space-8</span>
<span class="m-chip" title="组件级变量(可在业务侧覆盖)">--kole-m-message-duration</span>
<span class="m-chip" title="组件级变量(可在业务侧覆盖)">--kole-m-message-gap</span>
</div>
</section>
<section class="m-block">
<h2 id="sources">6 端源码</h2>
<p class="m-sub">同一组件的六份实现(生产环境的类名与结构一致,差异只在技术栈写法与单位)。点开查看,右侧可复制。</p>
<details class="m-details">
<summary>frameworks-mobile/Message.css · 纯样式(CSS) · 114 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Message.css</span><button class="m-copy" type="button" data-copy="code-229">复制</button></div>
<pre id="code-229"><code>/* Kole UI Mobile · Message 样式 — 对齐移动端规格 §42
轻量消息通知:顶部居中,一行「图标 + 文字」,四态(success / warning / error / info)。
与轻提示 Toast 的分工:Toast 占据视口中央并阻断交互,Message 贴在顶部、**不阻断**任何操作
(只占顶部一条,下面的页面照常可点),因此它的 z-index 低于遮罩与弹窗。
自动消失时长由宿主的定时器控制,本组件只负责显示态与退出动画。 */
.kole-m-message {
--kole-m-message-duration: 240ms;
--kole-m-message-gap: var(--kole-space-8);
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 1900;
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center;
gap: var(--kole-m-message-gap);
padding: calc(var(--kole-m-safe-top) + var(--kole-space-12)) var(--kole-m-gutter) 0;
pointer-events: none;
}
.kole-m-message__item {
box-sizing: border-box;
display: flex;
align-items: center;
gap: var(--kole-space-8);
width: 100%;
max-width: 343px;
min-height: var(--kole-m-touch-target);
padding: var(--kole-space-8) var(--kole-space-12);
border: 1px solid var(--kole-color-border);
border-radius: var(--kole-radius-base);
background: var(--kole-color-card-bg);
color: var(--kole-color-text-body);
font-family: var(--kole-font-family);
font-size: var(--kole-m-font-size-label);
line-height: 1.5;
box-shadow: var(--kole-shadow-medium);
/* 入场:从上方滑下 + 淡入;出场沿用同一个过渡(宿主移除 is-open 即可) */
opacity: 0;
transform: translateY(-100%);
transition: opacity var(--kole-m-message-duration) var(--kole-m-ease-slide),
transform var(--kole-m-message-duration) var(--kole-m-ease-slide);
}
.kole-m-message__item.is-open {
opacity: 1;
transform: translateY(0);
}
/* 变体 tone:四种语气(图标字形 + 侧边描边同族,文字保持正文色以保证对比度) */
.kole-m-message__item--info { border-inline-start: 3px solid var(--kole-color-info); }
.kole-m-message__item--success { border-inline-start: 3px solid var(--kole-color-success); }
.kole-m-message__item--warning { border-inline-start: 3px solid var(--kole-color-warning); }
.kole-m-message__item--error { border-inline-start: 3px solid var(--kole-color-error); }
.kole-m-message__icon {
flex: 0 0 auto;
display: inline-flex;
align-items: center;
justify-content: center;
width: var(--kole-icon-size-16);
font-size: var(--kole-m-font-size-body);
line-height: 1;
}
.kole-m-message__item--info .kole-m-message__icon { color: var(--kole-color-info); }
.kole-m-message__item--success .kole-m-message__icon { color: var(--kole-color-success); }
.kole-m-message__item--warning .kole-m-message__icon { color: var(--kole-color-warning); }
.kole-m-message__item--error .kole-m-message__icon { color: var(--kole-color-error); }
.kole-m-message__text {
flex: 1 1 auto;
min-width: 0;
word-break: break-word;
}
/* 关闭按钮(可选):原生 button,24px 视觉 + 44px 触控热区(靠 min-height 撑住) */
.kole-m-message__close {
flex: 0 0 auto;
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
width: var(--kole-m-touch-target);
height: var(--kole-m-touch-target);
margin-block: calc(-1 * var(--kole-space-8));
margin-inline-end: calc(-1 * var(--kole-space-8));
padding: 0;
border: 0;
border-radius: 50%;
background: none;
color: var(--kole-color-text-secondary);
font-family: inherit;
font-size: var(--kole-m-font-size-body);
line-height: 1;
cursor: pointer;
touch-action: manipulation;
pointer-events: auto;
}
.kole-m-message__close:active { background: var(--kole-color-table-header-bg); }
.kole-m-message__close:focus-visible {
outline: 2px solid var(--kole-color-focus-ring);
outline-offset: -2px;
}
@media (prefers-reduced-motion: reduce) {
.kole-m-message__item { transition: none; }
}
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Message.html · H5 原生(无框架) · 224 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Message.html</span><button class="m-copy" type="button" data-copy="code-230">复制</button></div>
<pre id="code-230"><code>&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;zh-CN&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, viewport-fit=cover&quot;&gt;
&lt;title&gt;Kole UI Mobile · Message(H5)&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;../.design_library/kole-ui-mobile/colors_and_type.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;Message.css&quot;&gt;
&lt;style&gt;
body { margin: 0; background: var(--kole-color-page-bg); font-family: var(--kole-font-family); color: var(--kole-color-text-body); }
.demo { max-width: 375px; margin: 0 auto; padding: var(--kole-m-gutter) 0; }
.demo-label { margin: 0; padding: var(--kole-space-12) var(--kole-m-gutter) var(--kole-space-8);
font-size: var(--kole-m-font-size-label); color: var(--kole-color-text-secondary); }
/* 展示框:transform 建立包含块,让 position: fixed 的消息层落在本框内(生产环境落在视口顶部)。
不做这一步,同页并列的多个消息层会全部叠在视口顶部,看起来「只渲染了一个」。 */
.demo-frame { position: relative; max-width: 375px; margin: 0 auto; height: 200px; overflow: hidden;
transform: translateZ(0); background: var(--kole-color-card-bg);
border-block: 1px solid var(--kole-color-border); }
.demo-frame__body { padding: var(--kole-space-12) var(--kole-m-gutter);
font-size: var(--kole-m-font-size-label); color: var(--kole-color-text-secondary); line-height: 1.7; }
.demo-actions { display: flex; flex-wrap: wrap; gap: var(--kole-space-8); }
.demo-trigger { min-height: var(--kole-m-touch-target); padding: 0 var(--kole-space-12);
border: 1px solid var(--kole-color-border); border-radius: var(--kole-radius-base);
background: var(--kole-color-card-bg); color: var(--kole-color-text-body);
font-family: inherit; font-size: var(--kole-m-font-size-label); cursor: pointer; touch-action: manipulation; }
.demo-trigger:focus-visible { outline: 2px solid var(--kole-color-focus-ring); outline-offset: 2px; }
.demo-hint { margin: 0; padding: var(--kole-space-8) var(--kole-m-gutter) 0;
font-size: var(--kole-m-font-size-caption); color: var(--kole-color-text-tertiary); }
.demo-block[hidden] { display: none; }
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;demo&quot;&gt;
&lt;section class=&quot;demo-block&quot; data-demo=&quot;tones&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;四种语气(tone=info / success / warning / error:图标与侧边描边同族,文字保持正文色)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;message-tones&quot;&gt;
&lt;div class=&quot;demo-frame__body&quot;&gt;
&lt;div class=&quot;demo-actions&quot;&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-info-trigger&quot;
data-behavior=&quot;click-toggles-class:#msg-info|is-open&quot;&gt;信息&lt;/button&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-success-trigger&quot;
data-behavior=&quot;click-toggles-class:#msg-success|is-open&quot;&gt;成功&lt;/button&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-warning-trigger&quot;
data-behavior=&quot;click-toggles-class:#msg-warning|is-open&quot;&gt;警告&lt;/button&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-error-trigger&quot;
data-behavior=&quot;click-toggles-class:#msg-error|is-open&quot;&gt;错误&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message&quot;&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--info&quot; id=&quot;msg-info&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;ℹ&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;已为你切换到最近使用的收货地址&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--success&quot; id=&quot;msg-success&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;✓&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;提交成功,预计 2 小时内审核完成&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--warning&quot; id=&quot;msg-warning&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;⚠&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;库存仅剩 2 件,下单后可能延迟发货&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--error&quot; id=&quot;msg-error&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;✕&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;网络异常,请检查连接后重试&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p class=&quot;demo-hint&quot;&gt;四条消息同一层并列,各自独立开关;点一次展开、再点一次收起。&lt;/p&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-block&quot; data-demo=&quot;closable&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;可关闭(closable=true:右侧 × 是原生 button,热区 44px,点它立即收起)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;message-closable&quot;&gt;
&lt;div class=&quot;demo-frame__body&quot;&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-closable-trigger&quot;
data-behavior=&quot;click-toggles-class:#msg-closable|is-open&quot;&gt;显示可关闭消息&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message&quot;&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--info&quot; id=&quot;msg-closable&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;ℹ&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;本次更新包含 3 项改进,点右侧 ✕ 立即收起&lt;/span&gt;
&lt;button class=&quot;kole-m-message__close&quot; type=&quot;button&quot; aria-label=&quot;关闭消息&quot;&gt;✕&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-block&quot; data-demo=&quot;duration&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;自动消失(duration=3000:到点回传 close 由宿主收起;duration=0 时不自动收)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;message-duration&quot;&gt;
&lt;div class=&quot;demo-frame__body&quot;&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-duration-trigger&quot;
data-behavior=&quot;click-sets-attr:#msg-duration|data-open|true&quot;&gt;显示并在 3 秒后自动收起&lt;/button&gt;
&lt;p class=&quot;demo-hint&quot; id=&quot;msg-duration-tip&quot;&gt;计时归宿主:组件只负责显示态,到点回传 close&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message&quot;&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--success&quot; id=&quot;msg-duration&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;✓&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;已保存,3 秒后这条消息自动收起&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-block&quot; data-demo=&quot;stack&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;多条并列(消息层纵向排列:新消息追加在下方,可同时在场)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;message-stack&quot;&gt;
&lt;div class=&quot;demo-frame__body&quot;&gt;两条消息同时在场,各自语气独立。&lt;/div&gt;
&lt;div class=&quot;kole-m-message&quot;&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--success is-open&quot; data-open=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;✓&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;图片上传完成(1/2)&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--warning is-open&quot; data-open=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;⚠&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;第 2 张超出 5MB,已跳过&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-block&quot; data-demo=&quot;plain&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;默认形态(不带关闭按钮、不阻断操作:消息层自身 pointer-events: none)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;message-plain&quot;&gt;
&lt;div class=&quot;demo-frame__body&quot;&gt;
&lt;button class=&quot;demo-trigger&quot; type=&quot;button&quot; id=&quot;msg-plain-trigger&quot;
data-behavior=&quot;click-sets-attr:#msg-plain|data-open|true&quot;&gt;显示默认消息&lt;/button&gt;
&lt;p class=&quot;demo-hint&quot;&gt;消息浮在顶部,下面这行文字仍然可以正常选中与点击。&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-message&quot;&gt;
&lt;div class=&quot;kole-m-message__item kole-m-message__item--info&quot; id=&quot;msg-plain&quot;
role=&quot;status&quot; aria-live=&quot;polite&quot; data-open=&quot;false&quot;&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;ℹ&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;已复制到剪贴板&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;/div&gt;
&lt;script&gt;
/* 演示页交互:类名与 data-open 由**同一个函数**写入(避免视觉与状态分叉)。
每块自带开关,互不依赖:触发器 id 与消息 id 成对写在下方映射里,
因此任一 `?demo=&lt;id&gt;` 单块预览都能独立工作。 */
(function () {
function setOpen(el, open) {
el.classList.toggle('is-open', open);
el.setAttribute('data-open', open ? 'true' : 'false');
}
function bind(triggerId, itemId, mode) {
var trig = document.getElementById(triggerId);
var item = document.getElementById(itemId);
if (!trig || !item) return;
trig.addEventListener('click', function () {
if (mode === 'show') setOpen(item, true);
else setOpen(item, !item.classList.contains('is-open'));
});
}
/* 四种语气:点一次展开、再点一次收起 */
bind('msg-info-trigger', 'msg-info', 'toggle');
bind('msg-success-trigger', 'msg-success', 'toggle');
bind('msg-warning-trigger', 'msg-warning', 'toggle');
bind('msg-error-trigger', 'msg-error', 'toggle');
bind('msg-closable-trigger', 'msg-closable', 'toggle');
bind('msg-plain-trigger', 'msg-plain', 'show');
/* 可关闭:点 × 只关它自己那一条 */
document.querySelectorAll('.kole-m-message__close').forEach(function (btn) {
btn.addEventListener('click', function () {
var item = btn.closest('.kole-m-message__item');
if (item) setOpen(item, false);
});
});
/* 自动消失:时长由宿主决定(这里演示 3000ms),到点收起。
组件不持有默认时长 —— 规格 §42.7 明确把这条留给宿主。 */
var dur = document.getElementById('msg-duration');
var durTrig = document.getElementById('msg-duration-trigger');
var tip = document.getElementById('msg-duration-tip');
var timer = null;
if (dur &amp;&amp; durTrig) {
durTrig.addEventListener('click', function () {
if (timer) clearTimeout(timer);
setOpen(dur, true);
if (tip) tip.textContent = '显示中…3 秒后自动收起';
timer = setTimeout(function () {
setOpen(dur, false);
timer = null;
if (tip) tip.textContent = '已自动收起(计时归宿主:组件只负责显示态)';
}, 3000);
});
}
})();
&lt;/script&gt;
&lt;script&gt;
/* ?demo=&lt;id&gt; → 只显示该演示块(文档站按块预览用;无参数时全部显示,测试与回归走无参数路径) */
(function () {
var id = new URLSearchParams(location.search).get('demo');
if (!id) return;
var blocks = Array.prototype.slice.call(document.querySelectorAll('.demo-block'));
var hit = false;
blocks.forEach(function (b) {
var on = b.getAttribute('data-demo') === id;
if (on) hit = true;
b.hidden = !on;
});
if (!hit) { blocks.forEach(function (b) { b.hidden = false; }); return; }
document.body.classList.add('demo-single');
var demoBox = document.querySelector('.demo');
if (demoBox) demoBox.style.minHeight = 'auto';
blocks.forEach(function (b) {
var label = b.querySelector('.demo-label');
if (label &amp;&amp; !b.hidden) label.hidden = true;
});
})();
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Message.jsx · React · 59 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Message.jsx</span><button class="m-copy" type="button" data-copy="code-231">复制</button></div>
<pre id="code-231"><code>import React, { useEffect, useRef } from 'react';
import './Message.css';
/* 消息通知(移动端)— 规格 §42
顶部居中、不阻断操作(根是 pointer-events: none,只有关闭按钮自己接收手势)。
**两种用法**:
① 组件形态(本文件导出的即此形态):受控 open + 内容 props,计时到点回传 onClose;
② 命令式调用:宿主自己维护一个列表与定时器(见规格 §42.5),本组件不提供全局方法 ——
命令式 API 需要单例容器与跨端定时器,属于宿主或框架层的职责(规格 §42.7)。
本组件只暴露组件形态的 props / events。 */
export default function Message({
tone = 'info',
open = false,
text = '',
duration = 3000,
closable = false,
onClose,
children = null,
}) {
/* 自动消失:计时归宿主(duration 由调用方决定),组件只负责「到点回传 close」。
duration=0 表示不自动关闭。open / duration 变化时重新计时。
回调放 ref:把 onClose 写进依赖会让「宿主传内联箭头函数」的常见写法每次渲染都重置计时器,
计时永远到不了点(定时器形同虚设),而这不是调用方的错。 */
const closeRef = useRef(onClose);
closeRef.current = onClose;
useEffect(() =&gt; {
if (!open || !duration) return undefined;
const timer = setTimeout(() =&gt; {
if (closeRef.current) closeRef.current();
}, duration);
return () =&gt; clearTimeout(timer);
}, [open, duration]);
const cls = 'kole-m-message__item kole-m-message__item--' + tone + (open ? ' is-open' : '');
return (
&lt;div className=&quot;kole-m-message&quot;&gt;
&lt;div className={cls} role=&quot;status&quot; aria-live=&quot;polite&quot; data-open={open ? 'true' : 'false'}&gt;
&lt;span className=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;
{tone === 'success' ? '✓' : tone === 'warning' ? '⚠' : tone === 'error' ? '✕' : 'ℹ'}
&lt;/span&gt;
&lt;span className=&quot;kole-m-message__text&quot;&gt;{text || children}&lt;/span&gt;
{closable ? (
&lt;button
className=&quot;kole-m-message__close&quot;
type=&quot;button&quot;
aria-label=&quot;关闭消息&quot;
onClick={() =&gt; {
if (onClose) onClose();
}}
&gt;
✕
&lt;/button&gt;
) : null}
&lt;/div&gt;
&lt;/div&gt;
);
}
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Message.vue2.vue · Vue 2 · 85 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Message.vue2.vue</span><button class="m-copy" type="button" data-copy="code-232">复制</button></div>
<pre id="code-232"><code>&lt;template&gt;
&lt;div class=&quot;kole-m-message&quot;&gt;
&lt;div
class=&quot;kole-m-message__item&quot;
:class=&quot;itemClass&quot;
role=&quot;status&quot;
aria-live=&quot;polite&quot;
:data-open=&quot;open ? 'true' : 'false'&quot;
&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;{{ glyph }}&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;&lt;slot&gt;{{ text }}&lt;/slot&gt;&lt;/span&gt;
&lt;button
v-if=&quot;closable&quot;
class=&quot;kole-m-message__close&quot;
type=&quot;button&quot;
aria-label=&quot;关闭消息&quot;
@click=&quot;$emit('close')&quot;
&gt;✕&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/template&gt;
&lt;script&gt;
var GLYPH = { info: 'ℹ', success: '✓', warning: '⚠', error: '✕' };
export default {
name: 'KoleMMessage',
props: {
tone: { type: String, default: 'info' },
open: { type: Boolean, default: false },
text: { type: String, default: '' },
duration: { type: Number, default: 3000 },
closable: { type: Boolean, default: false }
},
data: function () {
return { timer: null };
},
computed: {
glyph: function () {
return GLYPH[this.tone] || GLYPH.info;
},
itemClass: function () {
return [
'kole-m-message__item--' + this.tone,
this.open ? 'is-open' : ''
].filter(Boolean);
}
},
watch: {
open: function () {
this.schedule();
},
duration: function () {
this.schedule();
}
},
mounted: function () {
this.schedule();
},
beforeDestroy: function () {
this.clear();
},
methods: {
clear: function () {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
},
/* 自动消失:计时归宿主(duration 由调用方决定),组件只负责「到点回传 close」 */
schedule: function () {
this.clear();
var self = this;
if (this.open &amp;&amp; this.duration) {
this.timer = setTimeout(function () {
self.$emit('close');
}, this.duration);
}
}
}
};
&lt;/script&gt;
&lt;style src=&quot;./Message.css&quot;&gt;&lt;/style&gt;
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Message.vue3.vue · Vue 3 · 77 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Message.vue3.vue</span><button class="m-copy" type="button" data-copy="code-233">复制</button></div>
<pre id="code-233"><code>&lt;template&gt;
&lt;div class=&quot;kole-m-message&quot;&gt;
&lt;div
class=&quot;kole-m-message__item&quot;
:class=&quot;itemClass&quot;
role=&quot;status&quot;
aria-live=&quot;polite&quot;
:data-open=&quot;open ? 'true' : 'false'&quot;
&gt;
&lt;span class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;{{ glyph }}&lt;/span&gt;
&lt;span class=&quot;kole-m-message__text&quot;&gt;{{ content }}&lt;/span&gt;
&lt;button
v-if=&quot;closable&quot;
class=&quot;kole-m-message__close&quot;
type=&quot;button&quot;
aria-label=&quot;关闭消息&quot;
@click=&quot;onCloseClick&quot;
&gt;✕&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/template&gt;
&lt;script setup&gt;
import { computed, onBeforeUnmount, useSlots, watch } from 'vue';
const props = defineProps({
tone: { type: String, default: 'info' },
open: { type: Boolean, default: false },
text: { type: String, default: '' },
duration: { type: Number, default: 3000 },
closable: { type: Boolean, default: false }
});
const emit = defineEmits(['close']);
const slots = useSlots();
const content = computed(() =&gt; {
if (props.text) return props.text;
const nodes = slots.default ? slots.default() : [];
return nodes.map((n) =&gt; (typeof n.children === 'string' ? n.children : '')).join('');
});
const GLYPH = { info: 'ℹ', success: '✓', warning: '⚠', error: '✕' };
const glyph = computed(() =&gt; GLYPH[props.tone] || GLYPH.info);
const itemClass = computed(() =&gt; [
`kole-m-message__item--${props.tone}`,
props.open ? 'is-open' : ''
].filter(Boolean));
/* 自动消失:计时归宿主(duration 由调用方决定),组件只负责「到点回传 close」。
duration=0 表示不自动关闭;open 变化时重新计时。 */
let timer = null;
function clear() {
if (timer) {
clearTimeout(timer);
timer = null;
}
}
watch(
() =&gt; [props.open, props.duration],
() =&gt; {
clear();
if (props.open &amp;&amp; props.duration) {
timer = setTimeout(() =&gt; emit('close'), props.duration);
}
},
{ immediate: true }
);
onBeforeUnmount(clear);
function onCloseClick() {
emit('close');
}
&lt;/script&gt;
&lt;style src=&quot;./Message.css&quot;&gt;&lt;/style&gt;
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Message.uniapp.vue · uni-app(跨端:小程序 / App / H5) · 155 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Message.uniapp.vue</span><button class="m-copy" type="button" data-copy="code-234">复制</button></div>
<pre id="code-234"><code>&lt;template&gt;
&lt;view class=&quot;kole-m-message&quot;&gt;
&lt;view
class=&quot;kole-m-message__item&quot;
:class=&quot;itemClass&quot;
:role=&quot;'status'&quot;
:aria-label=&quot;content&quot;
:data-open=&quot;open ? 'true' : 'false'&quot;
&gt;
&lt;text class=&quot;kole-m-message__icon&quot; aria-hidden=&quot;true&quot;&gt;{{ glyph }}&lt;/text&gt;
&lt;text class=&quot;kole-m-message__text&quot;&gt;{{ content }}&lt;/text&gt;
&lt;view
v-if=&quot;closable&quot;
class=&quot;kole-m-message__close&quot;
role=&quot;button&quot;
aria-label=&quot;关闭消息&quot;
@tap=&quot;onCloseTap&quot;
&gt;
&lt;text&gt;✕&lt;/text&gt;
&lt;/view&gt;
&lt;/view&gt;
&lt;/view&gt;
&lt;/template&gt;
&lt;script setup&gt;
/* uni-app 端 · 消息通知(移动端)— 规格 §42
跨端差异:小程序 / App 端的读屏主要认 aria-label(aria-live 支持不一致),
因此这里把整条消息的名称写在 aria-label 上,图标 aria-hidden。
自动消失仍由本端定时器控制(duration 由调用方决定),到点回传 close。
尺寸用 rpx(2rpx ≈ 1px,88rpx = 44px 触控最小边长)。 */
import { computed, onBeforeUnmount, watch } from 'vue';
const props = defineProps({
tone: { type: String, default: 'info' },
open: { type: Boolean, default: false },
text: { type: String, default: '' },
duration: { type: Number, default: 3000 },
closable: { type: Boolean, default: false }
});
const emit = defineEmits(['close']);
const GLYPH = { info: 'ℹ', success: '✓', warning: '⚠', error: '✕' };
const glyph = computed(() =&gt; GLYPH[props.tone] || GLYPH.info);
const content = computed(() =&gt; props.text);
const itemClass = computed(() =&gt; [
`kole-m-message__item--${props.tone}`,
props.open ? 'is-open' : ''
].filter(Boolean));
let timer = null;
function clear() {
if (timer) {
clearTimeout(timer);
timer = null;
}
}
watch(
() =&gt; [props.open, props.duration],
() =&gt; {
clear();
if (props.open &amp;&amp; props.duration) {
timer = setTimeout(() =&gt; emit('close'), props.duration);
}
},
{ immediate: true }
);
onBeforeUnmount(clear);
function onCloseTap() {
emit('close');
}
&lt;/script&gt;
&lt;style&gt;
.kole-m-message {
--kole-m-message-duration: 240ms;
--kole-m-touch-target: 88rpx;
--kole-m-font-size-body: 32rpx;
--kole-m-font-size-label: 28rpx;
--kole-m-gutter: 32rpx;
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 1900;
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center;
padding: 24rpx var(--kole-m-gutter) 0;
}
.kole-m-message__item {
box-sizing: border-box;
display: flex;
align-items: center;
width: 100%;
min-height: var(--kole-m-touch-target);
padding: 16rpx 24rpx;
border: 2rpx solid var(--kole-color-border);
border-radius: 8rpx;
background-color: var(--kole-color-card-bg);
color: var(--kole-color-text-body);
font-size: var(--kole-m-font-size-label);
line-height: 1.5;
box-shadow: var(--kole-shadow-medium);
opacity: 0;
transform: translateY(-100%);
transition: opacity var(--kole-m-message-duration) ease-out;
}
.kole-m-message__item.is-open {
opacity: 1;
transform: translateY(0);
}
.kole-m-message__item--info { border-left: 6rpx solid var(--kole-color-info); }
.kole-m-message__item--success { border-left: 6rpx solid var(--kole-color-success); }
.kole-m-message__item--warning { border-left: 6rpx solid var(--kole-color-warning); }
.kole-m-message__item--error { border-left: 6rpx solid var(--kole-color-error); }
.kole-m-message__icon {
flex: 0 0 auto;
width: 32rpx;
font-size: var(--kole-m-font-size-body);
line-height: 1;
}
.kole-m-message__item--info .kole-m-message__icon { color: var(--kole-color-info); }
.kole-m-message__item--success .kole-m-message__icon { color: var(--kole-color-success); }
.kole-m-message__item--warning .kole-m-message__icon { color: var(--kole-color-warning); }
.kole-m-message__item--error .kole-m-message__icon { color: var(--kole-color-error); }
.kole-m-message__text {
flex: 1;
min-width: 0;
padding-left: 16rpx;
}
.kole-m-message__close {
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
width: var(--kole-m-touch-target);
height: var(--kole-m-touch-target);
margin-right: -16rpx;
border-radius: 50%;
color: var(--kole-color-text-secondary);
font-size: var(--kole-m-font-size-body);
}
&lt;/style&gt;
</code></pre>
</div>
</details>
</section>
<section class="m-block">
<h2 id="tests">测试与回归</h2>
<p class="m-sub">断言在真实的 375×640 设备帧里跑(引擎与 PC 侧共用 <code>tests/_runtime.js</code>,触控行为动词来自移动端 <code>tests/mobile/_behaviors.js</code>)。</p>
<p>
<span class="m-status pass">断言 22 条 · 全部通过</span>
<span class="m-status">报告 2026-09-22 03:04:00</span>
</p>
<div class="m-code">
<div class="m-code-head"><span>复现命令</span><button class="m-copy" type="button" data-copy="code-test">复制</button></div>
<pre id="code-test"><code>node site/dev-server.js &amp;
REG_BASE=http://127.0.0.1:3311 node tools/run-mobile-regression.mjs # 全量 5 个组件
npm run verify:mobile-docs # 本页内容完整性 + API 与源码一致性</code></pre>
</div>
</section>
<section class="m-block">
<h2 id="contract">设计契约</h2>
<details class="m-details">
<summary>components/mobile-message.json(点击展开原始 JSON)</summary>
<div class="m-code"><pre><code>{
"schemaVersion": 1,
"sourceKind": "authored-spec",
"provenance": "authored-in-repo",
"specFile": "spec/移动端规格.md",
"specSection": "42 · 消息通知 Message",
"confidence": "high",
"slug": "mobile-message",
"name": "消息通知 Message",
"semanticTypeCandidates": [
"message",
"notification",
"banner"
],
"variantDimensions": [
{
"name": "tone",
"values": [
"info",
"success",
"warning",
"error"
]
},
{
"name": "closable",
"values": [
"false",
"true"
]
}
],
"representativeVariants": [
{
"tone": "info",
"closable": "false",
"label": "信息(默认形态)"
},
{
"tone": "success",
"closable": "false",
"label": "成功"
},
{
"tone": "warning",
"closable": "true",
"label": "警告(需要用户读完,带关闭)"
},
{
"tone": "error",
"closable": "true",
"label": "错误(带关闭)"
}
],
"anatomy": {
"message": "消息层根元素,顶部固定的纵向列表容器;pointer-events: none 让下方页面照常可点",
"item": "单条消息,一行「图标 + 文字(+ 可选关闭)」,带 role=\"status\" 与 aria-live=\"polite\"",
"icon": "语气图标(装饰),aria-hidden=\"true\",语义由文字承担",
"text": "消息文字,超长换行,不截断",
"close": "可选的关闭按钮(原生 button,热区 44px)"
},
"structurePatterns": {
"tone": "info / success / warning / error —— 图标字形与侧边描边同族,文字保持正文色",
"closable": "false 读完自己消失 / true 右侧出现关闭按钮",
"状态类": "is-open 展开(滑下淡入 240ms)"
},
"usageHints": [
"在页面顶部给一条不打断操作的结果提示(提交成功、网络异常、库存告警、操作回执)",
"触屏上页面就是有限的可视区域,所以消息浮在内容之上(fixed)且不吃手势(pointer-events: none),页面不跳",
"与 Toast 的分工:Toast 占据视口中央用于「结果就是你此刻唯一关心的事」,Message 贴顶部一条用于「要告诉你但不该拦着你」",
"组件形态:受控 open + 内容 props;duration 到点回传 close,由宿主决定是否收起",
"命令式调用由宿主侧组装 —— 命令式 API 需要单例容器与跨端定时器治理,组件不提供全局方法"
],
"doNotInvent": [
"自动关闭的默认时长与「超时后是否保留」的策略",
"多条消息的排队、合并、去重与同屏上限",
"命令式全局方法(Message.success() 这类)与其单例容器",
"消息内的操作按钮与跳转链接(需要动作时请用通知栏或对话框)"
],
"unknowns": [
"tone=warning 与 error 是否需要不同的停留时长(当前统一由宿主传 duration)",
"顶部多条同时出现时是否该限制为最多两条(当前不限,由宿主控制)",
"是否需要在消息层上提供「点整条跳详情」的交互(当前只有可选的关闭按钮可点)"
],
"interaction": [
"消息层不吃手势(根 pointer-events: none),只有关闭按钮自己接收手势",
"自动消失时长由宿主决定:duration=0 表示不自动关闭",
"入场从上滑下并淡入 240ms(--kole-m-duration-slide),减少动态偏好下瞬时切换",
"多条并列时纵向排列,新的追加在下方;同屏条数上限由宿主决定"
],
"accessibility": [
"每条消息 role=\"status\" + aria-live=\"polite\":读屏朗读一次,不打断用户当前操作",
"语气图标 aria-hidden=\"true\",语义全部由文字承担(颜色不是唯一的信息通道)",
"关闭按钮是原生 button 并带 aria-label,可用 Tab 聚焦、Enter 触发",
"消息不抢焦点:出现时不移动焦点,用户正在输入的内容不受影响"
],
"api": {
"source": "implementation",
"note": "props / events / slots 为 6 端实现的公共接口(说明文字取自规格对应小节)。字段名与各端源码逐名核对:node tools/verify-mobile-docs.mjs",
"requiredNote": "「必传」按严格定义:实现里**没有默认值**时才为 Y(本门禁逐条核对 props 与各端源码的默认值,防止契约与实现脱节)。",
"props": [
{
"name": "tone",
"type": "'info' | 'success' | 'warning' | 'error'",
"default": "'info'",
"desc": "变体 tone:语气配色与图标形态(规格 §42.3)",
"required": false
},
{
"name": "open",
"type": "boolean",
"default": "false",
"desc": "状态 open:展开可见(规格 §42.4)",
"required": false
},
{
"name": "text",
"type": "string",
"default": "''",
"desc": "消息文字;与默认插槽二选一,text 优先(规格 §42.2 text)",
"required": false
},
{
"name": "duration",
"type": "number",
"default": "3000",
"desc": "自动关闭时长(毫秒);0 表示不自动关闭(规格 §42.5)",
"required": false
},
{
"name": "closable",
"type": "boolean",
"default": "false",
"desc": "变体 closable:是否显示右侧关闭按钮(规格 §42.3)",
"required": false
}
],
"events": [
{
"name": "close",
"params": "—",
"desc": "点关闭按钮或 duration 到点时触发;是否收起由宿主决定(规格 §42.5)"
}
],
"slots": [
{
"name": "default",
"desc": "消息内容(与 text 二选一;text 优先)"
}
]
},
"variantClasses": {
"tone": {
"info": [
".kole-m-message__item--info"
],
"success": [
".kole-m-message__item--success"
],
"warning": [
".kole-m-message__item--warning"
],
"error": [
".kole-m-message__item--error"
]
},
"closable": {
"false": [],
"true": [
".kole-m-message__close"
]
}
},
"demos": [
{
"id": "tones",
"group": "01 组件类型",
"title": "四种语气",
"desc": "信息 / 成功 / 警告 / 错误:图标与侧边描边同族变化,文字保持正文色以保证对比度不随语气波动。",
"variant": "tone=info|success|warning|error"
},
{
"id": "closable",
"group": "01 组件类型",
"title": "可关闭",
"desc": "closable=true:右侧 × 是原生 button、热区 44px;需要用户读完的长文案给一条显式关闭路径。",
"variant": "closable=true"
},
{
"id": "duration",
"group": "02 组件状态",
"title": "自动消失",
"desc": "duration 到点回传 close 由宿主收起;计时归宿主 —— 组件不持有默认时长以外的隐式行为。",
"variant": "duration=3000"
},
{
"id": "stack",
"group": "02 组件状态",
"title": "多条并列",
"desc": "消息层纵向排列,多条同时在场各自独立;同屏条数上限与合并策略由宿主决定。",
"variant": "多条同时 open"
},
{
"id": "plain",
"group": "02 组件状态",
"title": "默认形态",
"desc": "不带关闭按钮也不阻断操作:消息层自身 pointer-events: none,下方页面仍可正常点击与滚动。",
"variant": "closable=false"
}
],
"related": [
{
"slug": "mobile-toast",
"why": "需要占据视口中央、让用户只看结果时用轻提示;顶部一条且不打断操作用消息通知"
},
{
"slug": "mobile-noticebar",
"why": "常驻在页面里、随内容滚动的提醒用通知栏;消息通知浮在顶部且会消失"
},
{
"slug": "mobile-dialog",
"why": "需要用户先做决定再继续时用对话框,消息通知从不阻断操作"
}
]
}</code></pre></div>
</details>
</section>
<footer class="m-foot">
<p>生成物:本页由 <code>node tools/build-mobile.mjs</code> 从契约 <code>components/mobile-message.json</code> 与 6 端源码生成,请勿手改。</p>
<p>规格原文:<code>.design_library/kole-ui-mobile/spec/移动端规格.md</code> · 隔离门禁:<code>node tools/verify-mobile-isolation.mjs</code></p>
</footer>
</main>
</div>
<script>
(function () {
/* 左栏:≤1000px 默认收起(手机上不让导航占满一屏),跨断点时同步一次;不监听 resize,
免得跟用户手动的展开/收起抢状态。桌面不设 open 之外的动作。 */
var side = document.querySelector('details.m-side');
if (side && window.matchMedia) {
var mq = window.matchMedia('(max-width: 1000px)');
var sync = function () { if (mq.matches) side.removeAttribute('open'); else side.setAttribute('open', ''); };
sync();
if (mq.addEventListener) mq.addEventListener('change', sync);
else if (mq.addListener) mq.addListener(sync);
}
/* 单演示预览帧按内容高度自适应(同源可读 contentDocument;上限 360px、下限 140px)。
固定高度会在内容少的演示上留一大片空白(实测 SwipeCell 单个演示只用 ~120px)。 */
function fitDemoFrames() {
var frames = document.querySelectorAll('.m-demo-stage iframe');
Array.prototype.forEach.call(frames, function (f) {
var fit = function () {
try {
var d = f.contentDocument;
if (!d || !d.body) return;
/* 只量 body.scrollHeight:documentElement.scrollHeight 等于**帧视口高度**(html 撑满视口),
拿它做 max 会形成「帧高→视口高→量到的高度」反馈环,永远收敛在初始值(实测锁在 308px)。 */
var h = d.body.scrollHeight;
if (!h) h = d.documentElement ? d.documentElement.scrollHeight : 0;
if (!h) return;
f.style.height = Math.min(360, Math.max(140, h + 8)) + 'px';
} catch (e) { /* 跨源或未就绪:保持 CSS 兜底高度 */ }
};
f.addEventListener('load', function () { fit(); setTimeout(fit, 300); });
fit();
});
}
fitDemoFrames();
window.addEventListener('load', fitDemoFrames);
/* 主题模式(三态):与 PC 完全同一约定 —— localStorage[kole-mode] ∈ light|dark|auto,
auto 跟随系统,反色靠 html.kole-dark(令牌文件里已写好该组,两端共用一份令牌)。
用户在 PC 站选夜间,进移动端站也是夜间。 */
var MODE_KEY = 'kole-mode';
var MODE_LABEL = { light: '日间模式', dark: '夜间模式', auto: '自动模式' };
function readMode() {
try { var v = localStorage.getItem(MODE_KEY); if (v === 'light' || v === 'dark' || v === 'auto') return v; } catch (e) {}
return 'auto';
}
function systemDark() {
return !!(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches);
}
function applyMode(mode) {
var dark = mode === 'dark' || (mode === 'auto' && systemDark());
document.documentElement.classList.toggle('kole-dark', dark);
document.documentElement.style.colorScheme = dark ? 'dark' : 'light';
var cur = document.getElementById('m-mode-cur');
if (cur) cur.textContent = MODE_LABEL[mode] || MODE_LABEL.auto;
Array.prototype.forEach.call(document.querySelectorAll('.m-menu-opt'), function (o) {
o.setAttribute('aria-selected', o.getAttribute('data-mode') === mode ? 'true' : 'false');
});
/* 三态图标与 PC 同口径:显式选择时按时态给图标(日间=月亮 / 夜间=太阳),
自动模式下恒为「跟随系统」的显示器图标(此时两个显式图标都不显示)。 */
var moon = document.getElementById('m-icon-moon');
var sun = document.getElementById('m-icon-sun');
var auto = document.getElementById('m-icon-auto');
if (moon) moon.style.display = (mode === 'light') ? '' : 'none';
if (sun) sun.style.display = (mode === 'dark') ? '' : 'none';
if (auto) auto.style.display = (mode === 'auto') ? '' : 'none';
}
function bindModeMenu() {
var trigger = document.getElementById('m-mode-trigger');
var menu = document.getElementById('m-mode-menu');
if (!trigger || !menu) return;
var close = function (refocus) {
menu.classList.add('hidden'); trigger.setAttribute('aria-expanded', 'false');
if (refocus) trigger.focus();
};
trigger.addEventListener('click', function () {
var open = menu.classList.toggle('hidden');
trigger.setAttribute('aria-expanded', open ? 'false' : 'true');
});
trigger.addEventListener('keydown', function (e) {
if (e.key === 'Escape') close(true);
});
Array.prototype.forEach.call(menu.querySelectorAll('.m-menu-opt'), function (opt) {
opt.addEventListener('click', function () {
var mode = opt.getAttribute('data-mode');
try { localStorage.setItem(MODE_KEY, mode); } catch (e) {}
applyMode(mode);
close(true);
});
});
document.addEventListener('click', function (e) {
if (!menu.classList.contains('hidden') && !menu.contains(e.target) && !trigger.contains(e.target)) close(false);
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && !menu.classList.contains('hidden')) close(true);
});
/* 自动模式下跟随系统切换 */
if (window.matchMedia) {
var mq = window.matchMedia('(prefers-color-scheme: dark)');
var onChange = function () { if (readMode() === 'auto') applyMode('auto'); };
if (mq.addEventListener) mq.addEventListener('change', onChange);
else if (mq.addListener) mq.addListener(onChange);
}
applyMode(readMode());
}
bindModeMenu();
/* 版本下拉:与 PC 顶栏同一实现口径 —— 清单从部署根取(<prefix>/versions.json 与
<prefix>/site/versions.json 两份按序尝试,取有可用条目的那份),拿不到就退回不可点的
纯角标(data-single="1"),不留一个点不开的下拉。
清单不许把用户带去外站:path 只允许 ".."(站点根自身)或 x.y.z 快照目录名。 */
var VERSION_KEY_PATH = '..';
function isValidVersionPath(p) {
if (typeof p !== 'string' || !p.length || p.indexOf('\\') >= 0 || p.indexOf('//') >= 0) return false;
if (p === VERSION_KEY_PATH) return true;
return /^\d+\.\d+\.\d+$/.test(p);
}
/* 清单里的 path 相对部署根,".." = /site/、x.y.z = /x.y.z/site/。
当前页可能不在部署根下(快照页),故先还原部署根绝对路径再算回相对当前页。 */
function versionHref(absSite) {
var i = location.pathname.indexOf('/site/');
var prefix = i >= 0 ? location.pathname.slice(0, i) : '';
if (!prefix || absSite.indexOf(prefix + '/') !== 0) return absSite;
var rest = absSite.slice(prefix.length + 1);
var up = '';
var segs = prefix.slice(1).split('/');
for (var k = 0; k < segs.length; k++) up += "../";
return up + rest;
}
function buildVersionList(doc) {
var raw = doc && doc.versions;
if (!raw || !raw.length) return [];
var i = location.pathname.indexOf('/site/');
var prefix = i >= 0 ? location.pathname.slice(0, i) : '';
var list = [];
for (var k = 0; k < raw.length; k++) {
var v = raw[k] || {};
var ver = v.version ? String(v.version) : '';
var path = v.path ? String(v.path) : '';
if (!ver || !isValidVersionPath(path)) continue;
var absSite = (path === VERSION_KEY_PATH ? '' : '/' + path) + '/site/';
list.push({ version: ver, date: v.date ? String(v.date) : '', latest: !!v.latest, href: versionHref(absSite), absSite: absSite, current: false });
}
if (list.length) {
/* 当前版本 = 绝对路径上命中的最长前缀(最具体的那个)——与 PC 的判定一致,
快照页与根站点都能算对。 */
var here = location.pathname;
var best = -1;
for (var j = 0; j < list.length; j++) {
if (here.indexOf(list[j].absSite) === 0 && list[j].absSite.length > best) best = list[j].absSite.length;
}
for (var m = 0; m < list.length; m++) list[m].current = best >= 0 && list[m].absSite.length === best;
if (best < 0 && list[0]) list[0].current = true;
}
return list;
}
function bindVersionMenu() {
var trigger = document.getElementById('m-ver-trigger');
var menu = document.getElementById('m-ver-menu');
var chip = document.getElementById('m-ver');
if (!trigger || !menu) return;
var close = function (refocus) {
menu.classList.add('hidden'); trigger.setAttribute('aria-expanded', 'false');
if (refocus) trigger.focus();
};
var interactive = false;
var render = function (list) {
interactive = !!(list && list.length);
/* 只有清单拿不到才退回纯角标;只要有一版就是下拉(里面至少能看清当前是哪个版本) */
trigger.setAttribute('data-single', interactive ? '0' : '1');
if (!interactive) { menu.classList.add("hidden"); return; }
var cur = null;
for (var k = 0; k < list.length; k++) if (list[k].current) cur = list[k];
if (chip) chip.textContent = 'v' + ((cur && cur.version) || VERSION);
/* 重建选项(幂等:重复调用不会叠加) */
Array.prototype.slice.call(menu.querySelectorAll('.m-ver-opt')).forEach(function (n) { n.remove(); });
list.forEach(function (it) {
var opt = document.createElement('button');
opt.type = 'button'; opt.className = 'm-ver-opt'; opt.setAttribute('role', 'option');
opt.setAttribute('data-version', it.version);
opt.setAttribute('aria-selected', it.current ? 'true' : 'false');
var tag = it.current ? '当前浏览' : (it.latest ? '最新版' : (it.date || ''));
opt.innerHTML = '<span class="m-ver-opt-num">v' + it.version + '</span><span class="m-ver-opt-tag">' + tag + '</span>';
if (it.href) opt.setAttribute('data-href', it.href);
opt.addEventListener("click", function () {
if (!it.current && it.href) location.href = it.href;
else close(true);
});
menu.appendChild(opt);
});
};
trigger.addEventListener('click', function () {
if (!interactive) return;
if (menu.classList.contains('hidden')) { menu.classList.remove('hidden'); trigger.setAttribute('aria-expanded', 'true'); }
else close(false);
});
trigger.addEventListener('keydown', function (e) {
if (!interactive) return;
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); menu.classList.remove('hidden'); trigger.setAttribute('aria-expanded', 'true'); }
else if (e.key === 'Escape') close(true);
});
document.addEventListener('click', function (e) {
if (!menu.classList.contains('hidden') && !menu.contains(e.target) && !trigger.contains(e.target)) close(false);
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && !menu.classList.contains('hidden')) close(true);
});
/* 两份清单按序尝试(不并行:快照页那份必然 404,并行会把 404 记进控制台,
而站点门禁的「零控制台错误」是硬断言)。 */
if (!window.fetch || location.protocol === 'file:') return;
var i = location.pathname.indexOf('/site/');
if (i < 0) return;
var prefix = location.pathname.slice(0, i);
var urls = [prefix + '/versions.json', prefix + '/site/versions.json'];
var attempt = function (idx) {
if (idx >= urls.length) return;
fetch(urls[idx], { cache: 'no-store' })
.then(function (r) { if (!r.ok) throw new Error('HTTP ' + r.status); return r.json(); })
.then(function (doc) { var list = buildVersionList(doc); if (list.length) render(list); else attempt(idx + 1); })
.catch(function () { attempt(idx + 1); });
};
attempt(0);
}
bindVersionMenu();
function done(btn) {
var old = btn.textContent; btn.textContent = '已复制'; btn.classList.add('is-done');
setTimeout(function () { btn.textContent = old; btn.classList.remove('is-done'); }, 1200);
}
document.addEventListener('click', function (e) {
var btn = e.target && e.target.closest ? e.target.closest('.m-copy') : null;
if (!btn) return;
var src = document.getElementById(btn.getAttribute('data-copy') || '');
var text = src ? (src.innerText || src.textContent || '') : '';
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).then(function () { done(btn); }, function () { fallback(btn, text); });
} else { fallback(btn, text); }
});
function fallback(btn, text) {
try {
var ta = document.createElement('textarea'); ta.value = text; ta.setAttribute('readonly', '');
ta.style.position = 'fixed'; ta.style.opacity = '0'; document.body.appendChild(ta);
ta.select(); document.execCommand("copy"); document.body.removeChild(ta); done(btn);
} catch (err) { btn.textContent = '复制失败'; }
}
})();
</script>
</body>
</html>