Files
aurora-admin/site/m/component/swipecell.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

1628 lines
77 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>滑动单元格 SwipeCell — Kole UI Mobile</title>
<meta name="description" content="滑动单元格 SwipeCell:移动端组件(6 端实现:CSS / H5 原生 / React / Vue 2 / Vue 3 / uni-app)。与 PC 端物理隔离:类名 kole-m-、令牌 --kole-m-。规格来源:移动端规格 5 · 滑动单元格 SwipeCell。">
<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 is-active" href="swipecell.html" aria-current="page">滑动单元格<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" href="mobile-message.html">消息通知<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;">SwipeCell</span></h1>
<p>列表行左滑露出操作按钮,用于删除、标记等单行操作</p>
<p style="margin-top: 8px;" class="m-chips">
<span class="m-chip m">反馈</span>
<span class="m-chip">规格 5 · 滑动单元格 SwipeCell</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/swipecell.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/SwipeCell.html?demo=&lt;id&gt;</code>(只显示该演示块),代码是该演示块在演示页里的原文,可复制。全部演示同屏可看 <a href="../../../frameworks-mobile/SwipeCell.html" target="_blank">演示页 ↗</a>。</p>
<h3 class="m-demo-group">01 组件类型</h3>
<div class="m-demo" id="demo-left-single">
<div class="m-demo-head"><span class="m-demo-title">左滑 · 单个操作</span><span class="m-chip">direction=left / actions=1</span></div>
<p class="m-demo-desc">最常用的形态:左滑露出一个操作;位移超过操作区一半即展开。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/SwipeCell.html?demo=left-single" title="滑动单元格 SwipeCell · 左滑 · 单个操作" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 15 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/SwipeCell.html · left-single</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;left-single&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;左滑 · 单个操作(direction=left / actions=1,在行上向左拖动)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;swipecell-left-single&quot;&gt;
&lt;div class=&quot;kole-m-swipecell&quot; id=&quot;sc-left-1&quot; data-state=&quot;closed&quot;
data-behavior=&quot;swipe-sets-class:#sc-left-1|is-open&quot;&gt;
&lt;div class=&quot;kole-m-swipecell__actions&quot;&gt;
&lt;button class=&quot;kole-m-swipecell__action&quot; type=&quot;button&quot; aria-label=&quot;标记为已完成&quot;&gt;完成&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-swipecell__content&quot;&gt;
&lt;span class=&quot;kole-m-swipecell__title&quot;&gt;订单 20260920-001&lt;/span&gt;
&lt;span class=&quot;kole-m-swipecell__desc&quot;&gt;2026-09-20 09:12 · 待处理&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-left-double">
<div class="m-demo-head"><span class="m-demo-title">左滑 · 两个操作</span><span class="m-chip">actions=2</span></div>
<p class="m-demo-desc">两个操作为上限;破坏性操作放最右(拇指行程最短,也最不易误触)。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/SwipeCell.html?demo=left-double" title="滑动单元格 SwipeCell · 左滑 · 两个操作" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 16 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/SwipeCell.html · left-double</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;left-double&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;左滑 · 两个操作(actions=2,data-state 由 closed 变 open)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;swipecell-left-double&quot;&gt;
&lt;div class=&quot;kole-m-swipecell&quot; id=&quot;sc-left-2&quot; data-state=&quot;closed&quot;
data-behavior=&quot;swipe-sets-attr:#sc-left-2|data-state|open&quot;&gt;
&lt;div class=&quot;kole-m-swipecell__actions&quot;&gt;
&lt;button class=&quot;kole-m-swipecell__action&quot; type=&quot;button&quot; aria-label=&quot;标记为已完成&quot;&gt;完成&lt;/button&gt;
&lt;button class=&quot;kole-m-swipecell__action kole-m-swipecell__action--danger&quot; type=&quot;button&quot; aria-label=&quot;删除订单&quot;&gt;删除&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-swipecell__content&quot;&gt;
&lt;span class=&quot;kole-m-swipecell__title&quot;&gt;订单 20260920-002&lt;/span&gt;
&lt;span class=&quot;kole-m-swipecell__desc&quot;&gt;2026-09-20 10:40 · 待处理&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-right-single">
<div class="m-demo-head"><span class="m-demo-title">右滑 · 单个操作</span><span class="m-chip">direction=right</span></div>
<p class="m-demo-desc">右滑露出左侧操作,适合「标记已读」这类非破坏性动作。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/SwipeCell.html?demo=right-single" title="滑动单元格 SwipeCell · 右滑 · 单个操作" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 15 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/SwipeCell.html · right-single</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;right-single&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;右滑 · 单个操作(direction=right,在行上向右拖动)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;swipecell-right-single&quot;&gt;
&lt;div class=&quot;kole-m-swipecell kole-m-swipecell--right&quot; id=&quot;sc-right-1&quot; data-state=&quot;closed&quot;
data-behavior=&quot;swipe-sets-class:#sc-right-1|is-open|right&quot;&gt;
&lt;div class=&quot;kole-m-swipecell__actions&quot;&gt;
&lt;button class=&quot;kole-m-swipecell__action&quot; type=&quot;button&quot; aria-label=&quot;标记为已读&quot;&gt;已读&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-swipecell__content&quot;&gt;
&lt;span class=&quot;kole-m-swipecell__title&quot;&gt;订单 20260920-003&lt;/span&gt;
&lt;span class=&quot;kole-m-swipecell__desc&quot;&gt;2026-09-20 11:05 · 未读&lt;/span&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-open">
<div class="m-demo-head"><span class="m-demo-title">已展开态</span><span class="m-chip">open=true</span></div>
<p class="m-demo-desc">展开后操作按钮可键盘聚焦 —— 滑动不是唯一路径(无障碍要求)。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/SwipeCell.html?demo=open" title="滑动单元格 SwipeCell · 已展开态" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 16 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/SwipeCell.html · open</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;open&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;已展开态(is-open:操作按钮可键盘聚焦,滑动不是唯一路径)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;swipecell-open&quot;&gt;
&lt;div class=&quot;kole-m-swipecell is-open&quot; id=&quot;sc-open&quot; data-state=&quot;open&quot; style=&quot;--kole-m-swipecell-offset: -144px&quot;&gt;
&lt;div class=&quot;kole-m-swipecell__actions&quot;&gt;
&lt;button class=&quot;kole-m-swipecell__action&quot; type=&quot;button&quot; aria-label=&quot;标记为已完成&quot;&gt;完成&lt;/button&gt;
&lt;button class=&quot;kole-m-swipecell__action kole-m-swipecell__action--danger&quot; type=&quot;button&quot; aria-label=&quot;删除订单&quot;&gt;删除&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-swipecell__content&quot;&gt;
&lt;span class=&quot;kole-m-swipecell__title&quot;&gt;订单 20260920-004&lt;/span&gt;
&lt;span class=&quot;kole-m-swipecell__desc&quot;&gt;已滑出操作区,点击内容区先收起&lt;/span&gt;
&lt;/div&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>direction</code></td><td><code>'left' | 'right'</code></td><td><code>'left'</code></td><td>变体 direction:左滑露出右侧操作或右滑露出左侧操作(规格 §5.3)</td><td>N</td></tr>
<tr><td><code>actions</code></td><td><code>Action[]</code></td><td><code>[]</code></td><td>操作项(最多 2 个):{ key, label, tone?, ariaLabel? }(规格 §5.2/§5.3)</td><td>N</td></tr>
<tr><td><code>open</code></td><td><code>boolean</code></td><td><code>false</code></td><td>受控展开态(closed / open,规格 §5.4)</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>action</code></td><td><code>key, action</code></td><td>点击某个操作按钮时触发</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>行内容(标题、描述;规格 §5.2)</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-swipecell-offset</code></td><td><code>0px</code></td><td>组件内部默认值,可在业务侧覆盖</td></tr>
<tr><td><code>--kole-m-swipecell-action-width</code></td><td><code>72px</code></td><td>组件内部默认值,可在业务侧覆盖</td></tr>
</tbody>
</table>
</section>
<section class="m-block">
<h2 id="usage">何时使用</h2>
<ul>
<li>列表行左滑露出操作按钮,用于删除、标记等单行操作</li>
<li>横向位移超过 10px 判定为滑动,纵向位移更大时取消滑动</li>
<li>松手后按位移是否超过操作区宽度的一半决定展开或回弹</li>
<li>展开状态下点击内容区先收起,不触发内容点击</li>
<li>操作按钮为原生 button,具备 aria-label</li>
<li>滑动不可作为唯一路径:操作按钮在展开后必须可键盘聚焦</li>
</ul>
</section>
<section class="m-block">
<h2 id="interaction">交互与触控</h2>
<ul>
<li>横向位移超过 10px 判定为滑动,纵向位移更大时取消滑动</li>
<li>松手后按位移是否超过操作区宽度的一半决定展开或回弹</li>
<li>展开状态下点击内容区先收起,不触发内容点击</li>
</ul>
</section>
<section class="m-block">
<h2 id="a11y">无障碍</h2>
<ul>
<li>操作按钮为原生 button,具备 aria-label</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="actionsheet.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;">ActionSheet</em></td><td>需要标题与统一取消的批量选择用动作面板;行内单点操作用滑动单元格</td></tr>
<tr><td><a href="tabbar.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;">TabBar</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>操作区宽度是否有标准档位</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>cell</code></td><td>可滑动的行容器</td></tr>
<tr><td><code>content</code></td><td>行内容(标题、描述)</td></tr>
<tr><td><code>actions</code></td><td>右侧操作区,随滑动露出</td></tr>
<tr><td><code>action</code></td><td>单个操作按钮,可标记危险</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>direction</code></td><td>left / right</td><td><div><b>left</b> <span class="m-none">(由数据驱动,无专属类)</span></div><div><b>right</b> <span class="m-cls">.kole-m-swipecell--right</span></div></td></tr>
<tr><td><code>actions</code></td><td>1 / 2</td><td><div><b>1</b> <span class="m-cls">.kole-m-swipecell__action</span></div><div><b>2</b> <span class="m-cls">.kole-m-swipecell__action</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>direction=left · actions=1</code></td><td>左滑 · 单个操作</td></tr>
<tr><td><code>direction=left · actions=2</code></td><td>左滑 · 两个操作</td></tr>
<tr><td><code>direction=right · actions=1</code></td><td>右滑 · 单个操作</td></tr>
<tr><td><code>direction=left · actions=2</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-duration-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 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="表头背景">--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="反色文字(品牌色背景上的白字)">--kole-color-text-inverse</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="标题文字 · 15.4:1">--kole-color-text-title</span>
<span class="m-chip inherit" title="">--kole-font-family</span>
<span class="m-chip inherit" title="">--kole-space-12</span>
<span class="m-chip inherit" title="">--kole-space-4</span>
<span class="m-chip" title="组件级变量(可在业务侧覆盖)">--kole-ease-slide</span>
<span class="m-chip" title="组件级变量(可在业务侧覆盖)">--kole-m-swipecell-action-width</span>
<span class="m-chip" title="组件级变量(可在业务侧覆盖)">--kole-m-swipecell-offset</span>
</div>
</section>
<section class="m-block">
<h2 id="sources">6 端源码</h2>
<p class="m-sub">同一组件的六份实现(生产环境的类名与结构一致,差异只在技术栈写法与单位)。点开查看,右侧可复制。</p>
<details class="m-details">
<summary>frameworks-mobile/SwipeCell.css · 纯样式(CSS) · 84 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/SwipeCell.css</span><button class="m-copy" type="button" data-copy="code-25">复制</button></div>
<pre id="code-25"><code>/* Kole UI Mobile · SwipeCell 样式 — 对齐移动端规格 §5
滑动单元格:左滑露出右侧操作;横向位移 &gt; 10px 判定为滑动,纵向更大时取消;
松手按是否超过操作区宽度一半决定展开或回弹。 */
.kole-m-swipecell {
/* 操作区宽度:规格 §5.8 明确「是否有标准档位」未知,这里是实现默认值,可被业务覆盖 */
--kole-m-swipecell-offset: 0px;
--kole-m-swipecell-action-width: 72px;
position: relative;
overflow: hidden;
background: var(--kole-color-card-bg);
font-family: var(--kole-font-family);
}
.kole-m-swipecell__actions {
position: absolute;
inset-block: 0;
inset-inline-end: 0;
display: flex;
}
/* 变体 direction=right:操作区在左侧,内容向右滑出 */
.kole-m-swipecell--right .kole-m-swipecell__actions {
inset-inline-end: auto;
inset-inline-start: 0;
}
.kole-m-swipecell__action {
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
width: var(--kole-m-swipecell-action-width);
border: 0;
background: var(--kole-color-table-header-bg);
color: var(--kole-color-text-body);
font-family: inherit;
font-size: var(--kole-m-font-size-label);
cursor: pointer;
touch-action: manipulation;
}
.kole-m-swipecell__action:focus-visible {
outline: 2px solid var(--kole-color-focus-ring);
outline-offset: -2px;
}
.kole-m-swipecell__action:active { filter: brightness(.94); }
.kole-m-swipecell__action--danger {
background: var(--kole-color-error);
color: var(--kole-color-text-inverse);
}
.kole-m-swipecell__content {
position: relative;
z-index: 1;
display: block;
padding: var(--kole-space-12) var(--kole-m-gutter);
background: var(--kole-color-card-bg);
text-align: start;
transform: translateX(var(--kole-m-swipecell-offset));
transition: transform var(--kole-m-duration-slide) var(--kole-ease-slide);
touch-action: pan-y;
}
/* 拖拽中不跟手会有延迟感:取消过渡 */
.kole-m-swipecell.is-dragging .kole-m-swipecell__content { transition: none; }
.kole-m-swipecell__title {
display: block;
font-size: var(--kole-m-font-size-body);
color: var(--kole-color-text-title);
line-height: 1.4;
}
.kole-m-swipecell__desc {
display: block;
margin-top: var(--kole-space-4);
font-size: var(--kole-m-font-size-label);
color: var(--kole-color-text-secondary);
line-height: 1.4;
}
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/SwipeCell.html · H5 原生(无框架) · 168 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/SwipeCell.html</span><button class="m-copy" type="button" data-copy="code-26">复制</button></div>
<pre id="code-26"><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 · SwipeCell(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;SwipeCell.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); }
.demo-frame { position: relative; max-width: 375px; margin: 0 auto; overflow: hidden;
background: var(--kole-color-card-bg); border-block: 1px solid var(--kole-color-border); }
&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;left-single&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;左滑 · 单个操作(direction=left / actions=1,在行上向左拖动)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;swipecell-left-single&quot;&gt;
&lt;div class=&quot;kole-m-swipecell&quot; id=&quot;sc-left-1&quot; data-state=&quot;closed&quot;
data-behavior=&quot;swipe-sets-class:#sc-left-1|is-open&quot;&gt;
&lt;div class=&quot;kole-m-swipecell__actions&quot;&gt;
&lt;button class=&quot;kole-m-swipecell__action&quot; type=&quot;button&quot; aria-label=&quot;标记为已完成&quot;&gt;完成&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-swipecell__content&quot;&gt;
&lt;span class=&quot;kole-m-swipecell__title&quot;&gt;订单 20260920-001&lt;/span&gt;
&lt;span class=&quot;kole-m-swipecell__desc&quot;&gt;2026-09-20 09:12 · 待处理&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;left-double&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;左滑 · 两个操作(actions=2,data-state 由 closed 变 open)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;swipecell-left-double&quot;&gt;
&lt;div class=&quot;kole-m-swipecell&quot; id=&quot;sc-left-2&quot; data-state=&quot;closed&quot;
data-behavior=&quot;swipe-sets-attr:#sc-left-2|data-state|open&quot;&gt;
&lt;div class=&quot;kole-m-swipecell__actions&quot;&gt;
&lt;button class=&quot;kole-m-swipecell__action&quot; type=&quot;button&quot; aria-label=&quot;标记为已完成&quot;&gt;完成&lt;/button&gt;
&lt;button class=&quot;kole-m-swipecell__action kole-m-swipecell__action--danger&quot; type=&quot;button&quot; aria-label=&quot;删除订单&quot;&gt;删除&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-swipecell__content&quot;&gt;
&lt;span class=&quot;kole-m-swipecell__title&quot;&gt;订单 20260920-002&lt;/span&gt;
&lt;span class=&quot;kole-m-swipecell__desc&quot;&gt;2026-09-20 10:40 · 待处理&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;right-single&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;右滑 · 单个操作(direction=right,在行上向右拖动)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;swipecell-right-single&quot;&gt;
&lt;div class=&quot;kole-m-swipecell kole-m-swipecell--right&quot; id=&quot;sc-right-1&quot; data-state=&quot;closed&quot;
data-behavior=&quot;swipe-sets-class:#sc-right-1|is-open|right&quot;&gt;
&lt;div class=&quot;kole-m-swipecell__actions&quot;&gt;
&lt;button class=&quot;kole-m-swipecell__action&quot; type=&quot;button&quot; aria-label=&quot;标记为已读&quot;&gt;已读&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-swipecell__content&quot;&gt;
&lt;span class=&quot;kole-m-swipecell__title&quot;&gt;订单 20260920-003&lt;/span&gt;
&lt;span class=&quot;kole-m-swipecell__desc&quot;&gt;2026-09-20 11:05 · 未读&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;open&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;已展开态(is-open:操作按钮可键盘聚焦,滑动不是唯一路径)&lt;/p&gt;
&lt;div class=&quot;demo-frame&quot; data-assert=&quot;swipecell-open&quot;&gt;
&lt;div class=&quot;kole-m-swipecell is-open&quot; id=&quot;sc-open&quot; data-state=&quot;open&quot; style=&quot;--kole-m-swipecell-offset: -144px&quot;&gt;
&lt;div class=&quot;kole-m-swipecell__actions&quot;&gt;
&lt;button class=&quot;kole-m-swipecell__action&quot; type=&quot;button&quot; aria-label=&quot;标记为已完成&quot;&gt;完成&lt;/button&gt;
&lt;button class=&quot;kole-m-swipecell__action kole-m-swipecell__action--danger&quot; type=&quot;button&quot; aria-label=&quot;删除订单&quot;&gt;删除&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-swipecell__content&quot;&gt;
&lt;span class=&quot;kole-m-swipecell__title&quot;&gt;订单 20260920-004&lt;/span&gt;
&lt;span class=&quot;kole-m-swipecell__desc&quot;&gt;已滑出操作区,点击内容区先收起&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;script&gt;
/* 手势:纵向位移更大时取消滑动(让位给页面滚动);横向位移 &gt; 10px 才算滑动。
松手按是否超过操作区宽度一半决定展开/回弹;is-open 与 data-state 同一函数写入。 */
(function () {
var THRESHOLD = 10;
function apply(cell, open) {
var right = cell.classList.contains('kole-m-swipecell--right');
var width = cell.querySelector('.kole-m-swipecell__actions').offsetWidth || 72;
var offset = open ? (right ? width : -width) : 0;
cell.style.setProperty('--kole-m-swipecell-offset', offset + 'px');
cell.classList.toggle('is-open', open);
cell.setAttribute('data-state', open ? 'open' : 'closed');
}
document.querySelectorAll('.kole-m-swipecell').forEach(function (cell) {
var startX = 0, startY = 0, dx = 0, dragging = false, decided = false, width = 72;
cell.addEventListener('pointerdown', function (e) {
startX = e.clientX;
startY = e.clientY;
dx = 0;
decided = false;
width = cell.querySelector('.kole-m-swipecell__actions').offsetWidth || 72;
});
cell.addEventListener('pointermove', function (e) {
dx = e.clientX - startX;
var dy = e.clientY - startY;
if (!decided) {
if (Math.abs(dx) &lt; THRESHOLD &amp;&amp; Math.abs(dy) &lt; THRESHOLD) return;
decided = true;
if (Math.abs(dy) &gt; Math.abs(dx)) return; /* 纵向为主:交给页面滚动 */
dragging = true;
cell.classList.add('is-dragging');
}
if (!dragging) return;
var clamped = Math.max(-width, Math.min(width, dx));
cell.style.setProperty('--kole-m-swipecell-offset', clamped + 'px');
});
function end() {
if (dragging) {
dragging = false;
cell.classList.remove('is-dragging');
apply(cell, Math.abs(dx) &gt; width / 2);
} else if (cell.classList.contains('is-open')) {
apply(cell, false); /* 展开态点击内容区先收起 */
}
decided = false;
}
cell.addEventListener('pointerup', end);
cell.addEventListener('pointercancel', end);
});
})();
&lt;/script&gt;
&lt;script&gt;
/* ?demo=&lt;id&gt; → 只显示该演示块:文档站为每个演示单独起一个 375×640 预览帧。
无参数时全部显示 —— 测试页与回归走无参数路径,行为不变。 */
(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');
/* 单块模式去掉 min-height:100vh —— 否则内容高度随帧高变化(帧高→vh→内容高)形成反馈环,
自适应量到的永远是视口高度而不是内容高度。 */
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/SwipeCell.jsx · React · 110 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/SwipeCell.jsx</span><button class="m-copy" type="button" data-copy="code-27">复制</button></div>
<pre id="code-27"><code>import React, { useRef, useState } from 'react';
import './SwipeCell.css';
/* 与 CSS 的 --kole-m-swipecell-action-width 默认值保持一致:
展开位移 = 操作区宽度 × 操作数量(规格 §5.8 明确该宽度无标准档位,这里是实现默认值) */
const ACTION_WIDTH = 72;
/* 滑动单元格(移动端)— 规格 §5;横向位移 &gt; 10px 判定为滑动,
纵向位移更大时取消滑动(让位给页面滚动);松手按是否超过操作区宽度一半决定展开/回弹。 */
export default function SwipeCell({
direction = 'left',
actions = [],
open = false,
onAction,
children,
}) {
const [offset, setOffset] = useState(0);
const [dragging, setDragging] = useState(false);
const gestures = useRef({ startX: 0, startY: 0, dx: 0, width: ACTION_WIDTH, decided: false, dragging: false });
const rootRef = useRef(null);
/** 展开态位移:右侧操作向左滑(负),左侧操作向右滑(正) */
const openOffset = (direction === 'right' ? 1 : -1) * ACTION_WIDTH * Math.max(1, actions.length);
function measure() {
const el = rootRef.current &amp;&amp; rootRef.current.querySelector('.kole-m-swipecell__actions');
return (el &amp;&amp; el.offsetWidth) || ACTION_WIDTH;
}
function settle(isOpen) {
const w = measure();
setOffset(isOpen ? (direction === 'right' ? w : -w) : 0);
}
function onPointerDown(e) {
const g = gestures.current;
g.startX = e.clientX;
g.startY = e.clientY;
g.dx = 0;
g.decided = false;
g.dragging = false;
g.width = measure();
}
function onPointerMove(e) {
const g = gestures.current;
g.dx = e.clientX - g.startX;
const dy = e.clientY - g.startY;
if (!g.decided) {
if (Math.abs(g.dx) &lt; 10 &amp;&amp; Math.abs(dy) &lt; 10) return;
g.decided = true;
if (Math.abs(dy) &gt; Math.abs(g.dx)) return;
g.dragging = true;
setDragging(true);
}
if (!g.dragging) return;
setOffset(Math.max(-g.width, Math.min(g.width, g.dx)));
}
function onPointerEnd() {
const g = gestures.current;
if (g.dragging) {
g.dragging = false;
setDragging(false);
settle(Math.abs(g.dx) &gt; g.width / 2);
} else if (open) {
settle(false);
}
g.decided = false;
}
const appliedOffset = dragging || offset !== 0 ? offset : open ? openOffset : 0;
return (
&lt;div
ref={rootRef}
className={
'kole-m-swipecell' +
(direction === 'right' ? ' kole-m-swipecell--right' : '') +
(dragging ? ' is-dragging' : '') +
(open ? ' is-open' : '')
}
style={{ '--kole-m-swipecell-offset': appliedOffset + 'px' }}
data-state={open ? 'open' : 'closed'}
onPointerDown={onPointerDown}
onPointerMove={onPointerMove}
onPointerUp={onPointerEnd}
onPointerCancel={onPointerEnd}
&gt;
&lt;div className=&quot;kole-m-swipecell__actions&quot;&gt;
{actions.map((a, i) =&gt; (
&lt;button
key={a.key || i}
className={
'kole-m-swipecell__action' +
(a.tone === 'danger' ? ' kole-m-swipecell__action--danger' : '')
}
type=&quot;button&quot;
aria-label={a.ariaLabel || a.label}
onClick={() =&gt; onAction &amp;&amp; onAction(a.key, a)}
&gt;
{a.label}
&lt;/button&gt;
))}
&lt;/div&gt;
&lt;div className=&quot;kole-m-swipecell__content&quot;&gt;{children}&lt;/div&gt;
&lt;/div&gt;
);
}
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/SwipeCell.vue2.vue · Vue 2 · 105 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/SwipeCell.vue2.vue</span><button class="m-copy" type="button" data-copy="code-28">复制</button></div>
<pre id="code-28"><code>&lt;template&gt;
&lt;div
ref=&quot;root&quot;
class=&quot;kole-m-swipecell&quot;
:class=&quot;[{ 'kole-m-swipecell--right': direction === 'right' }, { 'is-dragging': dragging }, { 'is-open': open }]&quot;
:style=&quot;{ '--kole-m-swipecell-offset': appliedOffset + 'px' }&quot;
:data-state=&quot;open ? 'open' : 'closed'&quot;
@pointerdown=&quot;onDown&quot;
@pointermove=&quot;onMove&quot;
@pointerup=&quot;onEnd&quot;
@pointercancel=&quot;onEnd&quot;
&gt;
&lt;div class=&quot;kole-m-swipecell__actions&quot;&gt;
&lt;button
v-for=&quot;(a, i) in actions&quot;
:key=&quot;a.key || i&quot;
class=&quot;kole-m-swipecell__action&quot;
:class=&quot;{ 'kole-m-swipecell__action--danger': a.tone === 'danger' }&quot;
type=&quot;button&quot;
:aria-label=&quot;a.ariaLabel || a.label&quot;
@click=&quot;$emit('action', a.key, a)&quot;
&gt;
{{ a.label }}
&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-swipecell__content&quot;&gt;
&lt;slot&gt;&lt;/slot&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/template&gt;
&lt;script&gt;
/* 与 CSS 默认 --kole-m-swipecell-action-width 一致(规格 §5.8:该宽度无标准档位) */
var ACTION_WIDTH = 72;
export default {
name: 'KoleMSwipeCell',
props: {
direction: { type: String, default: 'left' },
actions: { type: Array, default: function () { return []; } },
open: { type: Boolean, default: false }
},
data: function () {
return {
offset: 0,
dragging: false,
g: { startX: 0, startY: 0, dx: 0, width: ACTION_WIDTH, decided: false, dragging: false }
};
},
computed: {
openOffset: function () {
var sign = this.direction === 'right' ? 1 : -1;
return sign * ACTION_WIDTH * Math.max(1, this.actions.length);
},
appliedOffset: function () {
if (this.dragging || this.offset !== 0) return this.offset;
return this.open ? this.openOffset : 0;
}
},
methods: {
measure: function () {
var el = this.$refs.root &amp;&amp; this.$refs.root.querySelector('.kole-m-swipecell__actions');
return (el &amp;&amp; el.offsetWidth) || ACTION_WIDTH;
},
settle: function (isOpen) {
var w = this.measure();
this.offset = isOpen ? (this.direction === 'right' ? w : -w) : 0;
},
onDown: function (e) {
this.g.startX = e.clientX;
this.g.startY = e.clientY;
this.g.dx = 0;
this.g.decided = false;
this.g.dragging = false;
this.g.width = this.measure();
},
onMove: function (e) {
this.g.dx = e.clientX - this.g.startX;
var dy = e.clientY - this.g.startY;
if (!this.g.decided) {
if (Math.abs(this.g.dx) &lt; 10 &amp;&amp; Math.abs(dy) &lt; 10) return;
this.g.decided = true;
if (Math.abs(dy) &gt; Math.abs(this.g.dx)) return;
this.g.dragging = true;
this.dragging = true;
}
if (!this.g.dragging) return;
this.offset = Math.max(-this.g.width, Math.min(this.g.width, this.g.dx));
},
onEnd: function () {
if (this.g.dragging) {
this.g.dragging = false;
this.dragging = false;
this.settle(Math.abs(this.g.dx) &gt; this.g.width / 2);
} else if (this.open) {
this.settle(false);
}
this.g.decided = false;
}
}
};
&lt;/script&gt;
&lt;style src=&quot;./SwipeCell.css&quot;&gt;&lt;/style&gt;
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/SwipeCell.vue3.vue · Vue 3 · 95 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/SwipeCell.vue3.vue</span><button class="m-copy" type="button" data-copy="code-29">复制</button></div>
<pre id="code-29"><code>&lt;template&gt;
&lt;div
ref=&quot;root&quot;
class=&quot;kole-m-swipecell&quot;
:class=&quot;[{ 'kole-m-swipecell--right': direction === 'right' }, { 'is-dragging': dragging }, { 'is-open': open }]&quot;
:style=&quot;{ '--kole-m-swipecell-offset': appliedOffset + 'px' }&quot;
:data-state=&quot;open ? 'open' : 'closed'&quot;
@pointerdown=&quot;onDown&quot;
@pointermove=&quot;onMove&quot;
@pointerup=&quot;onEnd&quot;
@pointercancel=&quot;onEnd&quot;
&gt;
&lt;div class=&quot;kole-m-swipecell__actions&quot;&gt;
&lt;button
v-for=&quot;(a, i) in actions&quot;
:key=&quot;a.key || i&quot;
class=&quot;kole-m-swipecell__action&quot;
:class=&quot;{ 'kole-m-swipecell__action--danger': a.tone === 'danger' }&quot;
type=&quot;button&quot;
:aria-label=&quot;a.ariaLabel || a.label&quot;
@click=&quot;emit('action', a.key, a)&quot;
&gt;
{{ a.label }}
&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-swipecell__content&quot;&gt;
&lt;slot&gt;&lt;/slot&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/template&gt;
&lt;script setup&gt;
import { computed, ref } from 'vue';
/* 与 CSS 默认 --kole-m-swipecell-action-width 一致(规格 §5.8:该宽度无标准档位) */
const ACTION_WIDTH = 72;
const props = defineProps({
direction: { type: String, default: 'left' },
actions: { type: Array, default: () =&gt; [] },
open: { type: Boolean, default: false }
});
const emit = defineEmits(['action']);
const root = ref(null);
const offset = ref(0);
const dragging = ref(false);
const g = { startX: 0, startY: 0, dx: 0, width: ACTION_WIDTH, decided: false, dragging: false };
const openOffset = computed(() =&gt; (props.direction === 'right' ? 1 : -1) * ACTION_WIDTH * Math.max(1, props.actions.length));
const appliedOffset = computed(() =&gt; (dragging.value || offset.value !== 0 ? offset.value : props.open ? openOffset.value : 0));
function measure() {
const el = root.value &amp;&amp; root.value.querySelector('.kole-m-swipecell__actions');
return (el &amp;&amp; el.offsetWidth) || ACTION_WIDTH;
}
function settle(isOpen) {
const w = measure();
offset.value = isOpen ? (props.direction === 'right' ? w : -w) : 0;
}
function onDown(e) {
g.startX = e.clientX;
g.startY = e.clientY;
g.dx = 0;
g.decided = false;
g.dragging = false;
g.width = measure();
}
function onMove(e) {
g.dx = e.clientX - g.startX;
const dy = e.clientY - g.startY;
if (!g.decided) {
if (Math.abs(g.dx) &lt; 10 &amp;&amp; Math.abs(dy) &lt; 10) return;
g.decided = true;
if (Math.abs(dy) &gt; Math.abs(g.dx)) return;
g.dragging = true;
dragging.value = true;
}
if (!g.dragging) return;
offset.value = Math.max(-g.width, Math.min(g.width, g.dx));
}
function onEnd() {
if (g.dragging) {
g.dragging = false;
dragging.value = false;
settle(Math.abs(g.dx) &gt; g.width / 2);
} else if (props.open) {
settle(false);
}
g.decided = false;
}
&lt;/script&gt;
&lt;style src=&quot;./SwipeCell.css&quot;&gt;&lt;/style&gt;
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/SwipeCell.uniapp.vue · uni-app(跨端:小程序 / App / H5) · 157 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/SwipeCell.uniapp.vue</span><button class="m-copy" type="button" data-copy="code-30">复制</button></div>
<pre id="code-30"><code>&lt;template&gt;
&lt;view
class=&quot;kole-m-swipecell&quot;
:class=&quot;[direction === 'right' ? 'kole-m-swipecell--right' : '', dragging ? 'is-dragging' : '', open ? 'is-open' : '']&quot;
:style=&quot;'--kole-m-swipecell-offset:' + appliedOffset + 'rpx'&quot;
:data-state=&quot;open ? 'open' : 'closed'&quot;
@touchstart=&quot;onStart&quot;
@touchmove=&quot;onMove&quot;
@touchend=&quot;onEnd&quot;
@touchcancel=&quot;onEnd&quot;
&gt;
&lt;view class=&quot;kole-m-swipecell__actions&quot;&gt;
&lt;view
v-for=&quot;(a, i) in actions&quot;
:key=&quot;a.key || i&quot;
class=&quot;kole-m-swipecell__action&quot;
:class=&quot;a.tone === 'danger' ? 'kole-m-swipecell__action--danger' : ''&quot;
role=&quot;button&quot;
:aria-label=&quot;a.ariaLabel || a.label&quot;
@tap=&quot;emit('action', a.key, a)&quot;
&gt;
&lt;text&gt;{{ a.label }}&lt;/text&gt;
&lt;/view&gt;
&lt;/view&gt;
&lt;view class=&quot;kole-m-swipecell__content&quot; role=&quot;button&quot; @tap=&quot;onContentTap&quot;&gt;
&lt;slot&gt;&lt;/slot&gt;
&lt;/view&gt;
&lt;/view&gt;
&lt;/template&gt;
&lt;script setup&gt;
/* uni-app 端 · 滑动单元格(移动端)— 规格 §5
跨端差异:手势用 @touchstart/@touchmove/@touchend(小程序与 App 端无 PointerEvent);
位移以 px 判定(阈值 10px),展开位移换算为 rpx(2rpx = 1px @375pt)。
规格 §5.4「多行同时展开的互斥规则」未定,故本组件只管自身开合。 */
import { computed, ref } from 'vue';
const ACTION_WIDTH_RPX = 144; /* 72px × 2 */
const OPEN_THRESHOLD_PX = 10;
const props = defineProps({
direction: { type: String, default: 'left' },
actions: { type: Array, default: () =&gt; [] },
open: { type: Boolean, default: false }
});
const emit = defineEmits(['action']);
const offset = ref(0); /* 单位 rpx */
const dragging = ref(false);
const startX = ref(0);
const startY = ref(0);
const dx = ref(0);
const decided = ref(false);
const isDragging = ref(false);
const openOffset = computed(() =&gt; {
var sign = props.direction === 'right' ? 1 : -1;
return sign * ACTION_WIDTH_RPX * Math.max(1, props.actions.length);
});
const appliedOffset = computed(() =&gt; (isDragging.value || offset.value !== 0 ? offset.value : props.open ? openOffset.value : 0));
function touch(e) {
var t = (e.touches &amp;&amp; e.touches[0]) || (e.changedTouches &amp;&amp; e.changedTouches[0]) || {};
return { x: t.clientX != null ? t.clientX : t.pageX, y: t.clientY != null ? t.clientY : t.pageY };
}
function onStart(e) {
var p = touch(e);
startX.value = p.x;
startY.value = p.y;
dx.value = 0;
decided.value = false;
isDragging.value = false;
}
function onMove(e) {
var p = touch(e);
dx.value = p.x - startX.value;
var dy = p.y - startY.value;
if (!decided.value) {
if (Math.abs(dx.value) &lt; OPEN_THRESHOLD_PX &amp;&amp; Math.abs(dy) &lt; OPEN_THRESHOLD_PX) return;
decided.value = true;
if (Math.abs(dy) &gt; Math.abs(dx.value)) return; /* 纵向为主:让位给页面滚动 */
isDragging.value = true;
dragging.value = true;
}
if (!isDragging.value) return;
var limit = ACTION_WIDTH_RPX * Math.max(1, props.actions.length);
offset.value = Math.max(-limit, Math.min(limit, dx.value * 2));
}
function onEnd() {
if (isDragging.value) {
isDragging.value = false;
dragging.value = false;
var limit = ACTION_WIDTH_RPX * Math.max(1, props.actions.length);
var isOpen = Math.abs(offset.value) &gt; limit / 2;
offset.value = isOpen ? (props.direction === 'right' ? limit : -limit) : 0;
}
decided.value = false;
}
function onContentTap() {
/* 规格 §5.5:展开状态下点击内容区先收起,不触发内容点击 */
if (props.open || offset.value !== 0) offset.value = 0;
}
&lt;/script&gt;
&lt;style&gt;
.kole-m-swipecell {
--kole-m-swipecell-offset: 0rpx;
--kole-m-touch-target: 88rpx;
--kole-m-font-size-body: 32rpx;
--kole-m-font-size-label: 28rpx;
--kole-m-gutter: 32rpx;
position: relative;
overflow: hidden;
background-color: var(--kole-color-card-bg);
}
.kole-m-swipecell__actions {
position: absolute;
top: 0;
bottom: 0;
right: 0;
display: flex;
}
.kole-m-swipecell--right .kole-m-swipecell__actions {
right: auto;
left: 0;
}
.kole-m-swipecell__action {
display: flex;
align-items: center;
justify-content: center;
width: 144rpx;
background-color: var(--kole-color-table-header-bg);
color: var(--kole-color-text-body);
font-size: var(--kole-m-font-size-label);
}
.kole-m-swipecell__action--danger {
background-color: var(--kole-color-error);
color: var(--kole-color-text-inverse);
}
.kole-m-swipecell__content {
position: relative;
z-index: 1;
display: block;
padding: 24rpx var(--kole-m-gutter);
background-color: var(--kole-color-card-bg);
transform: translateX(var(--kole-m-swipecell-offset));
transition: transform 240ms cubic-bezier(.32, .72, 0, 1);
}
.kole-m-swipecell.is-dragging .kole-m-swipecell__content { transition: none; }
&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">断言 17 条 · 全部通过</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/swipecell.json(点击展开原始 JSON)</summary>
<div class="m-code"><pre><code>{
"schemaVersion": 1,
"sourceKind": "authored-spec",
"provenance": "authored-in-repo",
"specFile": "spec/移动端规格.md",
"specSection": "5 · 滑动单元格 SwipeCell",
"confidence": "high",
"slug": "swipecell",
"name": "滑动单元格 SwipeCell",
"semanticTypeCandidates": [
"swipe-cell",
"list-item",
"gesture"
],
"variantDimensions": [
{
"name": "direction",
"values": [
"left",
"right"
]
},
{
"name": "actions",
"values": [
"1",
"2"
]
}
],
"representativeVariants": [
{
"direction": "left",
"actions": "1",
"label": "左滑 · 单个操作"
},
{
"direction": "left",
"actions": "2",
"label": "左滑 · 两个操作"
},
{
"direction": "right",
"actions": "1",
"label": "右滑 · 单个操作"
},
{
"direction": "left",
"actions": "2",
"label": "已展开态"
}
],
"anatomy": {
"cell": "可滑动的行容器",
"content": "行内容(标题、描述)",
"actions": "右侧操作区,随滑动露出",
"action": "单个操作按钮,可标记危险"
},
"structurePatterns": {
"direction": "left(左滑露出右侧操作,默认)/ right(右滑露出左侧操作)",
"actions": "1 / 2(操作数量,最多 2 个)"
},
"usageHints": [
"列表行左滑露出操作按钮,用于删除、标记等单行操作",
"横向位移超过 10px 判定为滑动,纵向位移更大时取消滑动",
"松手后按位移是否超过操作区宽度的一半决定展开或回弹",
"展开状态下点击内容区先收起,不触发内容点击",
"操作按钮为原生 button,具备 aria-label",
"滑动不可作为唯一路径:操作按钮在展开后必须可键盘聚焦"
],
"doNotInvent": [
"多行同时展开的互斥规则",
"滑动与纵向滚动的竞争阈值细节"
],
"unknowns": [
"操作区宽度是否有标准档位",
"拖拽中的阴影表现"
],
"interaction": [
"横向位移超过 10px 判定为滑动,纵向位移更大时取消滑动",
"松手后按位移是否超过操作区宽度的一半决定展开或回弹",
"展开状态下点击内容区先收起,不触发内容点击"
],
"accessibility": [
"操作按钮为原生 button,具备 aria-label",
"滑动不可作为唯一路径:操作按钮在展开后必须可键盘聚焦"
],
"api": {
"source": "implementation",
"note": "props / events / slots 为 6 端实现的公共接口(说明文字取自规格对应小节)。字段名与各端源码逐名核对:node tools/verify-mobile-docs.mjs",
"props": [
{
"name": "direction",
"type": "'left' | 'right'",
"default": "'left'",
"desc": "变体 direction:左滑露出右侧操作或右滑露出左侧操作(规格 §5.3)",
"required": false
},
{
"name": "actions",
"type": "Action[]",
"default": "[]",
"desc": "操作项(最多 2 个):{ key, label, tone?, ariaLabel? }(规格 §5.2/§5.3)",
"required": false
},
{
"name": "open",
"type": "boolean",
"default": "false",
"desc": "受控展开态(closed / open,规格 §5.4)",
"required": false
}
],
"events": [
{
"name": "action",
"params": "key, action",
"desc": "点击某个操作按钮时触发"
}
],
"slots": [
{
"name": "default",
"desc": "行内容(标题、描述;规格 §5.2)"
}
],
"requiredNote": "「必传」按严格定义:实现里**没有默认值**时才为 Y(本门禁逐条核对 props 与各端源码的默认值,防止契约与实现脱节)。"
},
"variantClasses": {
"direction": {
"left": [],
"right": [
".kole-m-swipecell--right"
]
},
"actions": {
"1": [
".kole-m-swipecell__action"
],
"2": [
".kole-m-swipecell__action"
]
}
},
"demos": [
{
"id": "left-single",
"group": "01 组件类型",
"title": "左滑 · 单个操作",
"desc": "最常用的形态:左滑露出一个操作;位移超过操作区一半即展开。",
"variant": "direction=left / actions=1"
},
{
"id": "left-double",
"group": "01 组件类型",
"title": "左滑 · 两个操作",
"desc": "两个操作为上限;破坏性操作放最右(拇指行程最短,也最不易误触)。",
"variant": "actions=2"
},
{
"id": "right-single",
"group": "01 组件类型",
"title": "右滑 · 单个操作",
"desc": "右滑露出左侧操作,适合「标记已读」这类非破坏性动作。",
"variant": "direction=right"
},
{
"id": "open",
"group": "02 组件状态",
"title": "已展开态",
"desc": "展开后操作按钮可键盘聚焦 —— 滑动不是唯一路径(无障碍要求)。",
"variant": "open=true"
}
],
"related": [
{
"slug": "actionsheet",
"why": "需要标题与统一取消的批量选择用动作面板;行内单点操作用滑动单元格"
},
{
"slug": "tabbar",
"why": "长列表底部常带标签栏,滑动时要保证列表可滚、标签栏不动"
}
]
}</code></pre></div>
</details>
</section>
<footer class="m-foot">
<p>生成物:本页由 <code>node tools/build-mobile.mjs</code> 从契约 <code>components/swipecell.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>