Files
aurora-admin b59247231a
Regression / regression (push) Canceled after 0s
feat(安全+品牌): 对外产物发布脱敏(3注入点/2465文件0泄露) + Kole Cup 定稿
安全:CHANGELOG.md 是仓库内部变更流水(含服务器目录、镜像回滚标签、内网网段、
部署时序、AI 工作流用语),此前被 build-site.ps1 / precompute.mjs / build-mobile.mjs
原样注入站点,而站点是公网可下载的静态文件 —— 抓一次 /site/m/changelog.html
即可拿到内网地址段与服务器目录布局。

- 新增 tools/lib/redact-publish.mjs(零依赖,构建期过滤,不改 CHANGELOG.md,
  内部可追溯性完整保留)
- 接入 precompute.mjs(PC data.json/changelog.json)与 build-mobile.mjs
  (移动端更新日志页);build-site.ps1 不碰(ASCII-only 铁律)
- 只处理 changelog 字段:components[].sources 是规范实现源码,逐字保真
  (详情页代码区主动高亮注释,剥注释会破坏该功能)
- 实测消除:/opt/aurora-admin.prev-*、kole-ui-showcase:pre-*、docker compose、
  192.168.5.7、16 位产物指纹、1531/1531、并发会话/本会话/派子 agent
- settings.html 演示占位 IP 192.168.5.0/24(= 真实网段)改为 RFC 5737 的 192.0.2.0/24

品牌:Kole Cup 饮料杯标记定稿(几何 K → 圆角杯盖 + 杯身负空间 K,无吸管),
brand-mark.json 升 schemaVersion 3(paths 支持 { d, evenodd }),
verify:brand 增至 25 条(新增 B9b:负空间必须带 fill-rule)。

验证:发布集 2465 文件全量扫描 0 泄露;PC 回归 100%(1464/1464) ·
移动端 100%(807/807);门禁品牌 25 / 隔离 31 / 移动文档 12 / 示例 9 / 版本 40 / i18n 17 全绿;
已按 AGENTS §九 发布公网,2461/2461 逐字节一致,五项验收全过。

已知未处理(既有缺口,ROADMAP S7-P28 已记录):data.mobile.json 的
meta.generated 为墙上时钟,会让 CI 的「生成物可复现」断言在重跑构建后永远非空;
该 CI 流水线本身亦从未通过(无 runner)。
2026-09-23 07:31:06 +08:00

