Files
aurora-admin/site/m/component/mobile-rate.html
T
aurora-admin f1fbfc2ddb
Regression / regression (push) Canceled after 0s
feat(品牌标识): 几何 K 图标(favicon/顶栏标记/theme-color) + 并行会话成果入库
## 品牌标识(本次会话)

起因:品牌此前没有任何图形标识 —— 唯一 favicon 是内联 data-URI 里的字母「A」,
那是 v2.0.0「Aurora Admin → Kole UI」改名漏掉的一处(PC 顶栏也是「A」,
移动端站已是「K」;移动端文档站则完全没有 favicon)。

- 几何:24 网格三个互不接触的笔画(竖 + 两斜),圆头描边;
  描边 2.25 → 16px 标签页尺寸下正好 1.5px = 规范原文「描边1.5px」
- 取色分两套(刻意):favicon 硬编码品牌蓝/白(渲染在浏览器标签栏,不继承 kole-dark);
  顶栏标记走 currentColor(实测暗色下自动转 rgb(20,22,28))
- 新增 theme-color 双条(light #FFFFFF / dark #1C1F26,取 --kole-color-card-bg)
- 修 site/app.js hero 标语 KOLE ADMIN → KOLE UI(改名变形残留)
- 移动端 7 个模板补 favicon(此前计数 0)

验收:门禁 9 条全 OK(site-routing/site-routes/mobile-docs/mobile-site/isolation/
theme/nav/i18n/icons);PC 回归 1464/1464 · 移动端 807/807,各连跑 8 次一致;
两端 favicon 405 字节逐字节一致;PC 站控制台错误 1→0。

## 并行会话成果(本次一并入库)

- 图标系统:2576 图标(TDesign/Element Plus,MIT)+ 11 端注入 + 5 个构建门禁工具
  + IconPreview 预览页 + ICON-SPEC.md 冻结规格
- 移动端平台:47 组件 × 6 端 + 文档站 53 页 + 隔离门禁
- PC 组件:103 个大后台组件 / 组件11 批次
- uni-app:PC 端试点 + 移动端端实现 + 真实编译验证

## 工程

- .gitignore 补 .scratch/ 与 .zcode-preexisting-*.txt(会话中间产物,实测 9.1MB,不入库)
- CHANGELOG 补品牌标识条目
- ROADMAP 登 S8-P4(品牌标识任务包 + og:image/apple-touch-icon 未做部分)
2026-09-21 10:05:48 +08:00

2105 lines
118 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="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3E%3Crect%20width='24'%20height='24'%20rx='6'%20fill='%232F54EB'/%3E%3Cg%20fill='none'%20stroke='%23FFFFFF'%20stroke-width='2.25'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M7%205.5V18.5'/%3E%3Cpath%20d='M17%205.5l-6.25%204.06'/%3E%3Cpath%20d='M10.75%2014.44L17%2018.5'/%3E%3C/g%3E%3C/svg%3E">
<meta name="theme-color" content="#FFFFFF" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#1C1F26" media="(prefers-color-scheme: dark)">
<title>评分 Rate — Kole UI Mobile</title>
<meta name="description" content="评分 Rate:移动端组件(6 端实现:CSS / H5 原生 / React / Vue 2 / Vue 3 / uni-app)。与 PC 端物理隔离:类名 kole-m-、令牌 --kole-m-。规格来源:移动端规格 36 · 评分 Rate。">
<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" aria-hidden="true"><svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 5.5V18.5"/><path d="M17 5.5l-6.25 4.06"/><path d="M10.75 14.44L17 18.5"/></svg></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 is-active" href="mobile-rate.html" aria-current="page">评分<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;">Rate</span></h1>
<p>让用户对一次体验给出星级评价(商品、物流、服务),或只读展示已有的平均分</p>
<p style="margin-top: 8px;" class="m-chips">
<span class="m-chip m">数据录入</span>
<span class="m-chip">规格 36 · 评分 Rate</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-rate.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/Rate.html?demo=&lt;id&gt;</code>(只显示该演示块),代码是该演示块在演示页里的原文,可复制。全部演示同屏可看 <a href="../../../frameworks-mobile/Rate.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">allowHalf=false</span></div>
<p class="m-demo-desc">点第 N 颗即取 N 分;整行 44px 高,星形本体只有 24px。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Rate.html?demo=basic" title="评分 Rate · 基础用法" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 42 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Rate.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;基础用法(点第 N 颗即取 N 分;整行 44px 高,星形本体只有 24px)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;div class=&quot;kole-m-rate&quot; id=&quot;rate-basic&quot; role=&quot;radiogroup&quot; aria-label=&quot;商品评分&quot;
data-score=&quot;4&quot; data-max=&quot;5&quot; data-assert=&quot;rate-basic&quot;&gt;
&lt;span class=&quot;kole-m-rate__stars&quot;&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;1 星&quot;
data-behavior=&quot;click-sets-attr:#rate-basic|data-score|1&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;2 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;3 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;4 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;false&quot; aria-label=&quot;5 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__text&quot; aria-live=&quot;polite&quot;&gt;4 分&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;</code></pre></div>
</details>
</div>
<div class="m-demo" id="demo-half">
<div class="m-demo-head"><span class="m-demo-title">半星</span><span class="m-chip">allowHalf=true</span></div>
<p class="m-demo-desc">allowHalf=true:点某颗星的左半取 N-0.5 分、右半取 N 分。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Rate.html?demo=half" title="评分 Rate · 半星" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 52 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Rate.html · half</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;half&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;半星(allowHalf=true:点某颗星的左半取 N-0.5 分、右半取 N 分 —— 规则写进规格 §36.5)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;div class=&quot;kole-m-rate kole-m-rate--half&quot; id=&quot;rate-half&quot; role=&quot;radiogroup&quot; aria-label=&quot;物流评分&quot;
data-score=&quot;3.5&quot; data-max=&quot;5&quot; data-half=&quot;true&quot; data-assert=&quot;rate-half&quot;&gt;
&lt;span class=&quot;kole-m-rate__stars&quot;&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;1 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot;&gt;&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;2 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot;&gt;&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;3 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot;&gt;&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;3.5 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 50%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot;&gt;&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;false&quot; aria-label=&quot;5 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot;
data-behavior=&quot;click-sets-attr:#rate-half|data-score|4.5&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot;&gt;&lt;/span&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__text&quot; aria-live=&quot;polite&quot;&gt;3.5 分&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;</code></pre></div>
</details>
</div>
<div class="m-demo" id="demo-size">
<div class="m-demo-head"><span class="m-demo-title">尺寸两档</span><span class="m-chip">size=default|small</span></div>
<p class="m-demo-desc">size=small 星形 18px 用于行内展示;default 24px 用于可评分场景。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Rate.html?demo=size" title="评分 Rate · 尺寸两档" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 45 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Rate.html · size</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;size&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;尺寸两档(size=small 星形 18px,用于行内展示;default 24px 用于可评分场景)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot; data-assert=&quot;rate-size&quot;&gt;
&lt;div class=&quot;kole-m-rate kole-m-rate--small kole-m-rate--readonly&quot; role=&quot;img&quot; aria-label=&quot;评分 3 分(满分 5 分)&quot;&gt;
&lt;span class=&quot;kole-m-rate__stars&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__text&quot;&gt;small(18px)&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-rate kole-m-rate--readonly&quot; role=&quot;img&quot; aria-label=&quot;评分 3 分(满分 5 分)&quot;&gt;
&lt;span class=&quot;kole-m-rate__stars&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__text&quot;&gt;default(24px)&lt;/span&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-readonly">
<div class="m-demo-head"><span class="m-demo-title">只读展示</span><span class="m-chip">readonly=true</span></div>
<p class="m-demo-desc">readonly=true:星形不再是按钮、点击不改值,整组用 role=&quot;img&quot; 播报分值。</p>
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Rate.html?demo=readonly" title="评分 Rate · 只读展示" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 25 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Rate.html · readonly</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;readonly&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;只读展示(readonly=true:用于列表里展示已有评分,星形不再是按钮、点击不改值)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;div class=&quot;kole-m-rate kole-m-rate--readonly&quot; role=&quot;img&quot; aria-label=&quot;评分 4.5 分(满分 5 分)&quot; data-assert=&quot;rate-readonly&quot;&gt;
&lt;span class=&quot;kole-m-rate__stars&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 50%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__text&quot;&gt;4.5 分 · 共 128 条评价&lt;/span&gt;
&lt;/div&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/Rate.html?demo=disabled" title="评分 Rate · 禁用" loading="lazy"></iframe></div>
<details class="m-details"><summary>查看代码(演示页原文 · 41 行)</summary>
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Rate.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;div class=&quot;kole-m-rate is-disabled&quot; role=&quot;radiogroup&quot; aria-label=&quot;满意度评分&quot; aria-disabled=&quot;true&quot;
data-score=&quot;2&quot; data-max=&quot;5&quot; data-assert=&quot;rate-disabled&quot;&gt;
&lt;span class=&quot;kole-m-rate__stars&quot;&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;1 星&quot; disabled&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;2 星&quot; disabled&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;false&quot; aria-label=&quot;3 星&quot; disabled&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;false&quot; aria-label=&quot;4 星&quot; disabled&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;false&quot; aria-label=&quot;5 星&quot; disabled&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__text&quot; aria-live=&quot;polite&quot;&gt;2 分&lt;/span&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>value</code></td><td><code>number</code></td><td><code>0</code></td><td>受控分值,允许半星(3.5)与 0(未评分)(规格 §36.5)</td><td>N</td></tr>
<tr><td><code>max</code></td><td><code>number</code></td><td><code>5</code></td><td>满分星数,决定渲染几颗星(规格 §36.2 stars)</td><td>N</td></tr>
<tr><td><code>allowHalf</code></td><td><code>boolean</code></td><td><code>false</code></td><td>变体 allowHalf:是否允许半星(点左半取 N-0.5 分)(规格 §36.3)</td><td>N</td></tr>
<tr><td><code>size</code></td><td><code>'default' | 'small'</code></td><td><code>'default'</code></td><td>变体 size:星形 24px 还是 18px(行内展示用)(规格 §36.3)</td><td>N</td></tr>
<tr><td><code>readonly</code></td><td><code>boolean</code></td><td><code>false</code></td><td>变体 readonly:只读展示(不渲染可点区域,整组用 role=&quot;img&quot; 播报)(规格 §36.3)</td><td>N</td></tr>
<tr><td><code>disabled</code></td><td><code>boolean</code></td><td><code>false</code></td><td>状态 disabled:置灰且不可聚焦,点击不改值(规格 §36.4)</td><td>N</td></tr>
<tr><td><code>label</code></td><td><code>string</code></td><td><code>'评分'</code></td><td>无障碍名称,落到 radiogroup / img 的 aria-label(规格 §36.6)</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>change</code></td><td><code>(value)</code></td><td>点星或键盘步进改值时触发,回传新分值(可含 0.5)(规格 §36.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>数值文案位置的自定义内容(如「4.5 分 · 共 128 条评价」),替换默认的「N 分」(规格 §36.2 text)</td></tr>
</tbody>
</table>
<h3 class="m-h3">CSS 变量</h3>
<p class="m-sub">组件级变量(在组件样式表里定义)。业务侧可在自己的作用域内覆盖,不必改组件源码。</p>
<table class="m-table">
<thead><tr><th>名称</th><th>默认值</th><th>说明</th></tr></thead>
<tbody>
<tr><td><code>--kole-m-rate-star</code></td><td><code>24px</code></td><td>星形字号(= 视觉边长)</td></tr>
<tr><td><code>--kole-m-rate-gap</code></td><td><code>8px</code></td><td>星与星之间的间距</td></tr>
</tbody>
</table>
</section>
<section class="m-block">
<h2 id="usage">何时使用</h2>
<ul>
<li>让用户对一次体验给出星级评价(商品、物流、服务),或只读展示已有的平均分</li>
<li>触屏上没有悬停预览:桌面上鼠标划过就能预告「点下去会是几分」,触屏上这个预告不存在</li>
<li>填充比例(含半星)必须直接可读,且星形本体只有 24px、热区要补到 44px 高</li>
<li>点第 N 颗星取 N 分;allowHalf=true 时点第 N 颗星的左半取 N-0.5 分、右半取 N 分</li>
<li>取值后立即触发 change 事件(回传 3.5 这类半星值也是合法输入)</li>
</ul>
</section>
<section class="m-block">
<h2 id="interaction">交互与触控</h2>
<ul>
<li>**取值规则**:点第 N 颗星取 N 分;allowHalf=true 时点第 N 颗星的**左半**取 N-0.5 分、**右半**取 N 分(半星只在开启该项时存在,默认整星)</li>
<li>星形本体视觉 24px(size=small 时 18px),但每颗星的可点区域高度是 44px;横向不做死区,相邻星的边界就是两半分界</li>
<li>一次触摸即取值,不需要二次确认;不响应长按与拖动(拖动选分在触屏上容易滑错,规格未纳入)</li>
<li>已选中的部分用**填充比例**表达(半星就是左半填充),不能只靠颜色深浅区分</li>
<li>取值后立即触发 change 事件(回传 3.5 这类半星值也是合法输入)</li>
<li>readonly=true 时不渲染任何可点区域(只读展示不抢键盘序列)</li>
</ul>
</section>
<section class="m-block">
<h2 id="a11y">无障碍</h2>
<ul>
<li>可评分形态:根是 role=&quot;radiogroup&quot; + aria-label,每颗星是原生 button + role=&quot;radio&quot; + aria-checked</li>
<li>星形的名称是「N 星」(aria-label),读屏播报的是分值而不是符号</li>
<li>只读形态:整组是一个 role=&quot;img&quot; + aria-label(「评分 4.5 分(满分 5 分)」),组内星形 aria-hidden</li>
<li>禁用态用原生 disabled 并补 aria-disabled=&quot;true&quot;</li>
<li>键盘:聚焦后左右方向键步进(整星模式步长 1,半星模式步长 0.5)</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-slider.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;">Slider</em></td><td>连续区间的粗选用 Slider;离散档位(1~5 星)且带语义的用 Rate</td></tr>
<tr><td><a href="mobile-form.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;">Form</em></td><td>评分作为表单里的一个字段时,标签、必填星号与错误提示由 Form 的 item 提供</td></tr>
<tr><td><a href="mobile-tag.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;">Tag</em></td><td>只是标注一个既有结论(如「好评」「差评」)用 Tag;需要用户给出分值时用 Rate</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>评分的业务含义映射(如「4 分以上算好评」)与统计口径</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>分值是否允许与文案一一对应(如 1 分「很差」、5 分「很好」)</td></tr>
<tr><td><span class="m-chip">规格未定</span></td><td>星形换用图标字体或 SVG 后填充比例的表达是否仍然一致</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>rate</code></td><td>根元素,一行里放进「星组 + 数值文案」</td></tr>
<tr><td><code>stars</code></td><td>星组,横向排列,只负责布局</td></tr>
<tr><td><code>star</code></td><td>单颗星,可点区域(原生 button),自身撑满 44px 高</td></tr>
<tr><td><code>glyph</code></td><td>星形本体(视觉 24px),由灰底星 + 品牌色覆盖层叠成</td></tr>
<tr><td><code>fill</code></td><td>覆盖层,宽度即该颗星的填充比例(100% 整星 / 50% 半星 / 0% 未选)</td></tr>
<tr><td><code>text</code></td><td>数值文案,默认「N 分」,可由默认插槽替换</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>size</code></td><td>default / small</td><td><div><b>default</b> <span class="m-none">(由数据驱动,无专属类)</span></div><div><b>small</b> <span class="m-cls">.kole-m-rate--small</span></div></td></tr>
<tr><td><code>allowHalf</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-rate--half</span> <span class="m-cls">.kole-m-rate__half</span></div></td></tr>
<tr><td><code>readonly</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-rate--readonly</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>size=default · allowHalf=false · readonly=false</code></td><td>默认(整星可评分,星形 24px)</td></tr>
<tr><td><code>size=default · allowHalf=true · readonly=false</code></td><td>支持半星(点左半取 N-0.5 分)</td></tr>
<tr><td><code>size=small · allowHalf=false · readonly=true</code></td><td>行内只读展示(星形 18px,不占键盘序列)</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-brand</span>
<span class="m-chip inherit" title="卡片背景">--kole-color-card-bg</span>
<span class="m-chip inherit" title="输入框聚焦外发光">--kole-color-focus-ring</span>
<span class="m-chip inherit" title="----------------------------------------------------------
status — 成功/警告/错误/信息色
这些色值同时用于「文字」与「填充底」,两处都要达标:
作文字需 ≥4.5:1;作填充底时其上的白字也需 ≥4.5:1。
故取 Ant 色阶 7(色阶 6 的白字/白底对比度均不足)。
----------------------------------------------------------">--kole-color-icon-inactive</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="次要文字 · 5.10:1(原 #8C8C8C 仅 3.36:1)">--kole-color-text-secondary</span>
<span class="m-chip inherit" title="">--kole-space-8</span>
<span class="m-chip" title="组件级变量(可在业务侧覆盖)">--kole-m-rate-gap</span>
<span class="m-chip" title="组件级变量(可在业务侧覆盖)">--kole-m-rate-star</span>
</div>
</section>
<section class="m-block">
<h2 id="sources">6 端源码</h2>
<p class="m-sub">同一组件的六份实现(生产环境的类名与结构一致,差异只在技术栈写法与单位)。点开查看,右侧可复制。</p>
<details class="m-details">
<summary>frameworks-mobile/Rate.css · 纯样式(CSS) · 125 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Rate.css</span><button class="m-copy" type="button" data-copy="code-205">复制</button></div>
<pre id="code-205"><code>/* Kole UI Mobile · Rate 样式 — 对齐移动端规格 §36
评分:点第 N 颗星即取 N 分;allowHalf=true 时点某颗星的左半取 N-0.5 分(半星规则见 §36.5)。
触屏上没有鼠标悬停预览,所以「已选中的部分」必须靠填充比例表达(半星就是左半填充),
不能只靠颜色深浅;星形本体视觉只有 24px,热区要补到 44px 高。
填充的实现:每颗星是「灰底星 + 品牌色覆盖层」,覆盖层的宽度就是这半颗/整颗的填充比例
(而不是叠一个透明度,那样在浅色轨道上看不出分界)。 */
.kole-m-rate {
/* 组件级变量:业务侧可在容器上覆盖 */
--kole-m-rate-star: 24px; /* 星形字号(= 视觉边长) */
--kole-m-rate-gap: 8px; /* 星与星之间的间距 */
box-sizing: border-box;
display: flex;
align-items: center;
gap: var(--kole-space-8);
width: 100%;
min-height: var(--kole-m-touch-target);
padding: 0 var(--kole-m-gutter);
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;
}
/* 变体 size=small:紧凑(列表里展示已有评分时用,配 readonly) */
.kole-m-rate--small { --kole-m-rate-star: 18px; }
/* 星组:横向排列;每颗星自身撑到 44px 高(热区),所以组本身就够高 */
.kole-m-rate__stars {
flex: 0 0 auto;
display: flex;
align-items: center;
}
/* 交互形态:每颗星是独立可聚焦的按钮(radiogroup 里的一项) */
.kole-m-rate__star {
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
position: relative;
height: var(--kole-m-touch-target);
padding: 0 calc(var(--kole-m-rate-gap) / 2);
margin: 0;
border: 0;
background: none;
color: inherit;
font: inherit;
line-height: 1;
cursor: pointer;
touch-action: manipulation;
}
.kole-m-rate__star:disabled { cursor: not-allowed; }
/* 星形本体:灰底 + 覆盖层(覆盖层宽度 = 填充比例,表达半星) */
.kole-m-rate__glyph {
position: relative;
display: inline-block;
font-size: var(--kole-m-rate-star);
line-height: 1;
}
.kole-m-rate__base { color: var(--kole-color-icon-inactive); }
.kole-m-rate__fill {
position: absolute;
top: 0;
bottom: 0;
left: 0;
overflow: hidden;
white-space: nowrap;
color: var(--kole-color-brand);
}
/* 半星的点击分区:盖在星形本体左右各一半上(纵向由整颗星的 44px 承担)。
只在 allowHalf=true(.kole-m-rate--half)时出现 —— 整星模式下点击位置不影响取值。 */
.kole-m-rate__half {
display: none;
position: absolute;
top: 0;
bottom: 0;
width: 50%;
}
.kole-m-rate--half .kole-m-rate__half { display: block; }
.kole-m-rate__half--left { left: 0; }
.kole-m-rate__half--right { right: 0; }
/* 数值文案:默认「N 分」,可由默认插槽替换成任意内容 */
.kole-m-rate__text {
flex: 1 1 auto;
min-width: 0;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
color: var(--kole-color-text-secondary);
font-size: var(--kole-m-font-size-label);
}
/* 变体 readonly=true:只读展示(值仍被读屏读出,但不可改;星形不再是按钮) */
.kole-m-rate--readonly { cursor: default; }
.kole-m-rate--readonly .kole-m-rate__star { cursor: default; }
.kole-m-rate--readonly .kole-m-rate__half { display: none; }
.kole-m-rate--readonly .kole-m-rate__text { color: var(--kole-color-text-secondary); }
/* 状态 disabled:整条置灰且不可聚焦 */
.kole-m-rate.is-disabled { cursor: not-allowed; }
.kole-m-rate.is-disabled .kole-m-rate__base,
.kole-m-rate.is-disabled .kole-m-rate__fill { color: var(--kole-color-text-disabled); }
.kole-m-rate.is-disabled .kole-m-rate__text { color: var(--kole-color-text-disabled); }
.kole-m-rate__star:focus-visible {
outline: 2px solid var(--kole-color-focus-ring);
outline-offset: -2px;
}
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Rate.html · H5 原生(无框架) · 307 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Rate.html</span><button class="m-copy" type="button" data-copy="code-206">复制</button></div>
<pre id="code-206"><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 · Rate(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;Rate.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 { 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;基础用法(点第 N 颗即取 N 分;整行 44px 高,星形本体只有 24px)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;div class=&quot;kole-m-rate&quot; id=&quot;rate-basic&quot; role=&quot;radiogroup&quot; aria-label=&quot;商品评分&quot;
data-score=&quot;4&quot; data-max=&quot;5&quot; data-assert=&quot;rate-basic&quot;&gt;
&lt;span class=&quot;kole-m-rate__stars&quot;&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;1 星&quot;
data-behavior=&quot;click-sets-attr:#rate-basic|data-score|1&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;2 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;3 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;4 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;false&quot; aria-label=&quot;5 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__text&quot; aria-live=&quot;polite&quot;&gt;4 分&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-block&quot; data-demo=&quot;half&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;半星(allowHalf=true:点某颗星的左半取 N-0.5 分、右半取 N 分 —— 规则写进规格 §36.5)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;div class=&quot;kole-m-rate kole-m-rate--half&quot; id=&quot;rate-half&quot; role=&quot;radiogroup&quot; aria-label=&quot;物流评分&quot;
data-score=&quot;3.5&quot; data-max=&quot;5&quot; data-half=&quot;true&quot; data-assert=&quot;rate-half&quot;&gt;
&lt;span class=&quot;kole-m-rate__stars&quot;&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;1 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot;&gt;&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;2 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot;&gt;&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;3 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot;&gt;&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;3.5 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 50%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot;&gt;&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;false&quot; aria-label=&quot;5 星&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot;
data-behavior=&quot;click-sets-attr:#rate-half|data-score|4.5&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot;&gt;&lt;/span&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__text&quot; aria-live=&quot;polite&quot;&gt;3.5 分&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-block&quot; data-demo=&quot;readonly&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;只读展示(readonly=true:用于列表里展示已有评分,星形不再是按钮、点击不改值)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot;&gt;
&lt;div class=&quot;kole-m-rate kole-m-rate--readonly&quot; role=&quot;img&quot; aria-label=&quot;评分 4.5 分(满分 5 分)&quot; data-assert=&quot;rate-readonly&quot;&gt;
&lt;span class=&quot;kole-m-rate__stars&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 50%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__text&quot;&gt;4.5 分 · 共 128 条评价&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section class=&quot;demo-block&quot; data-demo=&quot;size&quot;&gt;
&lt;p class=&quot;demo-label&quot;&gt;尺寸两档(size=small 星形 18px,用于行内展示;default 24px 用于可评分场景)&lt;/p&gt;
&lt;div class=&quot;demo-pad&quot; data-assert=&quot;rate-size&quot;&gt;
&lt;div class=&quot;kole-m-rate kole-m-rate--small kole-m-rate--readonly&quot; role=&quot;img&quot; aria-label=&quot;评分 3 分(满分 5 分)&quot;&gt;
&lt;span class=&quot;kole-m-rate__stars&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__text&quot;&gt;small(18px)&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;kole-m-rate kole-m-rate--readonly&quot; role=&quot;img&quot; aria-label=&quot;评分 3 分(满分 5 分)&quot;&gt;
&lt;span class=&quot;kole-m-rate__stars&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__text&quot;&gt;default(24px)&lt;/span&gt;
&lt;/div&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;div class=&quot;kole-m-rate is-disabled&quot; role=&quot;radiogroup&quot; aria-label=&quot;满意度评分&quot; aria-disabled=&quot;true&quot;
data-score=&quot;2&quot; data-max=&quot;5&quot; data-assert=&quot;rate-disabled&quot;&gt;
&lt;span class=&quot;kole-m-rate__stars&quot;&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;1 星&quot; disabled&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;true&quot; aria-label=&quot;2 星&quot; disabled&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 100%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;false&quot; aria-label=&quot;3 星&quot; disabled&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;false&quot; aria-label=&quot;4 星&quot; disabled&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;button class=&quot;kole-m-rate__star&quot; type=&quot;button&quot; role=&quot;radio&quot; aria-checked=&quot;false&quot; aria-label=&quot;5 星&quot; disabled&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; style=&quot;width: 0%&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__text&quot; aria-live=&quot;polite&quot;&gt;2 分&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;/div&gt;
&lt;script&gt;
/* 演示页脚本:真实评分。
半星规则(写进规格 §36.5):allowHalf=true 时,点第 N 颗星的**左半**取 N-0.5 分、右半取 N 分;
整星模式(默认)下点击位置不影响取值,一律取 N。
每次改值重算每颗星的填充比例(0% / 50% / 100%),并同步 aria-checked 与右侧文案。
真实业务里这份状态由宿主管理(受控 value + change 事件),此处是最小可运行实现。 */
(function () {
function scoreOf(root) {
return Number(root.getAttribute('data-score') || 0);
}
function render(root) {
var score = scoreOf(root);
var stars = root.querySelectorAll('.kole-m-rate__star');
Array.prototype.forEach.call(stars, function (star, i) {
var ratio = Math.max(0, Math.min(1, score - i));
var fill = star.querySelector('.kole-m-rate__fill');
if (fill) fill.style.width = (ratio * 100) + '%';
star.setAttribute('aria-checked', ratio &gt;= 1 ? 'true' : 'false');
});
var text = root.querySelector('.kole-m-rate__text');
if (text) text.textContent = score + ' 分';
}
Array.prototype.forEach.call(document.querySelectorAll('.kole-m-rate'), function (root) {
if (root.classList.contains('is-disabled') || root.classList.contains('kole-m-rate--readonly')) return;
if (root.getAttribute('aria-disabled') === 'true') return;
var half = root.getAttribute('data-half') === 'true' || root.classList.contains('kole-m-rate--half');
root.addEventListener('click', function (e) {
var star = e.target.closest ? e.target.closest('.kole-m-rate__star') : null;
if (!star || !root.contains(star)) return;
var stars = Array.prototype.slice.call(root.querySelectorAll('.kole-m-rate__star'));
var index = stars.indexOf(star) + 1; /* 第 N 颗(1 起) */
if (!index) return;
var halfEl = e.target.closest ? e.target.closest('.kole-m-rate__half') : null;
var isLeftHalf = half &amp;&amp; halfEl &amp;&amp; halfEl.getAttribute('data-half') === 'left';
root.setAttribute('data-score', String(isLeftHalf ? index - 0.5 : index));
render(root);
});
/* 键盘:左右方向键整星步进(半星模式下是 0.5) */
root.addEventListener('keydown', function (e) {
var delta = e.key === 'ArrowLeft' || e.key === 'ArrowDown' ? -1 : e.key === 'ArrowRight' || e.key === 'ArrowUp' ? 1 : 0;
if (!delta) return;
e.preventDefault();
var max = Number(root.getAttribute('data-max') || 5);
var min = half ? 0.5 : 1;
var next = Math.round((scoreOf(root) + delta * (half ? 0.5 : 1)) * 2) / 2;
root.setAttribute('data-score', String(Math.max(min, Math.min(max, next))));
render(root);
});
});
})();
&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/Rate.jsx · React · 103 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Rate.jsx</span><button class="m-copy" type="button" data-copy="code-207">复制</button></div>
<pre id="code-207"><code>import React from 'react';
import './Rate.css';
/* 评分(移动端)— 规格 §36
点第 N 颗星取 N 分;allowHalf=true 时点某颗星的左半取 N-0.5 分(规则见规格 §36.5)。
触屏上没有鼠标悬停预览,所以「已选中的部分」靠填充比例表达(半星 = 左半填充),
不能只靠颜色深浅;星形本体视觉 24px,热区撑到 44px 高。
readonly=true 时是纯展示(用 role=&quot;img&quot; + aria-label 播报「N 分(满分 M 分)」),
此时不渲染任何可聚焦控件 —— 列表里一行一个评分不该抢走键盘序列。 */
export default function Rate({
value = 0,
max = 5,
allowHalf = false,
size = 'default',
readonly = false,
disabled = false,
label = '评分',
onChange,
children = null,
}) {
const cls =
'kole-m-rate' +
(allowHalf ? ' kole-m-rate--half' : '') +
(size === 'small' ? ' kole-m-rate--small' : '') +
(readonly ? ' kole-m-rate--readonly' : '') +
(disabled ? ' is-disabled' : '');
const stars = [];
for (let i = 0; i &lt; max; i++) stars.push(i);
function pick(index, isLeftHalf) {
if (readonly || disabled) return;
const next = isLeftHalf ? index - 0.5 : index;
if (onChange) onChange(next);
}
const ratioOf = (i) =&gt; Math.max(0, Math.min(1, value - i));
/* 只读形态:整组是一个 role=&quot;img&quot;,名称由 aria-label 播报(不留下可聚焦的星) */
if (readonly) {
return (
&lt;div className={cls} role=&quot;img&quot; aria-label={`${label} ${value} 分(满分 ${max} 分)`}&gt;
&lt;span className=&quot;kole-m-rate__stars&quot; aria-hidden=&quot;true&quot;&gt;
{stars.map((i) =&gt; (
&lt;span className=&quot;kole-m-rate__star&quot; key={i}&gt;
&lt;span className=&quot;kole-m-rate__glyph&quot;&gt;
&lt;span className=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span className=&quot;kole-m-rate__fill&quot; style={{ width: ratioOf(i) * 100 + '%' }}&gt;
★
&lt;/span&gt;
&lt;/span&gt;
&lt;/span&gt;
))}
&lt;/span&gt;
{children || &lt;span className=&quot;kole-m-rate__text&quot;&gt;{value} 分&lt;/span&gt;}
&lt;/div&gt;
);
}
return (
&lt;div className={cls} role=&quot;radiogroup&quot; aria-label={label} aria-disabled={disabled ? 'true' : undefined}&gt;
&lt;span className=&quot;kole-m-rate__stars&quot;&gt;
{stars.map((i) =&gt; {
const index = i + 1;
const full = ratioOf(i) &gt;= 1;
return (
&lt;button
className=&quot;kole-m-rate__star&quot;
key={index}
type=&quot;button&quot;
role=&quot;radio&quot;
aria-checked={full ? 'true' : 'false'}
aria-label={`${index} 星`}
disabled={disabled}
onClick={(e) =&gt; {
/* 半星判定:点在左半区取 N-0.5,右半区取 N(整星模式下位置不影响取值) */
const isLeftHalf =
allowHalf &amp;&amp; e.target &amp;&amp; e.target.getAttribute &amp;&amp; e.target.getAttribute('data-half') === 'left';
pick(index, isLeftHalf);
}}
&gt;
&lt;span className=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span className=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span className=&quot;kole-m-rate__fill&quot; style={{ width: ratioOf(i) * 100 + '%' }}&gt;
★
&lt;/span&gt;
&lt;/span&gt;
{allowHalf ? (
&lt;&gt;
&lt;span className=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot; /&gt;
&lt;span className=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot; /&gt;
&lt;/&gt;
) : null}
&lt;/button&gt;
);
})}
&lt;/span&gt;
{children || &lt;span className=&quot;kole-m-rate__text&quot;&gt;{value} 分&lt;/span&gt;}
&lt;/div&gt;
);
}
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Rate.vue2.vue · Vue 2 · 122 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Rate.vue2.vue</span><button class="m-copy" type="button" data-copy="code-208">复制</button></div>
<pre id="code-208"><code>&lt;template&gt;
&lt;!-- 只读形态:整组是一个 role=&quot;img&quot;,名称由 aria-label 播报(不留下可聚焦的星) --&gt;
&lt;div
v-if=&quot;readonly&quot;
class=&quot;kole-m-rate&quot;
:class=&quot;rateClass&quot;
role=&quot;img&quot;
:aria-label=&quot;label + ' ' + value + ' 分(满分 ' + max + ' 分)'&quot;
&gt;
&lt;span class=&quot;kole-m-rate__stars&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span v-for=&quot;(i, k) in starIndexes&quot; :key=&quot;k&quot; class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; :style=&quot;{ width: ratioOf(i) * 100 + '%' }&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/span&gt;
&lt;/span&gt;
&lt;slot&gt;
&lt;span class=&quot;kole-m-rate__text&quot;&gt;{{ value }} 分&lt;/span&gt;
&lt;/slot&gt;
&lt;/div&gt;
&lt;div
v-else
class=&quot;kole-m-rate&quot;
:class=&quot;rateClass&quot;
role=&quot;radiogroup&quot;
:aria-label=&quot;label&quot;
:aria-disabled=&quot;disabled ? 'true' : null&quot;
@keydown=&quot;onKeyDown&quot;
&gt;
&lt;span class=&quot;kole-m-rate__stars&quot;&gt;
&lt;button
v-for=&quot;(i, k) in starIndexes&quot;
:key=&quot;k&quot;
class=&quot;kole-m-rate__star&quot;
type=&quot;button&quot;
role=&quot;radio&quot;
:aria-checked=&quot;ratioOf(i) &gt;= 1 ? 'true' : 'false'&quot;
:aria-label=&quot;i + 1 + ' 星'&quot;
:disabled=&quot;disabled&quot;
@click=&quot;pick(i, $event)&quot;
&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; :style=&quot;{ width: ratioOf(i) * 100 + '%' }&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;template v-if=&quot;allowHalf&quot;&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot;&gt;&lt;/span&gt;
&lt;/template&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;slot&gt;
&lt;span class=&quot;kole-m-rate__text&quot;&gt;{{ value }} 分&lt;/span&gt;
&lt;/slot&gt;
&lt;/div&gt;
&lt;/template&gt;
&lt;script&gt;
/* 评分(移动端)— 规格 §36
点第 N 颗星取 N 分;allowHalf=true 时点某颗星的左半取 N-0.5 分(规则见规格 §36.5)。
触屏上没有鼠标悬停预览,所以「已选中的部分」靠填充比例表达(半星 = 左半填充),
不能只靠颜色深浅;星形本体视觉 24px,热区撑到 44px 高。
readonly=true 时是纯展示(用 role=&quot;img&quot; + aria-label 播报「N 分(满分 M 分)」),
此时不渲染任何可聚焦控件 —— 列表里一行一个评分不该抢走键盘序列。 */
export default {
name: 'KoleMRate',
props: {
value: { type: Number, default: 0 },
max: { type: Number, default: 5 },
allowHalf: { type: Boolean, default: false },
size: { type: String, default: 'default' },
readonly: { type: Boolean, default: false },
disabled: { type: Boolean, default: false },
label: { type: String, default: '评分' }
},
computed: {
starIndexes: function () {
var out = [];
for (var i = 0; i &lt; this.max; i++) out.push(i);
return out;
},
rateClass: function () {
return [
this.allowHalf ? 'kole-m-rate--half' : '',
this.size === 'small' ? 'kole-m-rate--small' : '',
this.readonly ? 'kole-m-rate--readonly' : '',
this.disabled ? 'is-disabled' : ''
].filter(Boolean);
}
},
methods: {
ratioOf: function (i) {
return Math.max(0, Math.min(1, this.value - i));
},
pick: function (i, e) {
if (this.readonly || this.disabled) return;
/* 半星判定:点在左半区取 N-0.5,右半区取 N(整星模式下位置不影响取值) */
var el = e.target &amp;&amp; e.target.getAttribute ? e.target : null;
var isLeftHalf = this.allowHalf &amp;&amp; el &amp;&amp; el.getAttribute('data-half') === 'left';
var index = i + 1;
this.$emit('change', isLeftHalf ? index - 0.5 : index);
},
onKeyDown: function (e) {
if (this.readonly || this.disabled) return;
var delta =
e.key === 'ArrowLeft' || e.key === 'ArrowDown' ? -1 : e.key === 'ArrowRight' || e.key === 'ArrowUp' ? 1 : 0;
if (!delta) return;
e.preventDefault();
var stepValue = this.allowHalf ? 0.5 : 1;
var min = this.allowHalf ? 0.5 : 1;
var next = Math.round((this.value + delta * stepValue) * 2) / 2;
this.$emit('change', Math.max(min, Math.min(this.max, next)));
}
}
};
&lt;/script&gt;
&lt;style src=&quot;./Rate.css&quot;&gt;&lt;/style&gt;
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Rate.vue3.vue · Vue 3 · 113 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Rate.vue3.vue</span><button class="m-copy" type="button" data-copy="code-209">复制</button></div>
<pre id="code-209"><code>&lt;template&gt;
&lt;!-- 只读形态:整组是一个 role=&quot;img&quot;,名称由 aria-label 播报(不留下可聚焦的星) --&gt;
&lt;div
v-if=&quot;readonly&quot;
class=&quot;kole-m-rate&quot;
:class=&quot;rateClass&quot;
role=&quot;img&quot;
:aria-label=&quot;`${label} ${value} 分(满分 ${max} 分)`&quot;
&gt;
&lt;span class=&quot;kole-m-rate__stars&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span v-for=&quot;(i, k) in starIndexes&quot; :key=&quot;k&quot; class=&quot;kole-m-rate__star&quot;&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; :style=&quot;{ width: ratioOf(i) * 100 + '%' }&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;/span&gt;
&lt;/span&gt;
&lt;slot&gt;
&lt;span class=&quot;kole-m-rate__text&quot;&gt;{{ value }} 分&lt;/span&gt;
&lt;/slot&gt;
&lt;/div&gt;
&lt;div
v-else
class=&quot;kole-m-rate&quot;
:class=&quot;rateClass&quot;
role=&quot;radiogroup&quot;
:aria-label=&quot;label&quot;
:aria-disabled=&quot;disabled ? 'true' : null&quot;
@keydown=&quot;onKeyDown&quot;
&gt;
&lt;span class=&quot;kole-m-rate__stars&quot;&gt;
&lt;button
v-for=&quot;(i, k) in starIndexes&quot;
:key=&quot;k&quot;
class=&quot;kole-m-rate__star&quot;
type=&quot;button&quot;
role=&quot;radio&quot;
:aria-checked=&quot;ratioOf(i) &gt;= 1 ? 'true' : 'false'&quot;
:aria-label=&quot;(i + 1) + ' 星'&quot;
:disabled=&quot;disabled&quot;
@click=&quot;pick(i, $event)&quot;
&gt;
&lt;span class=&quot;kole-m-rate__glyph&quot; aria-hidden=&quot;true&quot;&gt;
&lt;span class=&quot;kole-m-rate__base&quot;&gt;★&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__fill&quot; :style=&quot;{ width: ratioOf(i) * 100 + '%' }&quot;&gt;★&lt;/span&gt;
&lt;/span&gt;
&lt;template v-if=&quot;allowHalf&quot;&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; data-half=&quot;left&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; data-half=&quot;right&quot;&gt;&lt;/span&gt;
&lt;/template&gt;
&lt;/button&gt;
&lt;/span&gt;
&lt;slot&gt;
&lt;span class=&quot;kole-m-rate__text&quot;&gt;{{ value }} 分&lt;/span&gt;
&lt;/slot&gt;
&lt;/div&gt;
&lt;/template&gt;
&lt;script setup&gt;
/* 评分(移动端)— 规格 §36
点第 N 颗星取 N 分;allowHalf=true 时点某颗星的左半取 N-0.5 分(规则见规格 §36.5)。
触屏上没有鼠标悬停预览,所以「已选中的部分」靠填充比例表达(半星 = 左半填充),
不能只靠颜色深浅;星形本体视觉 24px,热区撑到 44px 高。
readonly=true 时是纯展示(用 role=&quot;img&quot; + aria-label 播报「N 分(满分 M 分)」),
此时不渲染任何可聚焦控件 —— 列表里一行一个评分不该抢走键盘序列。 */
import { computed } from 'vue';
const props = defineProps({
value: { type: Number, default: 0 },
max: { type: Number, default: 5 },
allowHalf: { type: Boolean, default: false },
size: { type: String, default: 'default' },
readonly: { type: Boolean, default: false },
disabled: { type: Boolean, default: false },
label: { type: String, default: '评分' }
});
const emit = defineEmits(['change']);
const starIndexes = computed(() =&gt; Array.from({ length: props.max }, (_, i) =&gt; i));
const rateClass = computed(() =&gt; [
props.allowHalf ? 'kole-m-rate--half' : '',
props.size === 'small' ? 'kole-m-rate--small' : '',
props.readonly ? 'kole-m-rate--readonly' : '',
props.disabled ? 'is-disabled' : ''
].filter(Boolean));
function ratioOf(i) {
return Math.max(0, Math.min(1, props.value - i));
}
function pick(i, e) {
if (props.readonly || props.disabled) return;
/* 半星判定:点在左半区取 N-0.5,右半区取 N(整星模式下位置不影响取值) */
const el = e.target &amp;&amp; e.target.getAttribute ? e.target : null;
const isLeftHalf = props.allowHalf &amp;&amp; el &amp;&amp; el.getAttribute('data-half') === 'left';
const index = i + 1;
emit('change', isLeftHalf ? index - 0.5 : index);
}
function onKeyDown(e) {
if (props.readonly || props.disabled) return;
const delta = e.key === 'ArrowLeft' || e.key === 'ArrowDown' ? -1 : e.key === 'ArrowRight' || e.key === 'ArrowUp' ? 1 : 0;
if (!delta) return;
e.preventDefault();
const stepValue = props.allowHalf ? 0.5 : 1;
const min = props.allowHalf ? 0.5 : 1;
const next = Math.round((props.value + delta * stepValue) * 2) / 2;
emit('change', Math.max(min, Math.min(props.max, next)));
}
&lt;/script&gt;
&lt;style src=&quot;./Rate.css&quot;&gt;&lt;/style&gt;
</code></pre>
</div>
</details>
<details class="m-details">
<summary>frameworks-mobile/Rate.uniapp.vue · uni-app(跨端:小程序 / App / H5) · 199 行</summary>
<div class="m-code">
<div class="m-code-head"><span>frameworks-mobile/Rate.uniapp.vue</span><button class="m-copy" type="button" data-copy="code-210">复制</button></div>
<pre id="code-210"><code>&lt;template&gt;
&lt;!-- 只读形态:整组是一个 role=&quot;img&quot;,名称由 aria-label 播报(不留下可聚焦的星) --&gt;
&lt;view
v-if=&quot;readonly&quot;
class=&quot;kole-m-rate&quot;
:class=&quot;rateClass&quot;
role=&quot;img&quot;
:aria-label=&quot;label + ' ' + value + ' 分(满分 ' + max + ' 分)'&quot;
&gt;
&lt;view class=&quot;kole-m-rate__stars&quot;&gt;
&lt;view v-for=&quot;(i, k) in starIndexes&quot; :key=&quot;k&quot; class=&quot;kole-m-rate__star&quot;&gt;
&lt;view class=&quot;kole-m-rate__glyph&quot;&gt;
&lt;text class=&quot;kole-m-rate__base&quot;&gt;★&lt;/text&gt;
&lt;text class=&quot;kole-m-rate__fill&quot; :style=&quot;{ width: ratioOf(i) * 100 + '%' }&quot;&gt;★&lt;/text&gt;
&lt;/view&gt;
&lt;/view&gt;
&lt;/view&gt;
&lt;slot&gt;
&lt;text class=&quot;kole-m-rate__text&quot;&gt;{{ value }} 分&lt;/text&gt;
&lt;/slot&gt;
&lt;/view&gt;
&lt;view
v-else
class=&quot;kole-m-rate&quot;
:class=&quot;rateClass&quot;
role=&quot;radiogroup&quot;
:aria-label=&quot;label&quot;
:aria-disabled=&quot;disabled ? 'true' : 'false'&quot;
&gt;
&lt;view class=&quot;kole-m-rate__stars&quot;&gt;
&lt;view
v-for=&quot;(i, k) in starIndexes&quot;
:key=&quot;k&quot;
class=&quot;kole-m-rate__star&quot;
:role=&quot;disabled ? '' : 'radio'&quot;
:aria-checked=&quot;ratioOf(i) &gt;= 1 ? 'true' : 'false'&quot;
:aria-label=&quot;i + 1 + ' 星'&quot;
:aria-disabled=&quot;disabled ? 'true' : 'false'&quot;
@tap=&quot;pick(i, $event)&quot;
&gt;
&lt;view class=&quot;kole-m-rate__glyph&quot;&gt;
&lt;text class=&quot;kole-m-rate__base&quot;&gt;★&lt;/text&gt;
&lt;text class=&quot;kole-m-rate__fill&quot; :style=&quot;{ width: ratioOf(i) * 100 + '%' }&quot;&gt;★&lt;/text&gt;
&lt;/view&gt;
&lt;template v-if=&quot;allowHalf&quot;&gt;
&lt;!-- uni 端取不到 DOM 的 e.target,半星靠两个分区各自挂处理器(左半取 N-0.5) --&gt;
&lt;view class=&quot;kole-m-rate__half kole-m-rate__half--left&quot; @tap.stop=&quot;pickLeft(i)&quot;&gt;&lt;/view&gt;
&lt;view class=&quot;kole-m-rate__half kole-m-rate__half--right&quot; @tap.stop=&quot;pick(i)&quot;&gt;&lt;/view&gt;
&lt;/template&gt;
&lt;/view&gt;
&lt;/view&gt;
&lt;slot&gt;
&lt;text class=&quot;kole-m-rate__text&quot;&gt;{{ value }} 分&lt;/text&gt;
&lt;/slot&gt;
&lt;/view&gt;
&lt;/template&gt;
&lt;script setup&gt;
/* uni-app 端 · 评分(移动端)— 规格 §36
跨端差异:
① 星用 view + role=&quot;radio&quot;(小程序没有可聚焦的原生 button 语义差异),点击用 @tap;
② 半星判定取不到 DOM 的 e.target,改用 @tap 在左右两个半区视图上的**各自处理器**:
左半区视图自己发 tap 就取 N-0.5,其余一律取 N(这是跨端下唯一可靠的分区方式);
③ 填充比例用内联 width 的百分比(与 H5 同一表达:灰底星 + 品牌色覆盖层);
④ 只读形态不渲染任何可点区域,整组一个 role=&quot;img&quot;。
尺寸用 rpx:88rpx = 375pt 下的 44px 触控最小边长,星形 48rpx = 24px。 */
import { computed } from 'vue';
const props = defineProps({
value: { type: Number, default: 0 },
max: { type: Number, default: 5 },
allowHalf: { type: Boolean, default: false },
size: { type: String, default: 'default' },
readonly: { type: Boolean, default: false },
disabled: { type: Boolean, default: false },
label: { type: String, default: '评分' }
});
const emit = defineEmits(['change']);
const starIndexes = computed(() =&gt; Array.from({ length: props.max }, (_, i) =&gt; i));
const rateClass = computed(() =&gt; [
props.allowHalf ? 'kole-m-rate--half' : '',
props.size === 'small' ? 'kole-m-rate--small' : '',
props.readonly ? 'kole-m-rate--readonly' : '',
props.disabled ? 'is-disabled' : ''
].filter(Boolean));
function ratioOf(i) {
return Math.max(0, Math.min(1, props.value - i));
}
/* 星本体被点时取整星(半区视图有自己的处理器,命中它时不会走到这里) */
function pick(i) {
if (props.readonly || props.disabled) return;
emit('change', i + 1);
}
/* 左半区:取 N-0.5(仅 allowHalf) */
function pickLeft(i) {
if (props.readonly || props.disabled || !props.allowHalf) return;
emit('change', i + 1 - 0.5);
}
&lt;/script&gt;
&lt;style&gt;
.kole-m-rate {
--kole-m-rate-star: 48rpx; /* 星形字号(= 视觉边长,24px @375pt) */
--kole-m-rate-gap: 16rpx; /* 星与星之间的间距 */
--kole-m-touch-target: 88rpx;
--kole-m-font-size-label: 28rpx;
--kole-m-gutter: 32rpx;
box-sizing: border-box;
display: flex;
align-items: center;
width: 100%;
min-height: var(--kole-m-touch-target);
padding-left: var(--kole-m-gutter);
padding-right: var(--kole-m-gutter);
background-color: var(--kole-color-card-bg);
color: var(--kole-color-text-body);
font-size: 32rpx;
}
/* 变体 size=small:紧凑(列表里展示已有评分,配 readonly) */
.kole-m-rate--small { --kole-m-rate-star: 36rpx; }
.kole-m-rate__stars {
flex-shrink: 0;
display: flex;
align-items: center;
}
/* 每颗星撑到 88rpx 高(热区),星形本体只占中间 48rpx */
.kole-m-rate__star {
position: relative;
display: flex;
align-items: center;
justify-content: center;
min-height: var(--kole-m-touch-target);
padding-left: 8rpx;
padding-right: 8rpx;
}
/* 星形本体:灰底 + 品牌色覆盖层(覆盖层宽度 = 填充比例,表达半星) */
.kole-m-rate__glyph {
position: relative;
display: flex;
align-items: center;
font-size: var(--kole-m-rate-star);
line-height: 1;
}
.kole-m-rate__base { color: var(--kole-color-icon-inactive); }
.kole-m-rate__fill {
position: absolute;
top: 0;
left: 0;
overflow: hidden;
white-space: nowrap;
color: var(--kole-color-brand);
}
/* 半星的点击分区:盖在星形本体左右各一半上(仅 allowHalf 时出现) */
.kole-m-rate__half {
display: none;
position: absolute;
top: 0;
bottom: 0;
width: 50%;
}
.kole-m-rate--half .kole-m-rate__half { display: block; }
.kole-m-rate__half--left { left: 0; }
.kole-m-rate__half--right { right: 0; }
.kole-m-rate__text {
flex: 1;
padding-left: 24rpx;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
color: var(--kole-color-text-secondary);
font-size: var(--kole-m-font-size-label);
}
/* 变体 readonly=true:只读展示(无半星分区、无按下反馈) */
.kole-m-rate--readonly .kole-m-rate__half { display: none; }
/* 状态 disabled:整条置灰 */
.kole-m-rate.is-disabled .kole-m-rate__base,
.kole-m-rate.is-disabled .kole-m-rate__fill { color: var(--kole-color-text-disabled); }
.kole-m-rate.is-disabled .kole-m-rate__text { 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">断言 17 条 · 全部通过</span>
<span class="m-status">报告 2026-09-20 16:50:33</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-rate.json(点击展开原始 JSON)</summary>
<div class="m-code"><pre><code>{
"schemaVersion": 1,
"sourceKind": "authored-spec",
"provenance": "authored-in-repo",
"specFile": "spec/移动端规格.md",
"specSection": "36 · 评分 Rate",
"confidence": "high",
"slug": "mobile-rate",
"name": "评分 Rate",
"semanticTypeCandidates": [
"rate",
"star-rating",
"score-input"
],
"variantDimensions": [
{
"name": "size",
"values": [
"default",
"small"
]
},
{
"name": "allowHalf",
"values": [
"false",
"true"
]
},
{
"name": "readonly",
"values": [
"false",
"true"
]
}
],
"representativeVariants": [
{
"size": "default",
"allowHalf": "false",
"readonly": "false",
"label": "默认(整星可评分,星形 24px)"
},
{
"size": "default",
"allowHalf": "true",
"readonly": "false",
"label": "支持半星(点左半取 N-0.5 分)"
},
{
"size": "small",
"allowHalf": "false",
"readonly": "true",
"label": "行内只读展示(星形 18px,不占键盘序列)"
}
],
"anatomy": {
"rate": "根元素,一行里放进「星组 + 数值文案」",
"stars": "星组,横向排列,只负责布局",
"star": "单颗星,可点区域(原生 button),自身撑满 44px 高",
"glyph": "星形本体(视觉 24px),由灰底星 + 品牌色覆盖层叠成",
"fill": "覆盖层,宽度即该颗星的填充比例(100% 整星 / 50% 半星 / 0% 未选)",
"text": "数值文案,默认「N 分」,可由默认插槽替换"
},
"structurePatterns": {
"size": "default(星形 24px)/ small(星形 18px,行内展示用)",
"allowHalf": "false(只能取整星)/ true(允许半星)",
"readonly": "false(可评分)/ true(只读展示已有评分)"
},
"usageHints": [
"让用户对一次体验给出星级评价(商品、物流、服务),或只读展示已有的平均分",
"触屏上没有悬停预览:桌面上鼠标划过就能预告「点下去会是几分」,触屏上这个预告不存在",
"填充比例(含半星)必须直接可读,且星形本体只有 24px、热区要补到 44px 高",
"点第 N 颗星取 N 分;allowHalf=true 时点第 N 颗星的左半取 N-0.5 分、右半取 N 分",
"取值后立即触发 change 事件(回传 3.5 这类半星值也是合法输入)"
],
"doNotInvent": [
"评分的业务含义映射(如「4 分以上算好评」)与统计口径",
"拖动选分与悬停预览(触屏没有悬停,拖动容易滑错)",
"评分理由 / 标签的联动采集(由宿主另行组合)",
"异步提交与失败回滚(宿主负责)"
],
"unknowns": [
"分值是否允许与文案一一对应(如 1 分「很差」、5 分「很好」)",
"星形换用图标字体或 SVG 后填充比例的表达是否仍然一致",
"只读形态是否要显示评价条数(当前由宿主用插槽补)"
],
"interaction": [
"**取值规则**:点第 N 颗星取 N 分;allowHalf=true 时点第 N 颗星的**左半**取 N-0.5 分、**右半**取 N 分(半星只在开启该项时存在,默认整星)",
"星形本体视觉 24px(size=small 时 18px),但每颗星的可点区域高度是 44px;横向不做死区,相邻星的边界就是两半分界",
"一次触摸即取值,不需要二次确认;不响应长按与拖动(拖动选分在触屏上容易滑错,规格未纳入)",
"已选中的部分用**填充比例**表达(半星就是左半填充),不能只靠颜色深浅区分",
"取值后立即触发 change 事件(回传 3.5 这类半星值也是合法输入)",
"readonly=true 时不渲染任何可点区域(只读展示不抢键盘序列)"
],
"accessibility": [
"可评分形态:根是 role=\"radiogroup\" + aria-label,每颗星是原生 button + role=\"radio\" + aria-checked",
"星形的名称是「N 星」(aria-label),读屏播报的是分值而不是符号",
"只读形态:整组是一个 role=\"img\" + aria-label(「评分 4.5 分(满分 5 分)」),组内星形 aria-hidden",
"禁用态用原生 disabled 并补 aria-disabled=\"true\"",
"键盘:聚焦后左右方向键步进(整星模式步长 1,半星模式步长 0.5)"
],
"api": {
"source": "implementation",
"note": "props / events / slots 为 6 端实现的公共接口(说明文字取自规格对应小节)。字段名与各端源码逐名核对:node tools/verify-mobile-docs.mjs",
"requiredNote": "「必传」按严格定义:实现里**没有默认值**时才为 Y(本门禁逐条核对 props 与各端源码的默认值,防止契约与实现脱节)。",
"props": [
{
"name": "value",
"type": "number",
"default": "0",
"desc": "受控分值,允许半星(3.5)与 0(未评分)(规格 §36.5)",
"required": false
},
{
"name": "max",
"type": "number",
"default": "5",
"desc": "满分星数,决定渲染几颗星(规格 §36.2 stars)",
"required": false
},
{
"name": "allowHalf",
"type": "boolean",
"default": "false",
"desc": "变体 allowHalf:是否允许半星(点左半取 N-0.5 分)(规格 §36.3)",
"required": false
},
{
"name": "size",
"type": "'default' | 'small'",
"default": "'default'",
"desc": "变体 size:星形 24px 还是 18px(行内展示用)(规格 §36.3)",
"required": false
},
{
"name": "readonly",
"type": "boolean",
"default": "false",
"desc": "变体 readonly:只读展示(不渲染可点区域,整组用 role=\"img\" 播报)(规格 §36.3)",
"required": false
},
{
"name": "disabled",
"type": "boolean",
"default": "false",
"desc": "状态 disabled:置灰且不可聚焦,点击不改值(规格 §36.4)",
"required": false
},
{
"name": "label",
"type": "string",
"default": "'评分'",
"desc": "无障碍名称,落到 radiogroup / img 的 aria-label(规格 §36.6)",
"required": false
}
],
"events": [
{
"name": "change",
"params": "(value)",
"desc": "点星或键盘步进改值时触发,回传新分值(可含 0.5)(规格 §36.5)"
}
],
"slots": [
{
"name": "default",
"desc": "数值文案位置的自定义内容(如「4.5 分 · 共 128 条评价」),替换默认的「N 分」(规格 §36.2 text)"
}
]
},
"variantClasses": {
"size": {
"default": [],
"small": [
".kole-m-rate--small"
]
},
"allowHalf": {
"false": [],
"true": [
".kole-m-rate--half",
".kole-m-rate__half"
]
},
"readonly": {
"false": [],
"true": [
".kole-m-rate--readonly"
]
}
},
"demos": [
{
"id": "basic",
"group": "01 组件类型",
"title": "基础用法",
"desc": "点第 N 颗即取 N 分;整行 44px 高,星形本体只有 24px。",
"variant": "allowHalf=false"
},
{
"id": "half",
"group": "01 组件类型",
"title": "半星",
"desc": "allowHalf=true:点某颗星的左半取 N-0.5 分、右半取 N 分。",
"variant": "allowHalf=true"
},
{
"id": "size",
"group": "01 组件类型",
"title": "尺寸两档",
"desc": "size=small 星形 18px 用于行内展示;default 24px 用于可评分场景。",
"variant": "size=default|small"
},
{
"id": "readonly",
"group": "02 组件状态",
"title": "只读展示",
"desc": "readonly=true:星形不再是按钮、点击不改值,整组用 role=\"img\" 播报分值。",
"variant": "readonly=true"
},
{
"id": "disabled",
"group": "02 组件状态",
"title": "禁用",
"desc": "整条置灰且不可聚焦:读屏会播报不可用,点击不改值。",
"variant": "disabled=true"
}
],
"related": [
{
"slug": "mobile-slider",
"why": "连续区间的粗选用 Slider;离散档位(1~5 星)且带语义的用 Rate"
},
{
"slug": "mobile-form",
"why": "评分作为表单里的一个字段时,标签、必填星号与错误提示由 Form 的 item 提供"
},
{
"slug": "mobile-tag",
"why": "只是标注一个既有结论(如「好评」「差评」)用 Tag;需要用户给出分值时用 Rate"
}
]
}</code></pre></div>
</details>
</section>
<footer class="m-foot">
<p>生成物:本页由 <code>node tools/build-mobile.mjs</code> 从契约 <code>components/mobile-rate.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>