2166 lines
110 KiB
HTML
Raw Permalink 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>表单 Form — Kole UI Mobile</title>
<meta name="description" content="表单 Form:移动端组件(6 端实现:CSS / H5 原生 / React / Vue 2 / Vue 3 / uni-app)。与 PC 端物理隔离:类名 kole-m-、令牌 --kole-m-。规格来源:移动端规格 32 · 表单 Form。">
<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 is-active" href="mobile-form.html" aria-current="page">表单<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" 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;">Form</span></h1>
<p>把一组字段(标签 + 控件 + 错误提示)组织成一次可提交的操作(下单、开票、认证)</p>
<p style="margin-top: 8px;" class="m-chips">
<span class="m-chip m">数据录入</span>
<span class="m-chip">规格 32 · 表单 Form</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-form.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/Form.html?demo=&lt;id&gt;</code>(只显示该演示块),代码是该演示块在演示页里的原文,可复制。全部演示同屏可看 <a href="../../../frameworks-mobile/Form.html" target="_blank">演示页 ↗</a>。</p>
<h3 class="m-demo-group">01 组件类型</h3>
<div class="m-demo" id="demo-basic">
<div class="m-demo-head"><span class="m-demo-title">可提交表单</span><span class="m-chip">labelPosition=top</span></div>
<p class="m-demo-desc">置顶标签 + 必填星号 + 提示行;点提交执行校验并写入 data-submitted。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Form.html?demo=basic" title="表单 Form · 可提交表单" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 46 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Form.html · basic</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;basic&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;可提交表单(置顶标签 + 必填星号 + 提示行;点提交即校验通过并写入 data-submitted)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;form class=&quot;kole-m-form&quot; id=&quot;form-basic&quot; data-assert=&quot;form-basic&quot; novalidate&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-basic-name-label&quot;&gt;
&lt;span class=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;*&lt;/span&gt;收货人
&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; name=&quot;name&quot; value=&quot;陈立&quot; required
aria-labelledby=&quot;f-basic-name-label&quot; aria-required=&quot;true&quot;&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-basic-phone-label&quot;&gt;
&lt;span class=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;*&lt;/span&gt;手机号
&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; name=&quot;phone&quot; inputmode=&quot;numeric&quot; value=&quot;13800138000&quot; required
aria-labelledby=&quot;f-basic-phone-label&quot; aria-required=&quot;true&quot; aria-describedby=&quot;f-basic-phone-hint&quot;&gt;
&lt;span class=&quot;kole-m-form__hint&quot; id=&quot;f-basic-phone-hint&quot;&gt;用于接收发货与签收通知&lt;/span&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-basic-region-label&quot;&gt;所在地区&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;button class=&quot;kole-m-form__hit&quot; type=&quot;button&quot; aria-labelledby=&quot;f-basic-region-label&quot; aria-haspopup=&quot;dialog&quot;&gt;
&lt;span&gt;浙江省 杭州市 余杭区&lt;/span&gt;
&lt;span aria-hidden=&quot;true&quot;&gt;›&lt;/span&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-basic-remark-label&quot;&gt;备注&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;textarea class=&quot;kole-m-form__control kole-m-form__control--multiline&quot; name=&quot;remark&quot; rows=&quot;2&quot;
aria-labelledby=&quot;f-basic-remark-label&quot; placeholder=&quot;选填:放快递柜、工作日送达&quot;&gt;&lt;/textarea&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;button class=&quot;kole-m-form__submit&quot; type=&quot;submit&quot; id=&quot;form-basic-submit&quot;
data-behavior=&quot;click-sets-attr:#form-basic|data-submitted|true&quot;&gt;提交订单&lt;/button&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/section&gt;</code></pre></div>
</details>
</div>
<div class="m-demo" id="demo-left">
<div class="m-demo-head"><span class="m-demo-title">标签在左</span><span class="m-chip">labelPosition=left</span></div>
<p class="m-demo-desc">labelPosition=left:标签定宽 72px 与控件同行,适合一组纵向对齐的字段。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Form.html?demo=left" title="表单 Form · 标签在左" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 32 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Form.html · left</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&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;标签位置两态(labelPosition=left:标签定宽 72px 与控件同行,适合一组纵向对齐的字段)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;form class=&quot;kole-m-form kole-m-form--left&quot; data-assert=&quot;form-left&quot; novalidate&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-left-title-label&quot;&gt;
&lt;span class=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;*&lt;/span&gt;发票抬头
&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; value=&quot;杭州某科技有限公司&quot; required
aria-labelledby=&quot;f-left-title-label&quot; aria-required=&quot;true&quot;&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-left-no-label&quot;&gt;纳税人识别号&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; inputmode=&quot;numeric&quot; value=&quot;91330100MA2XXXXX0A&quot;
aria-labelledby=&quot;f-left-no-label&quot;&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-left-type-label&quot;&gt;票种&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;button class=&quot;kole-m-form__hit&quot; type=&quot;button&quot; aria-labelledby=&quot;f-left-type-label&quot; aria-haspopup=&quot;dialog&quot;&gt;
&lt;span&gt;电子普通发票&lt;/span&gt;
&lt;span aria-hidden=&quot;true&quot;&gt;›&lt;/span&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/section&gt;</code></pre></div>
</details>
</div>
<div class="m-demo" id="demo-borderless">
<div class="m-demo-head"><span class="m-demo-title">无分隔线</span><span class="m-chip">borderless=true</span></div>
<p class="m-demo-desc">borderless=true:字段之间靠留白分组,嵌在卡片里时用。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Form.html?demo=borderless" title="表单 Form · 无分隔线" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 25 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Form.html · borderless</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;borderless&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;无分隔线(borderless=true:字段之间靠留白分组,嵌在卡片里时用)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;form class=&quot;kole-m-form kole-m-form--borderless&quot; data-assert=&quot;form-borderless&quot; novalidate&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-bl-company-label&quot;&gt;
&lt;span class=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;*&lt;/span&gt;公司名称
&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; value=&quot;杭州某科技有限公司&quot; required
aria-labelledby=&quot;f-bl-company-label&quot; aria-required=&quot;true&quot;&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-bl-size-label&quot;&gt;公司规模&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;button class=&quot;kole-m-form__hit&quot; type=&quot;button&quot; aria-labelledby=&quot;f-bl-size-label&quot; aria-haspopup=&quot;dialog&quot;&gt;
&lt;span&gt;50~200 人&lt;/span&gt;
&lt;span aria-hidden=&quot;true&quot;&gt;›&lt;/span&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;/form&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-error">
<div class="m-demo-head"><span class="m-demo-title">校验错误</span><span class="m-chip">状态 error</span></div>
<p class="m-demo-desc">is-error + aria-invalid 双写;错误文案在控件下方,标签与星号同时变错误色。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Form.html?demo=error" title="表单 Form · 校验错误" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 25 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Form.html · error</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;error&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;校验错误态(is-error + aria-invalid 双写;错误文案在控件下方,标签与星号同时变色)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;form class=&quot;kole-m-form&quot; id=&quot;form-error&quot; data-assert=&quot;form-error&quot; novalidate&gt;
&lt;div class=&quot;kole-m-form__item is-error&quot; id=&quot;form-error-item&quot; data-invalid=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-err-phone-label&quot;&gt;
&lt;span class=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;*&lt;/span&gt;手机号
&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; inputmode=&quot;numeric&quot; value=&quot;138&quot; required
aria-labelledby=&quot;f-err-phone-label&quot; aria-required=&quot;true&quot;
aria-invalid=&quot;true&quot; aria-describedby=&quot;f-err-phone-msg&quot;&gt;
&lt;span class=&quot;kole-m-form__error&quot; id=&quot;f-err-phone-msg&quot; role=&quot;alert&quot;&gt;请输入 11 位手机号&lt;/span&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-err-code-label&quot;&gt;验证码&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; inputmode=&quot;numeric&quot; placeholder=&quot;6 位数字&quot;
aria-labelledby=&quot;f-err-code-label&quot;&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/section&gt;</code></pre></div>
</details>
</div>
<div class="m-demo" id="demo-disabled">
<div class="m-demo-head"><span class="m-demo-title">整表禁用</span><span class="m-chip">disabled=true</span></div>
<p class="m-demo-desc">字段置灰且不可聚焦,提交按钮一并置灰;读屏会播报不可用。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Form.html?demo=disabled" title="表单 Form · 整表禁用" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 25 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Form.html · disabled</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;disabled&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;整表禁用(字段置灰且不可聚焦;提交按钮一并置灰,读屏会播报不可用)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;form class=&quot;kole-m-form is-disabled&quot; data-assert=&quot;form-disabled&quot; novalidate&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-dis-id-label&quot;&gt;企业认证编号&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; value=&quot;CERT-2026-0912&quot; disabled
aria-labelledby=&quot;f-dis-id-label&quot;&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-dis-owner-label&quot;&gt;认证主体&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; value=&quot;杭州某科技有限公司&quot; disabled
aria-labelledby=&quot;f-dis-owner-label&quot; aria-describedby=&quot;f-dis-hint&quot;&gt;
&lt;span class=&quot;kole-m-form__hint&quot; id=&quot;f-dis-hint&quot;&gt;认证信息由管理员维护,暂不可修改&lt;/span&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;button class=&quot;kole-m-form__submit&quot; type=&quot;submit&quot; disabled&gt;提交&lt;/button&gt;
&lt;/div&gt;
&lt;/form&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>fields</code></td><td><code>Array</code></td><td><code>[]</code></td><td>字段数组,每项 { name, label, value, type, required, error, hint, placeholder }(规格 §32.2)</td><td>N</td></tr>
<tr><td><code>labelPosition</code></td><td><code>'top' | 'left'</code></td><td><code>'top'</code></td><td>变体 labelPosition:标签置顶还是定宽在控件左侧(规格 §32.3)</td><td>N</td></tr>
<tr><td><code>borderless</code></td><td><code>boolean</code></td><td><code>false</code></td><td>变体 borderless:字段之间是否画 1px 分隔线(规格 §32.3)</td><td>N</td></tr>
<tr><td><code>disabled</code></td><td><code>boolean</code></td><td><code>false</code></td><td>状态 disabled:整表置灰且不可聚焦(规格 §32.4)</td><td>N</td></tr>
<tr><td><code>submitText</code></td><td><code>string</code></td><td><code>'提交'</code></td><td>提交行按钮文案;空字符串表示不渲染提交行(规格 §32.5)</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>submit</code></td><td><code>(fields)</code></td><td>提交时触发,回传字段数组供宿主校验与请求(规格 §32.5)</td></tr>
<tr><td><code>change</code></td><td><code>(name, value)</code></td><td>字段值变化时触发,回传字段名与当前值(规格 §32.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>提交行之前的自定义字段区(宿主插入自己的字段结构,规格 §32.2 item)</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-form-label-width</code></td><td><code>72px</code></td><td>labelPosition=left 时的标签列宽</td></tr>
<tr><td><code>--kole-m-form-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>移动端窄屏放不下左右两列时标签默认置顶,只有需要一组字段纵向对齐时才退回到定宽左标签</li>
<li>每个字段的错误提示必须贴在它自己的控件下方 —— 触屏上用户看不到「页头汇总错误」</li>
<li>控件高度不小于 44px;非输入型控件(选择器一类)整行都是热区</li>
<li>失焦即校验(触屏上软键盘收起会触发 blur),提交时再全量校验一次</li>
</ul>
</section>
<section class="m-block">
<h2 id="interaction">交互与触控</h2>
<ul>
<li>控件高度不小于 44px;非输入型控件(选择器一类)整行都是热区,按下反馈是整行背景变化</li>
<li>错误提示出现在控件正下方,不挤占输入区,也不跨到标签列</li>
<li>失焦即校验(触屏上软键盘收起会触发 blur),提交时再全量校验一次</li>
<li>校验失败时不跳转、不滚动到页首,错误就落在出错的字段上</li>
<li>提交成功后写 data-submitted=&quot;true&quot; 作为可断言的提交凭证;星号与错误色不单独承载语义</li>
</ul>
</section>
<section class="m-block">
<h2 id="a11y">无障碍</h2>
<ul>
<li>标签用 aria-labelledby 关联到控件(标签不是占位符的替代品)</li>
<li>必填用控件的 aria-required=&quot;true&quot; 与原生 required 双写;星号本身 aria-hidden</li>
<li>错误文案用 aria-describedby 关联到控件,并带 role=&quot;alert&quot; 播报</li>
<li>禁用态用原生 disabled,读屏会播报不可用且键盘会跳过</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-input.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;">Input</em></td><td>单个字段的输入框(高度、清除按钮、错误态)由 Input 负责;Form 只管字段的组织与提交</td></tr>
<tr><td><a href="mobile-textarea.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;">Textarea</em></td><td>多行文本字段用 Textarea(计数、自动增高);Form 的 item 只是把它包进标签与错误提示里</td></tr>
<tr><td><a href="mobile-button.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;">Button</em></td><td>表单外的独立动作(取消、暂存)用 Button;只有「提交本表单」才用 Form 内置的提交行</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>
<tr><td><span class="m-chip">规格未定</span></td><td>左标签模式下标签列宽是否随字号变化(当前固定 72px)</td></tr>
<tr><td><span class="m-chip">规格未定</span></td><td>提交行是否允许放两个并列动作(如「保存草稿 + 提交」)</td></tr>
<tr><td><span class="m-chip">规格未定</span></td><td>只读(readonly)字段是否需要独立的视觉层,还是复用 disabled</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>form</code></td><td>根元素,包住全部字段与提交行</td></tr>
<tr><td><code>item</code></td><td>单个字段,一列一个,字段之间用 1px 分隔线划分</td></tr>
<tr><td><code>label</code></td><td>字段标签;required=true 时前面带一个错误色星号</td></tr>
<tr><td><code>star</code></td><td>必填星号,装饰性(aria-hidden),语义由控件的 aria-required 承担</td></tr>
<tr><td><code>control</code></td><td>字段控件(原生 input / textarea,或包一层的可点区域)</td></tr>
<tr><td><code>errorText</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>labelPosition</code></td><td>top / left</td><td><div><b>top</b> <span class="m-none">(由数据驱动,无专属类)</span></div><div><b>left</b> <span class="m-cls">.kole-m-form--left</span></div></td></tr>
<tr><td><code>borderless</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-form--borderless</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>labelPosition=top · borderless=false</code></td><td>默认(置顶标签 + 字段间分隔线)</td></tr>
<tr><td><code>labelPosition=left · borderless=false</code></td><td>左标签(定宽 72px 与控件同行)</td></tr>
<tr><td><code>labelPosition=top · borderless=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-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="可点区域最小边长">--kole-m-touch-target</span>
<span class="m-chip inherit" title="分割线/边框">--kole-color-border</span>
<span class="m-chip inherit" title="品牌主色:主按钮、选中态、链接">--kole-color-brand</span>
<span class="m-chip inherit" title="品牌主色点击">--kole-color-brand-active</span>
<span class="m-chip inherit" title="卡片背景">--kole-color-card-bg</span>
<span class="m-chip inherit" title="禁用背景(按钮禁用态)">--kole-color-disabled-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="禁用态文字 · WCAG 1.4.3 对禁用控件豁免(规范定义于组件1/2.txt)">--kole-color-text-disabled</span>
<span class="m-chip inherit" title="反色文字(品牌色背景上的白字)">--kole-color-text-inverse</span>
<span class="m-chip inherit" title="占位文字 · 4.54:1(原 #BFBFBF 仅 1.84:1)">--kole-color-text-placeholder</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-radius-base</span>
<span class="m-chip inherit" title="">--kole-space-12</span>
<span class="m-chip inherit" title="">--kole-space-16</span>
<span class="m-chip inherit" title="">--kole-space-4</span>
<span class="m-chip inherit" title="">--kole-space-8</span>
<span class="m-chip" title="组件级变量(可在业务侧覆盖)">--kole-m-form-gap</span>
<span class="m-chip" title="组件级变量(可在业务侧覆盖)">--kole-m-form-label-width</span>
</div>
</section>
<section class="m-block">
<h2 id="sources">6 端源码</h2>
<p class="m-sub">同一组件的六份实现(生产环境的类名与结构一致,差异只在技术栈写法与单位)。点开查看,右侧可复制。</p>
<details class="m-details">
<summary>frameworks-mobile/Form.css · 纯样式(CSS) · 191 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Form.css</span><button class="m-copy" type="button" data-copy="code-193">复制</button></div>
<pre id="code-193"><code>/* Kole UI Mobile · Form 样式 — 对齐移动端规格 §32
表单:每个字段由「标签 + 必填星号 + 控件 + 错误提示」四段组成。
移动端与桌面端的关键差别是**标签位置**:窄屏放不下定宽左标签时用置顶标签(默认),
需要纵向对齐的一组字段才用 labelPosition=left。
错误提示在控件下方(不在标签旁),错误态用 is-error 与 aria-invalid 双写。 */
.kole-m-form {
/* 组件级变量:业务侧可在容器上覆盖 */
--kole-m-form-label-width: 72px; /* labelPosition=left 时的标签列宽 */
--kole-m-form-gap: var(--kole-space-8); /* 标签与控件之间的间距 */
box-sizing: border-box;
width: 100%;
background: var(--kole-color-card-bg);
color: var(--kole-color-text-body);
font-family: inherit;
font-size: var(--kole-m-font-size-body);
line-height: 1.4;
}
/* 字段:一列一个字段,字段之间用 1px 分隔线划分(变体 borderless=false,默认) */
.kole-m-form__item {
box-sizing: border-box;
display: flex;
flex-direction: column;
gap: var(--kole-m-form-gap);
padding: var(--kole-space-12) var(--kole-m-gutter);
}
.kole-m-form:not(.kole-m-form--borderless) .kole-m-form__item + .kole-m-form__item {
border-top: 1px solid var(--kole-color-border);
}
/* 变体 borderless=true:不画分隔线,靠留白分组(贴在卡片里时用) */
.kole-m-form--borderless .kole-m-form__item + .kole-m-form__item { border-top: 0; }
/* 变体 labelPosition=left:标签与控件同一行,标签列定宽、控件自适应 */
.kole-m-form--left .kole-m-form__item {
flex-direction: row;
align-items: flex-start;
}
.kole-m-form--left .kole-m-form__label {
flex: 0 0 auto;
width: var(--kole-m-form-label-width);
/* 标签首行与控件首行文字对齐(控件自身有 8px 内边距与 1px 边框) */
padding-top: calc(var(--kole-space-8) + 1px);
}
.kole-m-form__label {
display: flex;
align-items: center;
gap: var(--kole-space-4);
color: var(--kole-color-text-title);
font-size: var(--kole-m-font-size-label);
}
/* 必填星号:语义由控件的 aria-required 承担,星号本身对读屏隐藏 */
.kole-m-form__star {
flex: 0 0 auto;
color: var(--kole-color-error);
font-size: var(--kole-m-font-size-label);
line-height: 1;
}
/* 控件列:控件 + 下方错误提示(错误提示跟着控件走,不跨到标签列) */
.kole-m-form__main {
flex: 1 1 auto;
min-width: 0;
display: flex;
flex-direction: column;
gap: var(--kole-space-4);
}
.kole-m-form__control {
box-sizing: border-box;
display: block;
width: 100%;
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: inherit;
font-size: var(--kole-m-font-size-body);
line-height: 1.4;
}
.kole-m-form__control::placeholder { color: var(--kole-color-text-placeholder); }
/* 多行字段:控件高度由宿主决定(min-height 仍是 44px 触控下限) */
.kole-m-form__control--multiline {
min-height: calc(var(--kole-m-touch-target) * 2);
resize: none;
}
.kole-m-form__control:focus-visible {
outline: 2px solid var(--kole-color-focus-ring);
outline-offset: -2px;
}
/* 非输入型控件(选择器一类)包一层可点区域:整行热区,按下有反馈 */
.kole-m-form__hit {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--kole-space-8);
width: 100%;
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: inherit;
font-size: var(--kole-m-font-size-body);
line-height: 1.4;
text-align: start;
}
.kole-m-form__hit:active { background: var(--kole-color-table-header-bg); }
/* 状态 error:字段级 —— 边框、标签与星号一起变错误色(不只靠一处提示) */
.kole-m-form__item.is-error .kole-m-form__control,
.kole-m-form__item.is-error .kole-m-form__hit { border-color: var(--kole-color-error); }
.kole-m-form__item.is-error .kole-m-form__label { color: var(--kole-color-error); }
.kole-m-form__error {
display: block;
color: var(--kole-color-error);
font-size: var(--kole-m-font-size-label);
line-height: 1.4;
}
/* 提示行:未出错时是辅助说明(如「用于接收发货通知」),出错时换成错误文案 */
.kole-m-form__hint {
display: block;
color: var(--kole-color-text-secondary);
font-size: var(--kole-m-font-size-label);
line-height: 1.4;
}
/* 状态 disabled:整表置灰且不可聚焦(子控件是原生 disabled,这里补视觉) */
.kole-m-form.is-disabled { background: var(--kole-color-disabled-bg); }
.kole-m-form.is-disabled .kole-m-form__label,
.kole-m-form.is-disabled .kole-m-form__hint { color: var(--kole-color-text-disabled); }
.kole-m-form.is-disabled .kole-m-form__control,
.kole-m-form.is-disabled .kole-m-form__hit {
background: var(--kole-color-disabled-bg);
color: var(--kole-color-text-disabled);
cursor: not-allowed;
}
/* 提交行:整行一个主操作按钮(高度 ≥ 44px 触控边长;禁用时置灰) */
.kole-m-form__submit {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
min-height: var(--kole-m-touch-target);
padding: 0 var(--kole-space-16);
border: 0;
border-radius: var(--kole-radius-base);
background: var(--kole-color-brand);
color: var(--kole-color-text-inverse);
font-family: inherit;
font-size: var(--kole-m-font-size-body);
line-height: 1;
cursor: pointer;
touch-action: manipulation;
}
.kole-m-form__submit:active { background: var(--kole-color-brand-active); }
.kole-m-form__submit:disabled,
.kole-m-form.is-disabled .kole-m-form__submit {
background: var(--kole-color-disabled-bg);
color: var(--kole-color-text-disabled);
cursor: not-allowed;
}
.kole-m-form__submit:focus-visible {
outline: 2px solid var(--kole-color-focus-ring);
outline-offset: 2px;
}
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Form.html · H5 原生(无框架) · 275 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Form.html</span><button class="m-copy" type="button" data-copy="code-194">复制</button></div>
<pre id="code-194"><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 · Form(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;Form.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-pad { padding: var(--kole-m-gutter); background: var(--kole-color-card-bg); border-block: 1px solid var(--kole-color-border); }
.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;basic&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;可提交表单(置顶标签 + 必填星号 + 提示行;点提交即校验通过并写入 data-submitted)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;form class=&quot;kole-m-form&quot; id=&quot;form-basic&quot; data-assert=&quot;form-basic&quot; novalidate&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-basic-name-label&quot;&gt;
&lt;span class=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;*&lt;/span&gt;收货人
&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; name=&quot;name&quot; value=&quot;陈立&quot; required
aria-labelledby=&quot;f-basic-name-label&quot; aria-required=&quot;true&quot;&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-basic-phone-label&quot;&gt;
&lt;span class=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;*&lt;/span&gt;手机号
&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; name=&quot;phone&quot; inputmode=&quot;numeric&quot; value=&quot;13800138000&quot; required
aria-labelledby=&quot;f-basic-phone-label&quot; aria-required=&quot;true&quot; aria-describedby=&quot;f-basic-phone-hint&quot;&gt;
&lt;span class=&quot;kole-m-form__hint&quot; id=&quot;f-basic-phone-hint&quot;&gt;用于接收发货与签收通知&lt;/span&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-basic-region-label&quot;&gt;所在地区&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;button class=&quot;kole-m-form__hit&quot; type=&quot;button&quot; aria-labelledby=&quot;f-basic-region-label&quot; aria-haspopup=&quot;dialog&quot;&gt;
&lt;span&gt;浙江省 杭州市 余杭区&lt;/span&gt;
&lt;span aria-hidden=&quot;true&quot;&gt;›&lt;/span&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-basic-remark-label&quot;&gt;备注&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;textarea class=&quot;kole-m-form__control kole-m-form__control--multiline&quot; name=&quot;remark&quot; rows=&quot;2&quot;
aria-labelledby=&quot;f-basic-remark-label&quot; placeholder=&quot;选填:放快递柜、工作日送达&quot;&gt;&lt;/textarea&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;button class=&quot;kole-m-form__submit&quot; type=&quot;submit&quot; id=&quot;form-basic-submit&quot;
data-behavior=&quot;click-sets-attr:#form-basic|data-submitted|true&quot;&gt;提交订单&lt;/button&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-block&quot; data-demo=&quot;left&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;标签位置两态(labelPosition=left:标签定宽 72px 与控件同行,适合一组纵向对齐的字段)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;form class=&quot;kole-m-form kole-m-form--left&quot; data-assert=&quot;form-left&quot; novalidate&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-left-title-label&quot;&gt;
&lt;span class=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;*&lt;/span&gt;发票抬头
&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; value=&quot;杭州某科技有限公司&quot; required
aria-labelledby=&quot;f-left-title-label&quot; aria-required=&quot;true&quot;&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-left-no-label&quot;&gt;纳税人识别号&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; inputmode=&quot;numeric&quot; value=&quot;91330100MA2XXXXX0A&quot;
aria-labelledby=&quot;f-left-no-label&quot;&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-left-type-label&quot;&gt;票种&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;button class=&quot;kole-m-form__hit&quot; type=&quot;button&quot; aria-labelledby=&quot;f-left-type-label&quot; aria-haspopup=&quot;dialog&quot;&gt;
&lt;span&gt;电子普通发票&lt;/span&gt;
&lt;span aria-hidden=&quot;true&quot;&gt;›&lt;/span&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-block&quot; data-demo=&quot;borderless&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;无分隔线(borderless=true:字段之间靠留白分组,嵌在卡片里时用)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;form class=&quot;kole-m-form kole-m-form--borderless&quot; data-assert=&quot;form-borderless&quot; novalidate&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-bl-company-label&quot;&gt;
&lt;span class=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;*&lt;/span&gt;公司名称
&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; value=&quot;杭州某科技有限公司&quot; required
aria-labelledby=&quot;f-bl-company-label&quot; aria-required=&quot;true&quot;&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-bl-size-label&quot;&gt;公司规模&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;button class=&quot;kole-m-form__hit&quot; type=&quot;button&quot; aria-labelledby=&quot;f-bl-size-label&quot; aria-haspopup=&quot;dialog&quot;&gt;
&lt;span&gt;50~200 人&lt;/span&gt;
&lt;span aria-hidden=&quot;true&quot;&gt;›&lt;/span&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-block&quot; data-demo=&quot;error&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;校验错误态(is-error + aria-invalid 双写;错误文案在控件下方,标签与星号同时变色)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;form class=&quot;kole-m-form&quot; id=&quot;form-error&quot; data-assert=&quot;form-error&quot; novalidate&gt;
&lt;div class=&quot;kole-m-form__item is-error&quot; id=&quot;form-error-item&quot; data-invalid=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-err-phone-label&quot;&gt;
&lt;span class=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;*&lt;/span&gt;手机号
&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; inputmode=&quot;numeric&quot; value=&quot;138&quot; required
aria-labelledby=&quot;f-err-phone-label&quot; aria-required=&quot;true&quot;
aria-invalid=&quot;true&quot; aria-describedby=&quot;f-err-phone-msg&quot;&gt;
&lt;span class=&quot;kole-m-form__error&quot; id=&quot;f-err-phone-msg&quot; role=&quot;alert&quot;&gt;请输入 11 位手机号&lt;/span&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-err-code-label&quot;&gt;验证码&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; inputmode=&quot;numeric&quot; placeholder=&quot;6 位数字&quot;
aria-labelledby=&quot;f-err-code-label&quot;&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-block&quot; data-demo=&quot;disabled&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;整表禁用(字段置灰且不可聚焦;提交按钮一并置灰,读屏会播报不可用)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;form class=&quot;kole-m-form is-disabled&quot; data-assert=&quot;form-disabled&quot; novalidate&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-dis-id-label&quot;&gt;企业认证编号&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; value=&quot;CERT-2026-0912&quot; disabled
aria-labelledby=&quot;f-dis-id-label&quot;&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;span class=&quot;kole-m-form__label&quot; id=&quot;f-dis-owner-label&quot;&gt;认证主体&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;input class=&quot;kole-m-form__control&quot; type=&quot;text&quot; value=&quot;杭州某科技有限公司&quot; disabled
aria-labelledby=&quot;f-dis-owner-label&quot; aria-describedby=&quot;f-dis-hint&quot;&gt;
&lt;span class=&quot;kole-m-form__hint&quot; id=&quot;f-dis-hint&quot;&gt;认证信息由管理员维护,暂不可修改&lt;/span&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-form__item&quot;&gt;
&lt;button class=&quot;kole-m-form__submit&quot; type=&quot;submit&quot; disabled&gt;提交&lt;/button&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;/div&gt;
&lt;script&gt;
/* 演示页脚本:最小可运行的校验与提交。
- 提交:逐个必填控件检查;空或不合法 → 该项加 is-error + aria-invalid + data-invalid,错误文案落到框下
- 全部通过 → 在 form 上写 data-submitted=&quot;true&quot;(真实业务里是发请求)
判据只做「必填 + 手机号 11 位」两件事 —— 正则与业务规则属于宿主(规格 §32.7)。 */
(function () {
var PHONE = /^[0-9]{11}$/;
function itemOf(control) { return control.closest('.kole-m-form__item'); }
function setError(control, message) {
var item = itemOf(control);
if (!item) return;
item.classList.add('is-error');
item.setAttribute('data-invalid', 'true');
control.setAttribute('aria-invalid', 'true');
var block = item.querySelector('.kole-m-form__main');
var msg = item.querySelector('.kole-m-form__error');
if (!msg &amp;&amp; block &amp;&amp; message) {
msg = document.createElement('span');
msg.className = 'kole-m-form__error';
msg.id = control.name ? 'f-auto-' + control.name + '-msg' : '';
msg.setAttribute('role', 'alert');
if (msg.id) control.setAttribute('aria-describedby', msg.id);
block.appendChild(msg);
}
if (msg) msg.textContent = message || '';
}
function clearError(control) {
var item = itemOf(control);
if (!item) return;
item.classList.remove('is-error');
item.removeAttribute('data-invalid');
control.removeAttribute('aria-invalid');
var msg = item.querySelector('.kole-m-form__error');
if (msg) msg.remove();
}
function check(control) {
var value = String(control.value || '').trim();
if (control.hasAttribute('required') &amp;&amp; !value) {
setError(control, '此项为必填');
return false;
}
if (control.getAttribute('inputmode') === 'numeric' &amp;&amp; control.name === 'phone' &amp;&amp; !PHONE.test(value)) {
setError(control, '请输入 11 位手机号');
return false;
}
clearError(control);
return true;
}
Array.prototype.forEach.call(document.querySelectorAll('.kole-m-form'), function (form) {
if (form.classList.contains('is-disabled')) return;
var controls = Array.prototype.slice.call(form.querySelectorAll('.kole-m-form__control'));
/* 失焦即校验(触屏上软键盘收起会触发 blur) */
controls.forEach(function (c) {
c.addEventListener('blur', function () { check(c); });
});
form.addEventListener('submit', function (e) {
e.preventDefault();
var ok = true;
controls.forEach(function (c) { if (!check(c)) ok = false; });
if (!ok) {
form.removeAttribute('data-submitted');
return;
}
form.setAttribute('data-submitted', 'true');
});
});
})();
&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');
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/Form.jsx · React · 134 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Form.jsx</span><button class="m-copy" type="button" data-copy="code-195">复制</button></div>
<pre id="code-195"><code>import React, { useRef } from 'react';
import './Form.css';
/* 表单(移动端)— 规格 §32
结构:item(字段)&gt; label(标签 + 必填星号)/ main(控件 + 错误提示)。
移动端与桌面端的关键差别是**标签位置**:窄屏默认置顶标签(labelPosition=top),
需要一组纵向对齐的字段时才用 left(定宽标签列)。
必填星号是装饰(aria-hidden),语义由控件的 aria-required / required 承担;
错误态由字段级 is-error + 控件 aria-invalid 双写,错误文案用 aria-describedby 关联。
本端只做「必填」的结构表达,不发请求、不做正则校验(业务规则在宿主,规格 §32.7)。 */
let seq = 0;
export default function Form({
fields = [],
labelPosition = 'top',
borderless = false,
disabled = false,
submitText = '提交',
onSubmit,
onChange,
children = null,
}) {
const idRef = useRef(null);
if (idRef.current === null) {
seq += 1;
idRef.current = 'kole-m-form-' + seq;
}
const base = idRef.current;
const cls =
'kole-m-form' +
(labelPosition === 'left' ? ' kole-m-form--left' : '') +
(borderless ? ' kole-m-form--borderless' : '') +
(disabled ? ' is-disabled' : '');
return (
&lt;form
className={cls}
noValidate
onSubmit={(e) =&gt; {
e.preventDefault();
if (disabled) return;
if (onSubmit) onSubmit(fields);
}}
&gt;
{fields.map((f, i) =&gt; {
const item = f || {};
const key = item.name || String(i);
const labelId = `${base}-label-${key}`;
const errorId = `${base}-error-${key}`;
const hintId = `${base}-hint-${key}`;
const describedBy = [item.error ? errorId : '', item.hint ? hintId : ''].filter(Boolean).join(' ') || undefined;
return (
&lt;div className={'kole-m-form__item' + (item.error ? ' is-error' : '')} key={String(key)}&gt;
&lt;span className=&quot;kole-m-form__label&quot; id={labelId}&gt;
{item.required ? (
&lt;span className=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;
*
&lt;/span&gt;
) : null}
{item.label}
&lt;/span&gt;
&lt;span className=&quot;kole-m-form__main&quot;&gt;
{item.type === 'select' ? (
/* 非输入型控件:整行可点(原生 button,键盘可达) */
&lt;button className=&quot;kole-m-form__hit&quot; type=&quot;button&quot; aria-labelledby={labelId} aria-haspopup=&quot;dialog&quot; disabled={disabled}&gt;
&lt;span&gt;{item.value || item.placeholder || ''}&lt;/span&gt;
&lt;span aria-hidden=&quot;true&quot;&gt;›&lt;/span&gt;
&lt;/button&gt;
) : item.type === 'textarea' ? (
&lt;textarea
className=&quot;kole-m-form__control kole-m-form__control--multiline&quot;
name={item.name}
rows={item.rows || 2}
value={item.value || ''}
placeholder={item.placeholder || ''}
disabled={disabled}
required={!!item.required}
aria-labelledby={labelId}
aria-required={item.required ? 'true' : undefined}
aria-invalid={item.error ? 'true' : undefined}
aria-describedby={describedBy}
onChange={(e) =&gt; {
if (disabled) return;
if (onChange) onChange(item.name, e.target.value);
}}
/&gt;
) : (
&lt;input
className=&quot;kole-m-form__control&quot;
type=&quot;text&quot;
inputMode={item.inputMode || undefined}
name={item.name}
value={item.value || ''}
placeholder={item.placeholder || ''}
disabled={disabled}
required={!!item.required}
aria-labelledby={labelId}
aria-required={item.required ? 'true' : undefined}
aria-invalid={item.error ? 'true' : undefined}
aria-describedby={describedBy}
onChange={(e) =&gt; {
if (disabled) return;
if (onChange) onChange(item.name, e.target.value);
}}
/&gt;
)}
{item.error ? (
&lt;span className=&quot;kole-m-form__error&quot; id={errorId} role=&quot;alert&quot;&gt;
{item.error}
&lt;/span&gt;
) : null}
{item.hint ? (
&lt;span className=&quot;kole-m-form__hint&quot; id={hintId}&gt;
{item.hint}
&lt;/span&gt;
) : null}
&lt;/span&gt;
&lt;/div&gt;
);
})}
{children}
{submitText ? (
&lt;div className=&quot;kole-m-form__item&quot;&gt;
&lt;button className=&quot;kole-m-form__submit&quot; type=&quot;submit&quot; disabled={disabled}&gt;
{submitText}
&lt;/button&gt;
&lt;/div&gt;
) : null}
&lt;/form&gt;
);
}
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Form.vue2.vue · Vue 2 · 130 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Form.vue2.vue</span><button class="m-copy" type="button" data-copy="code-196">复制</button></div>
<pre id="code-196"><code>&lt;template&gt;
&lt;form class=&quot;kole-m-form&quot; :class=&quot;formClass&quot; novalidate @submit.prevent=&quot;onSubmit&quot;&gt;
&lt;div
v-for=&quot;(item, i) in fields&quot;
:key=&quot;String(keyOf(item, i))&quot;
class=&quot;kole-m-form__item&quot;
:class=&quot;{ 'is-error': !!(item &amp;&amp; item.error) }&quot;
&gt;
&lt;span class=&quot;kole-m-form__label&quot; :id=&quot;labelId(item, i)&quot;&gt;
&lt;span v-if=&quot;item &amp;&amp; item.required&quot; class=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;*&lt;/span&gt;{{ item &amp;&amp; item.label }}
&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;button
v-if=&quot;item &amp;&amp; item.type === 'select'&quot;
class=&quot;kole-m-form__hit&quot;
type=&quot;button&quot;
:aria-labelledby=&quot;labelId(item, i)&quot;
aria-haspopup=&quot;dialog&quot;
:disabled=&quot;disabled&quot;
&gt;
&lt;span&gt;{{ item.value || item.placeholder || '' }}&lt;/span&gt;
&lt;span aria-hidden=&quot;true&quot;&gt;›&lt;/span&gt;
&lt;/button&gt;
&lt;textarea
v-else-if=&quot;item &amp;&amp; item.type === 'textarea'&quot;
class=&quot;kole-m-form__control kole-m-form__control--multiline&quot;
:name=&quot;item.name&quot;
:rows=&quot;item.rows || 2&quot;
:value=&quot;item.value || ''&quot;
:placeholder=&quot;item.placeholder || ''&quot;
:disabled=&quot;disabled&quot;
:required=&quot;!!item.required&quot;
:aria-labelledby=&quot;labelId(item, i)&quot;
:aria-required=&quot;item.required ? 'true' : null&quot;
:aria-invalid=&quot;item.error ? 'true' : null&quot;
:aria-describedby=&quot;describedBy(item, i)&quot;
@input=&quot;onInput(item, $event)&quot;
&gt;&lt;/textarea&gt;
&lt;input
v-else
class=&quot;kole-m-form__control&quot;
type=&quot;text&quot;
:inputmode=&quot;(item &amp;&amp; item.inputMode) || null&quot;
:name=&quot;item &amp;&amp; item.name&quot;
:value=&quot;(item &amp;&amp; item.value) || ''&quot;
:placeholder=&quot;(item &amp;&amp; item.placeholder) || ''&quot;
:disabled=&quot;disabled&quot;
:required=&quot;!!(item &amp;&amp; item.required)&quot;
:aria-labelledby=&quot;labelId(item, i)&quot;
:aria-required=&quot;item &amp;&amp; item.required ? 'true' : null&quot;
:aria-invalid=&quot;item &amp;&amp; item.error ? 'true' : null&quot;
:aria-describedby=&quot;describedBy(item, i)&quot;
@input=&quot;onInput(item, $event)&quot;
/&gt;
&lt;span v-if=&quot;item &amp;&amp; item.error&quot; class=&quot;kole-m-form__error&quot; :id=&quot;errorId(item, i)&quot; role=&quot;alert&quot;&gt;{{ item.error }}&lt;/span&gt;
&lt;span v-if=&quot;item &amp;&amp; item.hint&quot; class=&quot;kole-m-form__hint&quot; :id=&quot;hintId(item, i)&quot;&gt;{{ item.hint }}&lt;/span&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;slot&gt;&lt;/slot&gt;
&lt;div v-if=&quot;submitText&quot; class=&quot;kole-m-form__item&quot;&gt;
&lt;button class=&quot;kole-m-form__submit&quot; type=&quot;submit&quot; :disabled=&quot;disabled&quot;&gt;{{ submitText }}&lt;/button&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/template&gt;
&lt;script&gt;
/* 表单(移动端)— 规格 §32
结构:item(字段)&gt; label(标签 + 必填星号)/ main(控件 + 错误提示)。
移动端与桌面端的关键差别是**标签位置**:窄屏默认置顶标签(labelPosition=top),
需要一组纵向对齐的字段时才用 left(定宽标签列)。
必填星号是装饰(aria-hidden),语义由控件的 aria-required / required 承担;
错误态由字段级 is-error + 控件 aria-invalid 双写,错误文案用 aria-describedby 关联。
本端只做「必填」的结构表达,不发请求、不做正则校验(业务规则在宿主,规格 §32.7)。 */
var seq = 0;
export default {
name: 'KoleMForm',
props: {
fields: { type: Array, default: function () { return []; } },
labelPosition: { type: String, default: 'top' },
borderless: { type: Boolean, default: false },
disabled: { type: Boolean, default: false },
submitText: { type: String, default: '提交' }
},
data: function () {
seq += 1;
return { base: 'kole-m-form-' + seq };
},
computed: {
formClass: function () {
return [
this.labelPosition === 'left' ? 'kole-m-form--left' : '',
this.borderless ? 'kole-m-form--borderless' : '',
this.disabled ? 'is-disabled' : ''
].filter(Boolean);
}
},
methods: {
keyOf: function (item, i) {
return item &amp;&amp; item.name !== undefined ? item.name : i;
},
labelId: function (item, i) {
return this.base + '-label-' + this.keyOf(item, i);
},
errorId: function (item, i) {
return this.base + '-error-' + this.keyOf(item, i);
},
hintId: function (item, i) {
return this.base + '-hint-' + this.keyOf(item, i);
},
describedBy: function (item, i) {
var ids = [];
if (item &amp;&amp; item.error) ids.push(this.errorId(item, i));
if (item &amp;&amp; item.hint) ids.push(this.hintId(item, i));
return ids.length ? ids.join(' ') : null;
},
onInput: function (item, e) {
if (this.disabled) return;
this.$emit('change', item &amp;&amp; item.name, e.target.value);
},
onSubmit: function () {
if (this.disabled) return;
this.$emit('submit', this.fields);
}
}
};
&lt;/script&gt;
&lt;style src=&quot;./Form.css&quot;&gt;&lt;/style&gt;
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Form.vue3.vue · Vue 3 · 126 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Form.vue3.vue</span><button class="m-copy" type="button" data-copy="code-197">复制</button></div>
<pre id="code-197"><code>&lt;template&gt;
&lt;form class=&quot;kole-m-form&quot; :class=&quot;formClass&quot; novalidate @submit.prevent=&quot;onSubmit&quot;&gt;
&lt;div
v-for=&quot;(item, i) in fields&quot;
:key=&quot;String(item &amp;&amp; item.name !== undefined ? item.name : i)&quot;
class=&quot;kole-m-form__item&quot;
:class=&quot;{ 'is-error': !!(item &amp;&amp; item.error) }&quot;
&gt;
&lt;span class=&quot;kole-m-form__label&quot; :id=&quot;labelId(item, i)&quot;&gt;
&lt;span v-if=&quot;item &amp;&amp; item.required&quot; class=&quot;kole-m-form__star&quot; aria-hidden=&quot;true&quot;&gt;*&lt;/span&gt;{{ item &amp;&amp; item.label }}
&lt;/span&gt;
&lt;span class=&quot;kole-m-form__main&quot;&gt;
&lt;button
v-if=&quot;item &amp;&amp; item.type === 'select'&quot;
class=&quot;kole-m-form__hit&quot;
type=&quot;button&quot;
:aria-labelledby=&quot;labelId(item, i)&quot;
aria-haspopup=&quot;dialog&quot;
:disabled=&quot;disabled&quot;
&gt;
&lt;span&gt;{{ item.value || item.placeholder || '' }}&lt;/span&gt;
&lt;span aria-hidden=&quot;true&quot;&gt;›&lt;/span&gt;
&lt;/button&gt;
&lt;textarea
v-else-if=&quot;item &amp;&amp; item.type === 'textarea'&quot;
class=&quot;kole-m-form__control kole-m-form__control--multiline&quot;
:name=&quot;item.name&quot;
:rows=&quot;item.rows || 2&quot;
:value=&quot;item.value || ''&quot;
:placeholder=&quot;item.placeholder || ''&quot;
:disabled=&quot;disabled&quot;
:required=&quot;!!item.required&quot;
:aria-labelledby=&quot;labelId(item, i)&quot;
:aria-required=&quot;item.required ? 'true' : null&quot;
:aria-invalid=&quot;item.error ? 'true' : null&quot;
:aria-describedby=&quot;describedBy(item, i)&quot;
@input=&quot;onInput(item, $event)&quot;
&gt;&lt;/textarea&gt;
&lt;input
v-else
class=&quot;kole-m-form__control&quot;
type=&quot;text&quot;
:inputmode=&quot;(item &amp;&amp; item.inputMode) || null&quot;
:name=&quot;item &amp;&amp; item.name&quot;
:value=&quot;(item &amp;&amp; item.value) || ''&quot;
:placeholder=&quot;(item &amp;&amp; item.placeholder) || ''&quot;
:disabled=&quot;disabled&quot;
:required=&quot;!!(item &amp;&amp; item.required)&quot;
:aria-labelledby=&quot;labelId(item, i)&quot;
:aria-required=&quot;item &amp;&amp; item.required ? 'true' : null&quot;
:aria-invalid=&quot;item &amp;&amp; item.error ? 'true' : null&quot;
:aria-describedby=&quot;describedBy(item, i)&quot;
@input=&quot;onInput(item, $event)&quot;
/&gt;
&lt;span v-if=&quot;item &amp;&amp; item.error&quot; class=&quot;kole-m-form__error&quot; :id=&quot;errorId(item, i)&quot; role=&quot;alert&quot;&gt;{{ item.error }}&lt;/span&gt;
&lt;span v-if=&quot;item &amp;&amp; item.hint&quot; class=&quot;kole-m-form__hint&quot; :id=&quot;hintId(item, i)&quot;&gt;{{ item.hint }}&lt;/span&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;slot&gt;&lt;/slot&gt;
&lt;div v-if=&quot;submitText&quot; class=&quot;kole-m-form__item&quot;&gt;
&lt;button class=&quot;kole-m-form__submit&quot; type=&quot;submit&quot; :disabled=&quot;disabled&quot;&gt;{{ submitText }}&lt;/button&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/template&gt;
&lt;script setup&gt;
/* 表单(移动端)— 规格 §32
结构:item(字段)&gt; label(标签 + 必填星号)/ main(控件 + 错误提示)。
移动端与桌面端的关键差别是**标签位置**:窄屏默认置顶标签(labelPosition=top),
需要一组纵向对齐的字段时才用 left(定宽标签列)。
必填星号是装饰(aria-hidden),语义由控件的 aria-required / required 承担;
错误态由字段级 is-error + 控件 aria-invalid 双写,错误文案用 aria-describedby 关联。
本端只做「必填」的结构表达,不发请求、不做正则校验(业务规则在宿主,规格 §32.7)。 */
import { computed, ref } from 'vue';
const props = defineProps({
fields: { type: Array, default: () =&gt; [] },
labelPosition: { type: String, default: 'top' },
borderless: { type: Boolean, default: false },
disabled: { type: Boolean, default: false },
submitText: { type: String, default: '提交' }
});
const emit = defineEmits(['submit', 'change']);
/* 字段 / 提示的 id:同页多实例不撞号(模块级自增即可) */
let seq = 0;
const base = ref('');
seq += 1;
base.value = 'kole-m-form-' + seq;
const formClass = computed(() =&gt; [
props.labelPosition === 'left' ? 'kole-m-form--left' : '',
props.borderless ? 'kole-m-form--borderless' : '',
props.disabled ? 'is-disabled' : ''
].filter(Boolean));
function keyOf(item, i) {
return item &amp;&amp; item.name !== undefined ? item.name : i;
}
function labelId(item, i) {
return base.value + '-label-' + keyOf(item, i);
}
function errorId(item, i) {
return base.value + '-error-' + keyOf(item, i);
}
function hintId(item, i) {
return base.value + '-hint-' + keyOf(item, i);
}
function describedBy(item, i) {
const ids = [];
if (item &amp;&amp; item.error) ids.push(errorId(item, i));
if (item &amp;&amp; item.hint) ids.push(hintId(item, i));
return ids.length ? ids.join(' ') : null;
}
function onInput(item, e) {
if (props.disabled) return;
emit('change', item &amp;&amp; item.name, e.target.value);
}
function onSubmit() {
if (props.disabled) return;
emit('submit', props.fields);
}
&lt;/script&gt;
&lt;style src=&quot;./Form.css&quot;&gt;&lt;/style&gt;
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Form.uniapp.vue · uni-app(跨端:小程序 / App / H5) · 253 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Form.uniapp.vue</span><button class="m-copy" type="button" data-copy="code-198">复制</button></div>
<pre id="code-198"><code>&lt;template&gt;
&lt;view class=&quot;kole-m-form&quot; :class=&quot;formClass&quot;&gt;
&lt;view
v-for=&quot;(item, i) in fields&quot;
:key=&quot;String(keyOf(item, i))&quot;
class=&quot;kole-m-form__item&quot;
:class=&quot;{ 'is-error': !!(item &amp;&amp; item.error) }&quot;
&gt;
&lt;view class=&quot;kole-m-form__label&quot;&gt;
&lt;text v-if=&quot;item &amp;&amp; item.required&quot; class=&quot;kole-m-form__star&quot;&gt;*&lt;/text&gt;
&lt;text&gt;{{ item &amp;&amp; item.label }}&lt;/text&gt;
&lt;/view&gt;
&lt;view class=&quot;kole-m-form__main&quot;&gt;
&lt;view
v-if=&quot;item &amp;&amp; item.type === 'select'&quot;
class=&quot;kole-m-form__hit&quot;
:role=&quot;disabled ? '' : 'button'&quot;
:aria-disabled=&quot;disabled ? 'true' : 'false'&quot;
@tap=&quot;onSelect(item)&quot;
&gt;
&lt;text&gt;{{ item.value || item.placeholder || '' }}&lt;/text&gt;
&lt;text class=&quot;kole-m-form__arrow&quot;&gt;›&lt;/text&gt;
&lt;/view&gt;
&lt;textarea
v-else-if=&quot;item &amp;&amp; item.type === 'textarea'&quot;
class=&quot;kole-m-form__control kole-m-form__control--multiline&quot;
:name=&quot;item.name&quot;
:value=&quot;item.value || ''&quot;
:placeholder=&quot;item.placeholder || ''&quot;
:disabled=&quot;disabled&quot;
@input=&quot;onInput(item, $event)&quot;
/&gt;
&lt;input
v-else
class=&quot;kole-m-form__control&quot;
type=&quot;text&quot;
:name=&quot;item &amp;&amp; item.name&quot;
:value=&quot;(item &amp;&amp; item.value) || ''&quot;
:placeholder=&quot;(item &amp;&amp; item.placeholder) || ''&quot;
:disabled=&quot;disabled&quot;
:aria-required=&quot;item &amp;&amp; item.required ? 'true' : 'false'&quot;
:aria-invalid=&quot;item &amp;&amp; item.error ? 'true' : 'false'&quot;
@input=&quot;onInput(item, $event)&quot;
/&gt;
&lt;text v-if=&quot;item &amp;&amp; item.error&quot; class=&quot;kole-m-form__error&quot;&gt;{{ item.error }}&lt;/text&gt;
&lt;text v-if=&quot;item &amp;&amp; item.hint&quot; class=&quot;kole-m-form__hint&quot;&gt;{{ item.hint }}&lt;/text&gt;
&lt;/view&gt;
&lt;/view&gt;
&lt;slot&gt;&lt;/slot&gt;
&lt;view v-if=&quot;submitText&quot; class=&quot;kole-m-form__item&quot;&gt;
&lt;view
class=&quot;kole-m-form__submit&quot;
:role=&quot;disabled ? '' : 'button'&quot;
:aria-disabled=&quot;disabled ? 'true' : 'false'&quot;
@tap=&quot;onSubmit&quot;
&gt;
&lt;text&gt;{{ submitText }}&lt;/text&gt;
&lt;/view&gt;
&lt;/view&gt;
&lt;/view&gt;
&lt;/template&gt;
&lt;script setup&gt;
/* uni-app 端 · 表单(移动端)— 规格 §32
跨端差异:
① 表单根与字段用 view(小程序没有 &lt;form&gt; 的原生校验语义),提交用 view + role=&quot;button&quot; + @tap;
② 控件是 uni 的 &lt;input&gt; / &lt;textarea&gt;,事件对象是 { detail: { value } },没有 DOM event.target;
③ 必填星号用 &lt;text&gt;,语义由 :aria-required 承担(小程序读屏读 aria-*);
④ 不支持 :focus-visible,聚焦反馈改由控件自身边框承担。
尺寸用 rpx:88rpx = 375pt 下的 44px 触控最小边长。 */
import { computed, ref } from 'vue';
const props = defineProps({
fields: { type: Array, default: () =&gt; [] },
labelPosition: { type: String, default: 'top' },
borderless: { type: Boolean, default: false },
disabled: { type: Boolean, default: false },
submitText: { type: String, default: '提交' }
});
const emit = defineEmits(['submit', 'change']);
/* 唯一实例基名:同页多实例不撞号(模块级自增即可) */
let seq = 0;
const base = ref('');
seq += 1;
base.value = 'kole-m-form-' + seq;
const formClass = computed(() =&gt; [
props.labelPosition === 'left' ? 'kole-m-form--left' : '',
props.borderless ? 'kole-m-form--borderless' : '',
props.disabled ? 'is-disabled' : ''
].filter(Boolean));
function keyOf(item, i) {
return item &amp;&amp; item.name !== undefined ? item.name : i;
}
/* uni 的 input / textarea 事件对象为 { detail: { value } },无 DOM event.target */
function onInput(item, e) {
if (props.disabled) return;
emit('change', item &amp;&amp; item.name, e &amp;&amp; e.detail ? e.detail.value : '');
}
function onSelect(item) {
if (props.disabled) return;
emit('change', item &amp;&amp; item.name, item &amp;&amp; item.value);
}
function onSubmit() {
if (props.disabled) return;
emit('submit', props.fields);
}
&lt;/script&gt;
&lt;style&gt;
.kole-m-form {
--kole-m-form-label-width: 144rpx; /* labelPosition=left 时的标签列宽(72px @375pt) */
--kole-m-form-gap: 16rpx; /* 标签与控件之间的间距 */
--kole-m-touch-target: 88rpx;
--kole-m-font-size-body: 32rpx;
--kole-m-font-size-label: 28rpx;
--kole-m-gutter: 32rpx;
box-sizing: border-box;
width: 100%;
background-color: var(--kole-color-card-bg);
color: var(--kole-color-text-body);
font-size: var(--kole-m-font-size-body);
}
.kole-m-form__item {
box-sizing: border-box;
display: flex;
flex-direction: column;
padding: 24rpx var(--kole-m-gutter);
}
.kole-m-form:not(.kole-m-form--borderless) .kole-m-form__item + .kole-m-form__item {
border-top: 1rpx solid var(--kole-color-border);
}
.kole-m-form--borderless .kole-m-form__item + .kole-m-form__item { border-top: 0; }
.kole-m-form--left .kole-m-form__item { flex-direction: row; }
.kole-m-form--left .kole-m-form__label {
flex-shrink: 0;
width: var(--kole-m-form-label-width);
padding-top: 18rpx;
}
.kole-m-form__label {
display: flex;
align-items: center;
margin-bottom: var(--kole-m-form-gap);
color: var(--kole-color-text-title);
font-size: var(--kole-m-font-size-label);
}
.kole-m-form--left .kole-m-form__label { margin-bottom: 0; }
.kole-m-form__star {
padding-right: 8rpx;
color: var(--kole-color-error);
}
.kole-m-form__main { flex: 1; }
.kole-m-form__control {
box-sizing: border-box;
width: 100%;
min-height: var(--kole-m-touch-target);
padding: 16rpx 24rpx;
border: 1rpx 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-body);
}
.kole-m-form__control--multiline { min-height: 176rpx; }
/* 非输入型控件:整行热区,按下有反馈 */
.kole-m-form__hit {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: space-between;
min-height: var(--kole-m-touch-target);
padding: 16rpx 24rpx;
border: 1rpx solid var(--kole-color-border);
border-radius: 8rpx;
background-color: var(--kole-color-card-bg);
color: var(--kole-color-text-body);
}
.kole-m-form__hit:active { background-color: var(--kole-color-table-header-bg); }
.kole-m-form__arrow { color: var(--kole-color-text-placeholder); }
/* 状态 error:边框、标签与星号一起变错误色(不只靠一处提示) */
.kole-m-form__item.is-error .kole-m-form__control,
.kole-m-form__item.is-error .kole-m-form__hit { border-color: var(--kole-color-error); }
.kole-m-form__item.is-error .kole-m-form__label { color: var(--kole-color-error); }
.kole-m-form__error {
display: block;
padding-top: 8rpx;
color: var(--kole-color-error);
font-size: var(--kole-m-font-size-label);
}
.kole-m-form__hint {
display: block;
padding-top: 8rpx;
color: var(--kole-color-text-secondary);
font-size: var(--kole-m-font-size-label);
}
/* 状态 disabled:整表置灰 */
.kole-m-form.is-disabled { background-color: var(--kole-color-disabled-bg); }
.kole-m-form.is-disabled .kole-m-form__label,
.kole-m-form.is-disabled .kole-m-form__hint { color: var(--kole-color-text-disabled); }
.kole-m-form.is-disabled .kole-m-form__control,
.kole-m-form.is-disabled .kole-m-form__hit {
background-color: var(--kole-color-disabled-bg);
color: var(--kole-color-text-disabled);
}
/* 提交行:整行主操作(高度 ≥ 88rpx 触控边长) */
.kole-m-form__submit {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
min-height: var(--kole-m-touch-target);
border-radius: 8rpx;
background-color: var(--kole-color-brand);
color: var(--kole-color-text-inverse);
font-size: var(--kole-m-font-size-body);
}
.kole-m-form__submit:active { background-color: var(--kole-color-brand-active); }
.kole-m-form.is-disabled .kole-m-form__submit {
background-color: var(--kole-color-disabled-bg);
color: var(--kole-color-text-disabled);
}
&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">断言 16 条 · 全部通过</span>
<span class="m-status">报告 2026-09-22 23:01:05</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-form.json(点击展开原始 JSON)</summary>
<div class="m-code"><pre><code>{
"schemaVersion": 1,
"sourceKind": "authored-spec",
"provenance": "authored-in-repo",
"specFile": "spec/移动端规格.md",
"specSection": "32 · 表单 Form",
"confidence": "high",
"slug": "mobile-form",
"name": "表单 Form",
"semanticTypeCandidates": [
"form",
"form-item",
"field-group"
],
"variantDimensions": [
{
"name": "labelPosition",
"values": [
"top",
"left"
]
},
{
"name": "borderless",
"values": [
"false",
"true"
]
}
],
"representativeVariants": [
{
"labelPosition": "top",
"borderless": "false",
"label": "默认(置顶标签 + 字段间分隔线)"
},
{
"labelPosition": "left",
"borderless": "false",
"label": "左标签(定宽 72px 与控件同行)"
},
{
"labelPosition": "top",
"borderless": "true",
"label": "无分隔线(靠留白分组,嵌在卡片里)"
}
],
"anatomy": {
"form": "根元素,包住全部字段与提交行",
"item": "单个字段,一列一个,字段之间用 1px 分隔线划分",
"label": "字段标签;required=true 时前面带一个错误色星号",
"star": "必填星号,装饰性(aria-hidden),语义由控件的 aria-required 承担",
"control": "字段控件(原生 input / textarea,或包一层的可点区域)",
"errorText": "字段级错误提示,落在该字段控件下方"
},
"structurePatterns": {
"labelPosition": "top(标签在控件上方,默认)/ left(标签定宽 72px 与控件同行)",
"borderless": "false(字段之间有分隔线)/ true(不画线,靠留白分组)"
},
"usageHints": [
"把一组字段(标签 + 控件 + 错误提示)组织成一次可提交的操作(下单、开票、认证)",
"移动端窄屏放不下左右两列时标签默认置顶,只有需要一组字段纵向对齐时才退回到定宽左标签",
"每个字段的错误提示必须贴在它自己的控件下方 —— 触屏上用户看不到「页头汇总错误」",
"控件高度不小于 44px;非输入型控件(选择器一类)整行都是热区",
"失焦即校验(触屏上软键盘收起会触发 blur),提交时再全量校验一次"
],
"doNotInvent": [
"字段内容的业务校验规则(正则、长度、合法性判断都在宿主,本组件只表达结构)",
"提交请求、失败重试与「提交中」的按钮态",
"字段的联动显隐与动态增删(由宿主决定渲染什么)",
"页首错误汇总条(移动端用字段级提示,不做汇总)"
],
"unknowns": [
"左标签模式下标签列宽是否随字号变化(当前固定 72px)",
"提交行是否允许放两个并列动作(如「保存草稿 + 提交」)",
"只读(readonly)字段是否需要独立的视觉层,还是复用 disabled"
],
"interaction": [
"控件高度不小于 44px;非输入型控件(选择器一类)整行都是热区,按下反馈是整行背景变化",
"错误提示出现在控件正下方,不挤占输入区,也不跨到标签列",
"失焦即校验(触屏上软键盘收起会触发 blur),提交时再全量校验一次",
"校验失败时不跳转、不滚动到页首,错误就落在出错的字段上",
"提交成功后写 data-submitted=\"true\" 作为可断言的提交凭证;星号与错误色不单独承载语义"
],
"accessibility": [
"标签用 aria-labelledby 关联到控件(标签不是占位符的替代品)",
"必填用控件的 aria-required=\"true\" 与原生 required 双写;星号本身 aria-hidden",
"错误文案用 aria-describedby 关联到控件,并带 role=\"alert\" 播报",
"禁用态用原生 disabled,读屏会播报不可用且键盘会跳过"
],
"api": {
"source": "implementation",
"note": "props / events / slots 为 6 端实现的公共接口(说明文字取自规格对应小节)。字段名与各端源码逐名核对:node tools/verify-mobile-docs.mjs",
"requiredNote": "「必传」按严格定义:实现里**没有默认值**时才为 Y(本门禁逐条核对 props 与各端源码的默认值,防止契约与实现脱节)。",
"props": [
{
"name": "fields",
"type": "Array",
"default": "[]",
"desc": "字段数组,每项 { name, label, value, type, required, error, hint, placeholder }(规格 §32.2)",
"required": false
},
{
"name": "labelPosition",
"type": "'top' | 'left'",
"default": "'top'",
"desc": "变体 labelPosition:标签置顶还是定宽在控件左侧(规格 §32.3)",
"required": false
},
{
"name": "borderless",
"type": "boolean",
"default": "false",
"desc": "变体 borderless:字段之间是否画 1px 分隔线(规格 §32.3)",
"required": false
},
{
"name": "disabled",
"type": "boolean",
"default": "false",
"desc": "状态 disabled:整表置灰且不可聚焦(规格 §32.4)",
"required": false
},
{
"name": "submitText",
"type": "string",
"default": "'提交'",
"desc": "提交行按钮文案;空字符串表示不渲染提交行(规格 §32.5)",
"required": false
}
],
"events": [
{
"name": "submit",
"params": "(fields)",
"desc": "提交时触发,回传字段数组供宿主校验与请求(规格 §32.5)"
},
{
"name": "change",
"params": "(name, value)",
"desc": "字段值变化时触发,回传字段名与当前值(规格 §32.5)"
}
],
"slots": [
{
"name": "default",
"desc": "提交行之前的自定义字段区(宿主插入自己的字段结构,规格 §32.2 item)"
}
]
},
"variantClasses": {
"labelPosition": {
"top": [],
"left": [
".kole-m-form--left"
]
},
"borderless": {
"false": [],
"true": [
".kole-m-form--borderless"
]
}
},
"demos": [
{
"id": "basic",
"group": "01 组件类型",
"title": "可提交表单",
"desc": "置顶标签 + 必填星号 + 提示行;点提交执行校验并写入 data-submitted。",
"variant": "labelPosition=top"
},
{
"id": "left",
"group": "01 组件类型",
"title": "标签在左",
"desc": "labelPosition=left:标签定宽 72px 与控件同行,适合一组纵向对齐的字段。",
"variant": "labelPosition=left"
},
{
"id": "borderless",
"group": "01 组件类型",
"title": "无分隔线",
"desc": "borderless=true:字段之间靠留白分组,嵌在卡片里时用。",
"variant": "borderless=true"
},
{
"id": "error",
"group": "02 组件状态",
"title": "校验错误",
"desc": "is-error + aria-invalid 双写;错误文案在控件下方,标签与星号同时变错误色。",
"variant": "状态 error"
},
{
"id": "disabled",
"group": "02 组件状态",
"title": "整表禁用",
"desc": "字段置灰且不可聚焦,提交按钮一并置灰;读屏会播报不可用。",
"variant": "disabled=true"
}
],
"related": [
{
"slug": "mobile-input",
"why": "单个字段的输入框(高度、清除按钮、错误态)由 Input 负责;Form 只管字段的组织与提交"
},
{
"slug": "mobile-textarea",
"why": "多行文本字段用 Textarea(计数、自动增高);Form 的 item 只是把它包进标签与错误提示里"
},
{
"slug": "mobile-button",
"why": "表单外的独立动作(取消、暂存)用 Button;只有「提交本表单」才用 Form 内置的提交行"
}
]
}</code></pre></div>
</details>
</section>
<footer class="m-foot">
<p>生成物:本页由 <code>node tools/build-mobile.mjs</code> 从契约 <code>components/mobile-form.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>