Regression / regression (push) Canceled after 0s
## 品牌标识(本次会话) 起因:品牌此前没有任何图形标识 —— 唯一 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 未做部分)
1787 lines
86 KiB
HTML
1787 lines
86 KiB
HTML
<!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>搜索框 Search — Kole UI Mobile</title>
|
||
<meta name="description" content="搜索框 Search:移动端组件(6 端实现:CSS / H5 原生 / React / Vue 2 / Vue 3 / uni-app)。与 PC 端物理隔离:类名 kole-m-、令牌 --kole-m-。规格来源:移动端规格 28 · 搜索框 Search。">
|
||
<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 is-active" href="mobile-search.html" aria-current="page">搜索框<em>Search</em></a>
|
||
<a class="m-side-link" href="mobile-stepper.html">步进器<em>Stepper</em></a>
|
||
<a class="m-side-link" href="mobile-switch.html">开关<em>Switch</em></a>
|
||
<a class="m-side-link" href="mobile-textarea.html">多行文本框<em>Textarea</em></a>
|
||
<a class="m-side-link" href="mobile-checkbox.html">多选框<em>Checkbox</em></a>
|
||
<a class="m-side-link" href="mobile-form.html">表单<em>Form</em></a>
|
||
<a class="m-side-link" href="mobile-radio.html">单选框<em>Radio</em></a>
|
||
<a class="m-side-link" href="mobile-rate.html">评分<em>Rate</em></a>
|
||
<a class="m-side-link" href="mobile-slider.html">滑动选择器<em>Slider</em></a>
|
||
<a class="m-side-link" href="mobile-cascader.html">级联选择器<em>Cascader</em></a>
|
||
<a class="m-side-link" href="mobile-colorpicker.html">颜色选择器<em>ColorPicker</em></a>
|
||
<a class="m-side-link" href="mobile-picker.html">选择器<em>Picker</em></a>
|
||
<a class="m-side-link" href="mobile-upload.html">上传<em>Upload</em></a>
|
||
<div class="m-side-group"><span>数据展示</span><span class="cnt">8</span></div>
|
||
<a class="m-side-link" href="cell.html">单元格<em>Cell</em></a>
|
||
<a class="m-side-link" href="mobile-badge.html">徽标<em>Badge</em></a>
|
||
<a class="m-side-link" href="mobile-tag.html">标签<em>Tag</em></a>
|
||
<a class="m-side-link" href="mobile-avatar.html">头像<em>Avatar</em></a>
|
||
<a class="m-side-link" href="mobile-list.html">列表<em>List</em></a>
|
||
<a class="m-side-link" href="mobile-collapse.html">折叠面板<em>Collapse</em></a>
|
||
<a class="m-side-link" href="mobile-table.html">表格<em>Table</em></a>
|
||
<a class="m-side-link" href="mobile-typography.html">排版<em>Typography</em></a>
|
||
<div class="m-side-group"><span>反馈</span><span class="cnt">12</span></div>
|
||
<a class="m-side-link" href="actionsheet.html">动作面板<em>ActionSheet</em></a>
|
||
<a class="m-side-link" href="pullrefresh.html">下拉刷新<em>PullRefresh</em></a>
|
||
<a class="m-side-link" href="swipecell.html">滑动单元格<em>SwipeCell</em></a>
|
||
<a class="m-side-link" href="mobile-popup.html">弹出层<em>Popup</em></a>
|
||
<a class="m-side-link" href="mobile-toast.html">轻提示<em>Toast</em></a>
|
||
<a class="m-side-link" href="mobile-dialog.html">对话框<em>Dialog</em></a>
|
||
<a class="m-side-link" href="mobile-noticebar.html">通知栏<em>NoticeBar</em></a>
|
||
<a class="m-side-link" href="mobile-loading.html">加载<em>Loading</em></a>
|
||
<a class="m-side-link" href="mobile-progress.html">进度条<em>Progress</em></a>
|
||
<a class="m-side-link" 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;">Search</span></h1>
|
||
<p>用关键词从长列表里取回一小段结果</p>
|
||
<p style="margin-top: 8px;" class="m-chips">
|
||
<span class="m-chip m">数据录入</span>
|
||
<span class="m-chip">规格 28 · 搜索框 Search</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><!-- ① 令牌:PC 令牌 + 移动端 --kole-m-* 合成单文件,引一次 -->
|
||
<link rel="stylesheet" href="kole-ui/mobile/tokens.css">
|
||
|
||
<!-- ② 本组件样式(全量则用 kole-ui/mobile/components/index.css) -->
|
||
<link rel="stylesheet" href="kole-ui/mobile/components/mobile-search.css">
|
||
|
||
<!-- ③ 结构照抄下方任一演示块(类名与 6 端实现一致) --></code></pre>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="m-block">
|
||
<h2 id="demo">演示</h2>
|
||
<p class="m-sub">每个演示都是真实渲染:预览帧加载 <code>frameworks-mobile/Search.html?demo=<id></code>(只显示该演示块),代码是该演示块在演示页里的原文,可复制。全部演示同屏可看 <a href="../../../frameworks-mobile/Search.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">round=true</span></div>
|
||
<p class="m-demo-desc">页面顶部一行:放大镜 + 输入区,输入即过滤(不等回车)。</p>
|
||
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Search.html?demo=basic" title="搜索框 Search · 基础用法" loading="lazy"></iframe></div>
|
||
<details class="m-details"><summary>查看代码(演示页原文 · 13 行)</summary>
|
||
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Search.html · basic</span><button class="m-copy" type="button" data-copy="code-demo-1">复制</button></div>
|
||
<pre id="code-demo-1"><code><section class="demo-block" data-demo="basic">
|
||
<p class="demo-label">基础用法(页面顶部一行:放大镜 + 输入区,输入即过滤,不等回车)</p>
|
||
<div class="demo-box">
|
||
<div class="kole-m-search is-filled" data-assert="search-basic">
|
||
<div class="kole-m-search__form">
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input class="kole-m-search__control" type="search" value="无线耳机" placeholder="搜索商品" aria-label="搜索商品">
|
||
</label>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section></code></pre></div>
|
||
</details>
|
||
</div>
|
||
<div class="m-demo" id="demo-cancel">
|
||
<div class="m-demo-head"><span class="m-demo-title">带取消</span><span class="m-chip">showCancel=true</span></div>
|
||
<p class="m-demo-desc">showCancel=true:触屏没有 Esc 键,退出搜索需要一个明确的文字动作。</p>
|
||
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Search.html?demo=cancel" title="搜索框 Search · 带取消" loading="lazy"></iframe></div>
|
||
<details class="m-details"><summary>查看代码(演示页原文 · 15 行)</summary>
|
||
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Search.html · cancel</span><button class="m-copy" type="button" data-copy="code-demo-2">复制</button></div>
|
||
<pre id="code-demo-2"><code><section class="demo-block" data-demo="cancel">
|
||
<p class="demo-label">带取消(showCancel:触屏没有 Esc 键,退出搜索要有一个明确动作)</p>
|
||
<div class="demo-box">
|
||
<div class="kole-m-search is-filled is-cancelable" id="sc-cancel-root" data-assert="search-cancel">
|
||
<div class="kole-m-search__form">
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input class="kole-m-search__control" type="search" value="订单" placeholder="搜索订单" aria-label="搜索订单" id="sc-cancel-field">
|
||
</label>
|
||
</div>
|
||
<button class="kole-m-search__cancel" type="button" id="sc-cancel"
|
||
data-behavior="click-toggles-class:#sc-cancel-root|is-filled">取消</button>
|
||
</div>
|
||
</div>
|
||
</section></code></pre></div>
|
||
</details>
|
||
</div>
|
||
<div class="m-demo" id="demo-round">
|
||
<div class="m-demo-head"><span class="m-demo-title">圆角两态</span><span class="m-chip">round=true|false</span></div>
|
||
<p class="m-demo-desc">round=true 胶囊形用于页面顶部;round=false 方角嵌在卡片或工具栏里。</p>
|
||
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Search.html?demo=round" title="搜索框 Search · 圆角两态" loading="lazy"></iframe></div>
|
||
<details class="m-details"><summary>查看代码(演示页原文 · 24 行)</summary>
|
||
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Search.html · round</span><button class="m-copy" type="button" data-copy="code-demo-3">复制</button></div>
|
||
<pre id="code-demo-3"><code><section class="demo-block" data-demo="round">
|
||
<p class="demo-label">圆角两态(round=true 胶囊形用于页面顶部 / round=false 方角嵌在卡片或工具栏里)</p>
|
||
<div class="demo-box">
|
||
<div class="demo-stack" data-assert="search-round">
|
||
<div class="kole-m-search kole-m-search--round is-cancelable">
|
||
<div class="kole-m-search__form">
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input class="kole-m-search__control" type="search" placeholder="圆角(胶囊,顶部常用)" aria-label="圆角搜索">
|
||
</label>
|
||
</div>
|
||
<button class="kole-m-search__cancel" type="button">取消</button>
|
||
</div>
|
||
<div class="kole-m-search">
|
||
<div class="kole-m-search__form">
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input class="kole-m-search__control" type="search" placeholder="方角(嵌在卡片里)" aria-label="方角搜索">
|
||
</label>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section></code></pre></div>
|
||
</details>
|
||
</div>
|
||
<div class="m-demo" id="demo-clear">
|
||
<div class="m-demo-head"><span class="m-demo-title">清除</span><span class="m-chip">clearable=true</span></div>
|
||
<p class="m-demo-desc">有值时清除按钮才出现;点它清空并把焦点留在输入框。</p>
|
||
<div class="m-demo-stage"><iframe src="../../../frameworks-mobile/Search.html?demo=clear" title="搜索框 Search · 清除" loading="lazy"></iframe></div>
|
||
<details class="m-details"><summary>查看代码(演示页原文 · 15 行)</summary>
|
||
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Search.html · clear</span><button class="m-copy" type="button" data-copy="code-demo-4">复制</button></div>
|
||
<pre id="code-demo-4"><code><section class="demo-block" data-demo="clear">
|
||
<p class="demo-label">清除(有值时清除按钮才出现;点它清空并把焦点留在输入框)</p>
|
||
<div class="demo-box">
|
||
<div class="kole-m-search is-filled" id="sc-clearable" data-assert="search-clear">
|
||
<div class="kole-m-search__form">
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input class="kole-m-search__control" type="search" value="蓝牙" placeholder="搜索商品" aria-label="搜索商品" id="sc-clearable-field">
|
||
</label>
|
||
<button class="kole-m-search__clear" type="button" aria-label="清除" id="sc-clearable-btn"
|
||
data-behavior="click-toggles-class:#sc-clearable|is-filled">✕</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section></code></pre></div>
|
||
</details>
|
||
</div>
|
||
<h3 class="m-demo-group">02 组件状态</h3>
|
||
<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/Search.html?demo=disabled" title="搜索框 Search · 禁用" loading="lazy"></iframe></div>
|
||
<details class="m-details"><summary>查看代码(演示页原文 · 13 行)</summary>
|
||
<div class="m-code"><div class="m-code-head"><span>frameworks-mobile/Search.html · disabled</span><button class="m-copy" type="button" data-copy="code-demo-5">复制</button></div>
|
||
<pre id="code-demo-5"><code><section class="demo-block" data-demo="disabled">
|
||
<p class="demo-label">禁用(置灰且不可聚焦,键盘与读屏都会跳过)</p>
|
||
<div class="demo-box">
|
||
<div class="kole-m-search is-disabled" data-assert="search-disabled">
|
||
<div class="kole-m-search__form">
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input class="kole-m-search__control" type="search" value="暂不可用" placeholder="搜索" aria-label="搜索" disabled>
|
||
</label>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section></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>string</code></td><td><code>''</code></td><td>受控关键词;有值时清除按钮才出现(规格 §28.5)</td><td>N</td></tr>
|
||
<tr><td><code>placeholder</code></td><td><code>string</code></td><td><code>''</code></td><td>占位文字,提示搜索范围(如「搜索商品」)(规格 §28.2 control)</td><td>N</td></tr>
|
||
<tr><td><code>round</code></td><td><code>boolean</code></td><td><code>true</code></td><td>变体 round:true 胶囊形,false 方角(规格 §28.3)</td><td>N</td></tr>
|
||
<tr><td><code>showCancel</code></td><td><code>boolean</code></td><td><code>false</code></td><td>变体 showCancel:右侧是否出现取消动作(规格 §28.3)</td><td>N</td></tr>
|
||
<tr><td><code>clearable</code></td><td><code>boolean</code></td><td><code>true</code></td><td>有值时是否允许清除(规格 §28.5)</td><td>N</td></tr>
|
||
<tr><td><code>disabled</code></td><td><code>boolean</code></td><td><code>false</code></td><td>状态 disabled:置灰且不可聚焦(规格 §28.4)</td><td>N</td></tr>
|
||
<tr><td><code>cancelText</code></td><td><code>string</code></td><td><code>'取消'</code></td><td>取消动作文案;不用图标代替文字(规格 §28.6)</td><td>N</td></tr>
|
||
<tr><td><code>label</code></td><td><code>string</code></td><td><code>'搜索'</code></td><td>无障碍名称,落到 aria-label(规格 §28.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>input</code></td><td><code>(value)</code></td><td>输入即触发,不等回车(规格 §28.5)</td></tr>
|
||
<tr><td><code>search</code></td><td><code>(value)</code></td><td>键盘「搜索」键触发(规格 §28.5)</td></tr>
|
||
<tr><td><code>clear</code></td><td><code>—</code></td><td>点击清除按钮触发,值由宿主置空(规格 §28.5)</td></tr>
|
||
<tr><td><code>cancel</code></td><td><code>—</code></td><td>点击取消动作触发,由宿主退出搜索态(规格 §28.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>根元素内的追加内容(如右侧的筛选入口)(规格 §28.2 search)</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-search-height</code></td><td><code>var(--kole-m-touch-target)</code></td><td>搜索框高度(≥ 44px 触控最小边长)</td></tr>
|
||
<tr><td><code>--kole-m-search-radius</code></td><td><code>var(--kole-radius-base)</code></td><td>round=false 时的圆角</td></tr>
|
||
<tr><td><code>--kole-m-search-icon-size</code></td><td><code>14px</code></td><td>放大镜视觉尺寸</td></tr>
|
||
</tbody>
|
||
</table>
|
||
</section>
|
||
|
||
<section class="m-block">
|
||
<h2 id="usage">何时使用</h2>
|
||
<ul>
|
||
<li>用关键词从长列表里取回一小段结果</li>
|
||
<li>移动端的搜索框几乎总是页面顶部的独立一行</li>
|
||
<li>输入即过滤(不等回车)</li>
|
||
<li>触屏没有 Esc 键,用户清空关键词后仍需一键回到列表,因此要有明确的取消动作</li>
|
||
<li>组件不发请求、不做防抖:只回传关键词,节流策略由宿主决定</li>
|
||
</ul>
|
||
</section>
|
||
|
||
<section class="m-block">
|
||
<h2 id="interaction">交互与触控</h2>
|
||
<ul>
|
||
<li>搜索框高度不小于 44px,取消动作热区不小于 44px</li>
|
||
<li>输入即触发 input 事件(不等回车);键盘「搜索」键触发 search 事件</li>
|
||
<li>清除按钮只在有值时出现,点击清空并把焦点留在输入框</li>
|
||
<li>清除与取消都是 44px 热区;两者同时出现时先清除、再取消(自右向左层级递进)</li>
|
||
</ul>
|
||
</section>
|
||
|
||
<section class="m-block">
|
||
<h2 id="a11y">无障碍</h2>
|
||
<ul>
|
||
<li>输入框用原生 input type="search"(iOS 键盘右下角键位变成「搜索」)</li>
|
||
<li>搜索图标是装饰性的,置 aria-hidden="true",名称由 aria-label 给出</li>
|
||
<li>清除按钮是原生 button 且带 aria-label="清除";取消动作是原生 button</li>
|
||
<li>取消按钮不用图标代替文字(触屏上文字比图标更好点)</li>
|
||
</ul>
|
||
</section>
|
||
|
||
<section class="m-block">
|
||
<h2 id="related">相似组件</h2>
|
||
<p class="m-sub">从「该用哪一个」的角度区分;PC 端的对应实现见 <a href="../../index.html">PC 文档站</a>。</p>
|
||
<table class="m-table">
|
||
<thead><tr><th>组件</th><th>何时用它而不是本组件</th></tr></thead>
|
||
<tbody>
|
||
<tr><td><a href="mobile-input.html">输入框</a><em style="font-family: var(--kole-font-family-num); font-style: normal; font-size: 11px; color: var(--kole-color-text-placeholder); margin-left: 6px;">Input</em></td><td>收集填写内容用输入框;目的就是从列表里取回结果时才用搜索框</td></tr>
|
||
<tr><td><a href="cell.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;">Cell</em></td><td>「搜索入口」只做跳转时用单元格,点开才是真搜索页</td></tr>
|
||
<tr><td><a href="mobile-list.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;">List</em></td><td>搜索结果用列表承载;搜索框只负责取关键词</td></tr>
|
||
</tbody>
|
||
</table>
|
||
</section>
|
||
|
||
<section class="m-block">
|
||
<h2 id="gaps">规格未定 / 禁止发明</h2>
|
||
<table class="m-table">
|
||
<thead><tr><th>类别</th><th>条目</th></tr></thead>
|
||
<tbody>
|
||
<tr><td><span class="m-chip">禁止发明</span></td><td>搜索的防抖时值与接口节流策略(由宿主决定)</td></tr>
|
||
<tr><td><span class="m-chip">禁止发明</span></td><td>搜索历史的存储与展示</td></tr>
|
||
<tr><td><span class="m-chip">禁止发明</span></td><td>搜索结果的高亮规则</td></tr>
|
||
<tr><td><span class="m-chip">规格未定</span></td><td>取消文案是否允许替换(如「返回」)</td></tr>
|
||
<tr><td><span class="m-chip">规格未定</span></td><td>是否需要自动聚焦并拉起键盘</td></tr>
|
||
<tr><td><span class="m-chip">规格未定</span></td><td>语音/扫码等扩展入口是否放进框内</td></tr>
|
||
</tbody>
|
||
</table>
|
||
</section>
|
||
|
||
<section class="m-block">
|
||
<h2 id="anatomy">结构(anatomy)</h2>
|
||
<table class="m-table">
|
||
<thead><tr><th>字段</th><th>说明</th></tr></thead>
|
||
<tbody>
|
||
<tr><td><code>search</code></td><td>根元素,一行里放进「搜索框 + 取消动作」</td></tr>
|
||
<tr><td><code>icon</code></td><td>框内左侧放大镜,纯装饰(不承载语义,读屏由 label 承担)</td></tr>
|
||
<tr><td><code>control</code></td><td>原生 input type="search",占满剩余宽度</td></tr>
|
||
<tr><td><code>clear</code></td><td>可选清除按钮,有值且清除可用时出现在图标与取消之间</td></tr>
|
||
<tr><td><code>cancel</code></td><td>可选取消动作,默认文案「取消」,由 showCancel 控制显隐</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>round</code></td><td>true / false</td><td><div><b>true</b> <span class="m-cls">.kole-m-search--round</span></div><div><b>false</b> <span class="m-none">(由数据驱动,无专属类)</span></div></td></tr>
|
||
<tr><td><code>showCancel</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-search__cancel</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>round=true · showCancel=true</code></td><td>胶囊形 + 取消(页面顶部常用)</td></tr>
|
||
<tr><td><code>round=false · showCancel=false</code></td><td>方角无取消(嵌在卡片或工具栏里)</td></tr>
|
||
<tr><td><code>round=true · showCancel=false</code></td><td>胶囊形无取消</td></tr>
|
||
</tbody>
|
||
</table>
|
||
</section>
|
||
|
||
<section class="m-block">
|
||
<h2 id="tokens">用到的令牌</h2>
|
||
<p class="m-sub">构建时从本组件样式表扫描得出。蓝色为移动端自有令牌,绿色为继承的 PC 令牌(改一处两端生效)。</p>
|
||
<div class="m-chips">
|
||
<span class="m-chip m" title="正文 / 列表项">--kole-m-font-size-body</span>
|
||
<span class="m-chip m" title="次级说明">--kole-m-font-size-label</span>
|
||
<span class="m-chip m" title="可点区域最小边长">--kole-m-touch-target</span>
|
||
<span class="m-chip inherit" title="分割线/边框">--kole-color-border</span>
|
||
<span class="m-chip inherit" title="品牌主色:主按钮、选中态、链接">--kole-color-brand</span>
|
||
<span class="m-chip inherit" title="品牌主色点击">--kole-color-brand-active</span>
|
||
<span class="m-chip inherit" title="卡片背景">--kole-color-card-bg</span>
|
||
<span class="m-chip inherit" title="禁用背景(按钮禁用态)">--kole-color-disabled-bg</span>
|
||
<span class="m-chip inherit" title="输入框聚焦外发光">--kole-color-focus-ring</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="占位文字 · 4.54:1(原 #BFBFBF 仅 1.84:1)">--kole-color-text-placeholder</span>
|
||
<span class="m-chip inherit" title="次要文字 · 5.10:1(原 #8C8C8C 仅 3.36:1)">--kole-color-text-secondary</span>
|
||
<span class="m-chip inherit" title="">--kole-ease-standard</span>
|
||
<span class="m-chip inherit" title="按钮、输入框、选择器">--kole-radius-base</span>
|
||
<span class="m-chip inherit" title="">--kole-space-12</span>
|
||
<span class="m-chip inherit" title="">--kole-space-8</span>
|
||
<span class="m-chip" title="组件级变量(可在业务侧覆盖)">--kole-m-search-height</span>
|
||
<span class="m-chip" title="组件级变量(可在业务侧覆盖)">--kole-m-search-icon-size</span>
|
||
<span class="m-chip" title="组件级变量(可在业务侧覆盖)">--kole-m-search-radius</span>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="m-block">
|
||
<h2 id="sources">6 端源码</h2>
|
||
<p class="m-sub">同一组件的六份实现(生产环境的类名与结构一致,差异只在技术栈写法与单位)。点开查看,右侧可复制。</p>
|
||
<details class="m-details">
|
||
<summary>frameworks-mobile/Search.css · 纯样式(CSS) · 177 行</summary>
|
||
<div class="m-code">
|
||
<div class="m-code-head"><span>frameworks-mobile/Search.css</span><button class="m-copy" type="button" data-copy="code-163">复制</button></div>
|
||
<pre id="code-163"><code>/* Kole UI Mobile · Search 样式 — 对齐移动端规格 §28
|
||
搜索框:整行高不小于 44px,输入即过滤(不等回车);
|
||
放大镜是 CSS 画的(圆 + 45° 短柄),不引入图标字体(零运行时依赖);
|
||
round=false 时是方角,round=true 时是胶囊;取消动作始终 44px 热区。 */
|
||
|
||
.kole-m-search {
|
||
/* 组件级变量:业务侧可在容器上覆盖 */
|
||
--kole-m-search-height: var(--kole-m-touch-target); /* 搜索框高度(≥ 44px 触控最小边长) */
|
||
--kole-m-search-radius: var(--kole-radius-base); /* round=false 时的圆角 */
|
||
--kole-m-search-icon-size: 14px; /* 放大镜视觉尺寸 */
|
||
box-sizing: border-box;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: var(--kole-space-8);
|
||
width: 100%;
|
||
}
|
||
|
||
/* 变体 round=true:胶囊形(页面顶部常用) */
|
||
.kole-m-search--round { --kole-m-search-radius: 999px; }
|
||
|
||
.kole-m-search__form {
|
||
flex: 1 1 auto;
|
||
min-width: 0;
|
||
box-sizing: border-box;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: var(--kole-space-8);
|
||
min-height: var(--kole-m-search-height);
|
||
padding: 0 var(--kole-space-12);
|
||
border: 1px solid var(--kole-color-border);
|
||
border-radius: var(--kole-m-search-radius);
|
||
background: var(--kole-color-card-bg);
|
||
color: var(--kole-color-text-body);
|
||
font-size: var(--kole-m-font-size-body);
|
||
transition: border-color 150ms var(--kole-ease-standard);
|
||
}
|
||
|
||
.kole-m-search__form:focus-within { border-color: var(--kole-color-brand); }
|
||
|
||
/* 整行热区(放大镜 + 输入区):点框内任意位置即聚焦。
|
||
label 里不能放 labelable 元素(button 就是),所以清除按钮在 label 外 ——
|
||
否则点击清除会连带激活 label,既触发两次语义又是不合法嵌套。 */
|
||
.kole-m-search__hit {
|
||
flex: 1 1 auto;
|
||
min-width: 0;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: var(--kole-space-8);
|
||
cursor: text;
|
||
}
|
||
|
||
/* 放大镜:圆(::before)+ 45° 短柄(::after),用 currentColor 跟随文字色 */
|
||
.kole-m-search__icon {
|
||
position: relative;
|
||
flex: 0 0 auto;
|
||
display: inline-block;
|
||
width: var(--kole-m-search-icon-size);
|
||
height: var(--kole-m-search-icon-size);
|
||
color: var(--kole-color-text-secondary);
|
||
}
|
||
|
||
.kole-m-search__icon::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: 0;
|
||
left: 0;
|
||
box-sizing: border-box;
|
||
width: 10px;
|
||
height: 10px;
|
||
border: 2px solid currentColor;
|
||
border-radius: 50%;
|
||
}
|
||
|
||
.kole-m-search__icon::after {
|
||
content: '';
|
||
position: absolute;
|
||
right: 0;
|
||
bottom: 1px;
|
||
width: 6px;
|
||
height: 2px;
|
||
background: currentColor;
|
||
transform: rotate(45deg);
|
||
transform-origin: right center;
|
||
}
|
||
|
||
.kole-m-search__control {
|
||
flex: 1 1 auto;
|
||
min-width: 0;
|
||
height: var(--kole-m-search-height);
|
||
padding: 0;
|
||
border: 0;
|
||
outline: none;
|
||
background: transparent;
|
||
color: inherit;
|
||
font-family: inherit;
|
||
font-size: var(--kole-m-font-size-body);
|
||
line-height: 1.4;
|
||
/* iOS 上 type=search 自带的内阴影与圆角会破坏外框视觉,这里清掉 */
|
||
appearance: none;
|
||
-webkit-appearance: none;
|
||
}
|
||
|
||
.kole-m-search__control::placeholder { color: var(--kole-color-text-placeholder); }
|
||
|
||
.kole-m-search__control::-webkit-search-decoration,
|
||
.kole-m-search__control::-webkit-search-cancel-button { -webkit-appearance: none; }
|
||
|
||
.kole-m-search__control:disabled { color: var(--kole-color-text-disabled); cursor: not-allowed; }
|
||
|
||
/* 清除按钮:视觉 16px、热区补到 44px;有值(is-filled)时才出现 */
|
||
.kole-m-search__clear {
|
||
flex: 0 0 auto;
|
||
display: none;
|
||
align-items: center;
|
||
justify-content: center;
|
||
box-sizing: border-box;
|
||
width: var(--kole-m-touch-target);
|
||
height: var(--kole-m-touch-target);
|
||
margin-right: calc(var(--kole-space-12) * -1);
|
||
padding: 0;
|
||
border: 0;
|
||
background: none;
|
||
color: var(--kole-color-text-placeholder);
|
||
font-size: var(--kole-m-font-size-label);
|
||
line-height: 1;
|
||
cursor: pointer;
|
||
touch-action: manipulation;
|
||
}
|
||
|
||
.kole-m-search.is-filled .kole-m-search__clear { display: inline-flex; }
|
||
|
||
.kole-m-search__clear:active { color: var(--kole-color-text-secondary); }
|
||
|
||
.kole-m-search__clear:focus-visible {
|
||
outline: 2px solid var(--kole-color-focus-ring);
|
||
outline-offset: -2px;
|
||
}
|
||
|
||
/* 取消动作:只有 showCancel(is-cancelable)时才出现;文字按钮,触屏比图标好点 */
|
||
.kole-m-search__cancel {
|
||
display: none;
|
||
flex: 0 0 auto;
|
||
align-items: center;
|
||
justify-content: center;
|
||
box-sizing: border-box;
|
||
min-width: var(--kole-m-touch-target);
|
||
min-height: var(--kole-m-touch-target);
|
||
padding: 0 var(--kole-space-8);
|
||
border: 0;
|
||
background: none;
|
||
color: var(--kole-color-brand);
|
||
font-family: inherit;
|
||
font-size: var(--kole-m-font-size-body);
|
||
line-height: 1;
|
||
cursor: pointer;
|
||
touch-action: manipulation;
|
||
}
|
||
|
||
.kole-m-search.is-cancelable .kole-m-search__cancel { display: inline-flex; }
|
||
|
||
.kole-m-search__cancel:active { color: var(--kole-color-brand-active); }
|
||
|
||
.kole-m-search__cancel:focus-visible {
|
||
outline: 2px solid var(--kole-color-focus-ring);
|
||
outline-offset: -2px;
|
||
}
|
||
|
||
/* 状态 disabled:整框置灰 */
|
||
.kole-m-search.is-disabled .kole-m-search__form {
|
||
background: var(--kole-color-disabled-bg);
|
||
color: var(--kole-color-text-disabled);
|
||
cursor: not-allowed;
|
||
}
|
||
|
||
/* 禁用态:整行不再是文本光标 */
|
||
.kole-m-search.is-disabled .kole-m-search__hit { cursor: not-allowed; }
|
||
</code></pre>
|
||
</div>
|
||
</details>
|
||
<details class="m-details">
|
||
<summary>frameworks-mobile/Search.html · H5 原生(无框架) · 173 行</summary>
|
||
<div class="m-code">
|
||
<div class="m-code-head"><span>frameworks-mobile/Search.html</span><button class="m-copy" type="button" data-copy="code-164">复制</button></div>
|
||
<pre id="code-164"><code><!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
||
<title>Kole UI Mobile · Search(H5)</title>
|
||
<link rel="stylesheet" href="../.design_library/kole-ui-mobile/colors_and_type.css">
|
||
<link rel="stylesheet" href="Search.css">
|
||
<style>
|
||
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-box { padding: var(--kole-m-gutter); background: var(--kole-color-card-bg); border-block: 1px solid var(--kole-color-border); }
|
||
.demo-stack { display: flex; flex-direction: column; gap: var(--kole-space-16); }
|
||
.demo-hits { margin: var(--kole-space-8) 0 0; padding: 0; list-style: none; font-size: var(--kole-m-font-size-label);
|
||
color: var(--kole-color-text-secondary); }
|
||
.demo-hits li { padding: var(--kole-space-8) 0; border-bottom: 1px solid var(--kole-color-border); }
|
||
.demo-hits li:last-child { border-bottom: 0; }
|
||
.demo-block[hidden] { display: none; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="demo">
|
||
<section class="demo-block" data-demo="basic">
|
||
<p class="demo-label">基础用法(页面顶部一行:放大镜 + 输入区,输入即过滤,不等回车)</p>
|
||
<div class="demo-box">
|
||
<div class="kole-m-search is-filled" data-assert="search-basic">
|
||
<div class="kole-m-search__form">
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input class="kole-m-search__control" type="search" value="无线耳机" placeholder="搜索商品" aria-label="搜索商品">
|
||
</label>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="demo-block" data-demo="cancel">
|
||
<p class="demo-label">带取消(showCancel:触屏没有 Esc 键,退出搜索要有一个明确动作)</p>
|
||
<div class="demo-box">
|
||
<div class="kole-m-search is-filled is-cancelable" id="sc-cancel-root" data-assert="search-cancel">
|
||
<div class="kole-m-search__form">
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input class="kole-m-search__control" type="search" value="订单" placeholder="搜索订单" aria-label="搜索订单" id="sc-cancel-field">
|
||
</label>
|
||
</div>
|
||
<button class="kole-m-search__cancel" type="button" id="sc-cancel"
|
||
data-behavior="click-toggles-class:#sc-cancel-root|is-filled">取消</button>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="demo-block" data-demo="round">
|
||
<p class="demo-label">圆角两态(round=true 胶囊形用于页面顶部 / round=false 方角嵌在卡片或工具栏里)</p>
|
||
<div class="demo-box">
|
||
<div class="demo-stack" data-assert="search-round">
|
||
<div class="kole-m-search kole-m-search--round is-cancelable">
|
||
<div class="kole-m-search__form">
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input class="kole-m-search__control" type="search" placeholder="圆角(胶囊,顶部常用)" aria-label="圆角搜索">
|
||
</label>
|
||
</div>
|
||
<button class="kole-m-search__cancel" type="button">取消</button>
|
||
</div>
|
||
<div class="kole-m-search">
|
||
<div class="kole-m-search__form">
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input class="kole-m-search__control" type="search" placeholder="方角(嵌在卡片里)" aria-label="方角搜索">
|
||
</label>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="demo-block" data-demo="clear">
|
||
<p class="demo-label">清除(有值时清除按钮才出现;点它清空并把焦点留在输入框)</p>
|
||
<div class="demo-box">
|
||
<div class="kole-m-search is-filled" id="sc-clearable" data-assert="search-clear">
|
||
<div class="kole-m-search__form">
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input class="kole-m-search__control" type="search" value="蓝牙" placeholder="搜索商品" aria-label="搜索商品" id="sc-clearable-field">
|
||
</label>
|
||
<button class="kole-m-search__clear" type="button" aria-label="清除" id="sc-clearable-btn"
|
||
data-behavior="click-toggles-class:#sc-clearable|is-filled">✕</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="demo-block" data-demo="disabled">
|
||
<p class="demo-label">禁用(置灰且不可聚焦,键盘与读屏都会跳过)</p>
|
||
<div class="demo-box">
|
||
<div class="kole-m-search is-disabled" data-assert="search-disabled">
|
||
<div class="kole-m-search__form">
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input class="kole-m-search__control" type="search" value="暂不可用" placeholder="搜索" aria-label="搜索" disabled>
|
||
</label>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
<script>
|
||
/* 演示页脚本:真实的「输入即过滤」。
|
||
- 输入时:有值 → 根加 is-filled(清除按钮出现);无值 → 去掉
|
||
- 点清除:清空输入框、去掉 is-filled,并把焦点交还输入框
|
||
- 输入即更新下方命中列表(真实业务里这次过滤走接口或本地索引)
|
||
真实业务里这份状态由宿主管理(受控 value + input 事件),此处是最小可运行实现。 */
|
||
(function () {
|
||
Array.prototype.forEach.call(document.querySelectorAll('.kole-m-search'), function (root) {
|
||
var control = root.querySelector('.kole-m-search__control');
|
||
if (!control) return;
|
||
function sync() {
|
||
root.classList.toggle('is-filled', String(control.value || '').length > 0);
|
||
}
|
||
control.addEventListener('input', sync);
|
||
sync();
|
||
});
|
||
|
||
var clearBtn = document.getElementById('sc-clearable-btn');
|
||
if (clearBtn) {
|
||
clearBtn.addEventListener('click', function () {
|
||
var root = document.getElementById('sc-clearable');
|
||
var control = document.getElementById('sc-clearable-field');
|
||
if (control) {
|
||
control.value = '';
|
||
control.focus();
|
||
}
|
||
if (root) root.classList.remove('is-filled');
|
||
});
|
||
}
|
||
|
||
var cancelBtn = document.getElementById('sc-cancel');
|
||
if (cancelBtn) {
|
||
cancelBtn.addEventListener('click', function () {
|
||
var root = document.getElementById('sc-cancel-root');
|
||
var control = document.getElementById('sc-cancel-field');
|
||
if (control) control.value = '';
|
||
if (root) root.classList.remove('is-filled');
|
||
});
|
||
}
|
||
})();
|
||
</script>
|
||
<script>
|
||
/* ?demo=<id> → 只显示该演示块(文档站按块预览用;无参数时全部显示,测试与回归走无参数路径) */
|
||
(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 && !b.hidden) label.hidden = true;
|
||
});
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|
||
</code></pre>
|
||
</div>
|
||
</details>
|
||
<details class="m-details">
|
||
<summary>frameworks-mobile/Search.jsx · React · 86 行</summary>
|
||
<div class="m-code">
|
||
<div class="m-code-head"><span>frameworks-mobile/Search.jsx</span><button class="m-copy" type="button" data-copy="code-165">复制</button></div>
|
||
<pre id="code-165"><code>import React from 'react';
|
||
import './Search.css';
|
||
|
||
/* 搜索框(移动端)— 规格 §28
|
||
输入即过滤(不等回车);放大镜是纯装饰(aria-hidden),名称由 label 落到 aria-label。
|
||
有值且清除可用时出现清除按钮;showCancel=true 时右侧出现取消动作(触屏没有 Esc 键)。
|
||
组件不发请求、不做防抖 —— 只回传关键词,节流由宿主决定(规格 §28.7)。 */
|
||
|
||
export default function Search({
|
||
value = '',
|
||
placeholder = '',
|
||
round = true,
|
||
showCancel = false,
|
||
clearable = true,
|
||
disabled = false,
|
||
cancelText = '取消',
|
||
label = '搜索',
|
||
onInput,
|
||
onSearch,
|
||
onClear,
|
||
onCancel,
|
||
children = null,
|
||
}) {
|
||
const filled = String(value || '').length > 0;
|
||
|
||
const cls =
|
||
'kole-m-search' +
|
||
(round ? ' kole-m-search--round' : '') +
|
||
(filled ? ' is-filled' : '') +
|
||
(showCancel ? ' is-cancelable' : '') +
|
||
(disabled ? ' is-disabled' : '');
|
||
|
||
return (
|
||
<div className={cls}>
|
||
<div className="kole-m-search__form">
|
||
{/* 整行热区是 label;清除按钮是 labelable 元素(button),必须在 label 外 */}
|
||
<label className="kole-m-search__hit">
|
||
<span className="kole-m-search__icon" aria-hidden="true" />
|
||
<input
|
||
className="kole-m-search__control"
|
||
type="search"
|
||
value={value}
|
||
placeholder={placeholder}
|
||
disabled={disabled}
|
||
aria-label={label}
|
||
onChange={(e) => {
|
||
if (disabled) return;
|
||
if (onInput) onInput(e.target.value);
|
||
}}
|
||
onKeyDown={(e) => {
|
||
if (disabled) return;
|
||
if (e.key === 'Enter' && onSearch) onSearch(value);
|
||
}}
|
||
/>
|
||
</label>
|
||
{clearable && filled && !disabled ? (
|
||
<button
|
||
className="kole-m-search__clear"
|
||
type="button"
|
||
aria-label="清除"
|
||
onClick={() => {
|
||
if (onClear) onClear();
|
||
}}
|
||
>
|
||
✕
|
||
</button>
|
||
) : null}
|
||
</div>
|
||
{showCancel ? (
|
||
<button
|
||
className="kole-m-search__cancel"
|
||
type="button"
|
||
disabled={disabled}
|
||
onClick={() => {
|
||
if (disabled) return;
|
||
if (onCancel) onCancel();
|
||
}}
|
||
>
|
||
{cancelText}
|
||
</button>
|
||
) : null}
|
||
{children}
|
||
</div>
|
||
);
|
||
}
|
||
</code></pre>
|
||
</div>
|
||
</details>
|
||
<details class="m-details">
|
||
<summary>frameworks-mobile/Search.vue2.vue · Vue 2 · 86 行</summary>
|
||
<div class="m-code">
|
||
<div class="m-code-head"><span>frameworks-mobile/Search.vue2.vue</span><button class="m-copy" type="button" data-copy="code-166">复制</button></div>
|
||
<pre id="code-166"><code><template>
|
||
<div class="kole-m-search" :class="searchClass">
|
||
<div class="kole-m-search__form">
|
||
<!-- 整行热区是 label;清除按钮是 labelable 元素(button),必须在 label 外 -->
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input
|
||
class="kole-m-search__control"
|
||
type="search"
|
||
:value="value"
|
||
:placeholder="placeholder"
|
||
:disabled="disabled"
|
||
:aria-label="label"
|
||
@input="onInput"
|
||
@keydown.enter="$emit('search', value)"
|
||
/>
|
||
</label>
|
||
<button
|
||
v-if="clearable && filled && !disabled"
|
||
class="kole-m-search__clear"
|
||
type="button"
|
||
aria-label="清除"
|
||
@click="$emit('clear')"
|
||
>
|
||
✕
|
||
</button>
|
||
</div>
|
||
<button
|
||
v-if="showCancel"
|
||
class="kole-m-search__cancel"
|
||
type="button"
|
||
:disabled="disabled"
|
||
@click="onCancel"
|
||
>
|
||
{{ cancelText }}
|
||
</button>
|
||
<slot></slot>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
/* 搜索框(移动端)— 规格 §28
|
||
输入即过滤(不等回车);放大镜是纯装饰(aria-hidden),名称由 label 落到 aria-label。
|
||
有值且清除可用时出现清除按钮;showCancel=true 时右侧出现取消动作(触屏没有 Esc 键)。
|
||
组件不发请求、不做防抖 —— 只回传关键词,节流由宿主决定(规格 §28.7)。 */
|
||
|
||
export default {
|
||
name: 'KoleMSearch',
|
||
props: {
|
||
value: { type: String, default: '' },
|
||
placeholder: { type: String, default: '' },
|
||
round: { type: Boolean, default: true },
|
||
showCancel: { type: Boolean, default: false },
|
||
clearable: { type: Boolean, default: true },
|
||
disabled: { type: Boolean, default: false },
|
||
cancelText: { type: String, default: '取消' },
|
||
label: { type: String, default: '搜索' }
|
||
},
|
||
computed: {
|
||
filled: function () {
|
||
return String(this.value || '').length > 0;
|
||
},
|
||
searchClass: function () {
|
||
return [
|
||
this.round ? 'kole-m-search--round' : '',
|
||
this.filled ? 'is-filled' : '',
|
||
this.showCancel ? 'is-cancelable' : '',
|
||
this.disabled ? 'is-disabled' : ''
|
||
].filter(Boolean);
|
||
}
|
||
},
|
||
methods: {
|
||
onInput: function (e) {
|
||
if (this.disabled) return;
|
||
this.$emit('input', e.target.value);
|
||
},
|
||
onCancel: function () {
|
||
if (this.disabled) return;
|
||
this.$emit('cancel');
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style src="./Search.css"></style>
|
||
</code></pre>
|
||
</div>
|
||
</details>
|
||
<details class="m-details">
|
||
<summary>frameworks-mobile/Search.vue3.vue · Vue 3 · 81 行</summary>
|
||
<div class="m-code">
|
||
<div class="m-code-head"><span>frameworks-mobile/Search.vue3.vue</span><button class="m-copy" type="button" data-copy="code-167">复制</button></div>
|
||
<pre id="code-167"><code><template>
|
||
<div class="kole-m-search" :class="searchClass">
|
||
<div class="kole-m-search__form">
|
||
<!-- 整行热区是 label;清除按钮是 labelable 元素(button),必须在 label 外 -->
|
||
<label class="kole-m-search__hit">
|
||
<span class="kole-m-search__icon" aria-hidden="true"></span>
|
||
<input
|
||
class="kole-m-search__control"
|
||
type="search"
|
||
:value="value"
|
||
:placeholder="placeholder"
|
||
:disabled="disabled"
|
||
:aria-label="label"
|
||
@input="onInput"
|
||
@keydown.enter="emit('search', value)"
|
||
/>
|
||
</label>
|
||
<button
|
||
v-if="clearable && filled && !disabled"
|
||
class="kole-m-search__clear"
|
||
type="button"
|
||
aria-label="清除"
|
||
@click="emit('clear')"
|
||
>
|
||
✕
|
||
</button>
|
||
</div>
|
||
<button
|
||
v-if="showCancel"
|
||
class="kole-m-search__cancel"
|
||
type="button"
|
||
:disabled="disabled"
|
||
@click="onCancel"
|
||
>
|
||
{{ cancelText }}
|
||
</button>
|
||
<slot></slot>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup>
|
||
/* 搜索框(移动端)— 规格 §28
|
||
输入即过滤(不等回车);放大镜是纯装饰(aria-hidden),名称由 label 落到 aria-label。
|
||
有值且清除可用时出现清除按钮;showCancel=true 时右侧出现取消动作(触屏没有 Esc 键)。
|
||
组件不发请求、不做防抖 —— 只回传关键词,节流由宿主决定(规格 §28.7)。 */
|
||
import { computed } from 'vue';
|
||
|
||
const props = defineProps({
|
||
value: { type: String, default: '' },
|
||
placeholder: { type: String, default: '' },
|
||
round: { type: Boolean, default: true },
|
||
showCancel: { type: Boolean, default: false },
|
||
clearable: { type: Boolean, default: true },
|
||
disabled: { type: Boolean, default: false },
|
||
cancelText: { type: String, default: '取消' },
|
||
label: { type: String, default: '搜索' }
|
||
});
|
||
const emit = defineEmits(['input', 'search', 'clear', 'cancel']);
|
||
|
||
const filled = computed(() => String(props.value || '').length > 0);
|
||
|
||
const searchClass = computed(() => [
|
||
props.round ? 'kole-m-search--round' : '',
|
||
filled.value ? 'is-filled' : '',
|
||
props.showCancel ? 'is-cancelable' : '',
|
||
props.disabled ? 'is-disabled' : ''
|
||
].filter(Boolean));
|
||
|
||
function onInput(e) {
|
||
if (props.disabled) return;
|
||
emit('input', e.target.value);
|
||
}
|
||
|
||
function onCancel() {
|
||
if (props.disabled) return;
|
||
emit('cancel');
|
||
}
|
||
</script>
|
||
|
||
<style src="./Search.css"></style>
|
||
</code></pre>
|
||
</div>
|
||
</details>
|
||
<details class="m-details">
|
||
<summary>frameworks-mobile/Search.uniapp.vue · uni-app(跨端:小程序 / App / H5) · 174 行</summary>
|
||
<div class="m-code">
|
||
<div class="m-code-head"><span>frameworks-mobile/Search.uniapp.vue</span><button class="m-copy" type="button" data-copy="code-168">复制</button></div>
|
||
<pre id="code-168"><code><template>
|
||
<view class="kole-m-search" :class="searchClass">
|
||
<view class="kole-m-search__form">
|
||
<view class="kole-m-search__icon"></view>
|
||
<input
|
||
class="kole-m-search__control"
|
||
type="text"
|
||
confirm-type="search"
|
||
:value="value"
|
||
:placeholder="placeholder"
|
||
:disabled="disabled"
|
||
:aria-label="label"
|
||
placeholder-class="kole-m-search__placeholder"
|
||
@input="onInput"
|
||
@confirm="onConfirm"
|
||
/>
|
||
<view
|
||
v-if="clearable && filled && !disabled"
|
||
class="kole-m-search__clear"
|
||
role="button"
|
||
aria-label="清除"
|
||
@tap="clear"
|
||
>
|
||
<text>✕</text>
|
||
</view>
|
||
</view>
|
||
<view
|
||
v-if="showCancel"
|
||
class="kole-m-search__cancel"
|
||
:role="disabled ? '' : 'button'"
|
||
:aria-disabled="disabled ? 'true' : 'false'"
|
||
@tap="onCancel"
|
||
>
|
||
<text>{{ cancelText }}</text>
|
||
</view>
|
||
<slot></slot>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
/* uni-app 端 · 搜索框(移动端)— 规格 §28
|
||
跨端差异:
|
||
① <input> 是 uni 基础组件,事件对象是 { detail: { value } },没有 DOM 的 event.target;
|
||
② 键盘右下角键位用 confirm-type="search"(对应 @confirm),不是 keydown.enter;
|
||
③ 取消动作与清除按钮用 view + role="button"(小程序没有可聚焦的原生 button 语义),点击用 @tap;
|
||
④ uni 的 input 没有 type="search" 的样式差异,用 type="text" + confirm-type 表达语义。
|
||
尺寸用 rpx:88rpx = 375pt 下的 44px 触控最小边长。 */
|
||
import { computed } from 'vue';
|
||
|
||
const props = defineProps({
|
||
value: { type: String, default: '' },
|
||
placeholder: { type: String, default: '' },
|
||
round: { type: Boolean, default: true },
|
||
showCancel: { type: Boolean, default: false },
|
||
clearable: { type: Boolean, default: true },
|
||
disabled: { type: Boolean, default: false },
|
||
cancelText: { type: String, default: '取消' },
|
||
label: { type: String, default: '搜索' }
|
||
});
|
||
const emit = defineEmits(['input', 'search', 'clear', 'cancel']);
|
||
|
||
const filled = computed(() => String(props.value || '').length > 0);
|
||
|
||
const searchClass = computed(() => [
|
||
props.round ? 'kole-m-search--round' : '',
|
||
filled.value ? 'is-filled' : '',
|
||
props.showCancel ? 'is-cancelable' : '',
|
||
props.disabled ? 'is-disabled' : ''
|
||
].filter(Boolean));
|
||
|
||
/* uni 的 <input> 事件对象为 { detail: { value } },无 DOM event.target */
|
||
function onInput(e) {
|
||
if (props.disabled) return;
|
||
emit('input', e && e.detail ? e.detail.value : '');
|
||
}
|
||
|
||
function onConfirm(e) {
|
||
if (props.disabled) return;
|
||
emit('search', e && e.detail ? e.detail.value : props.value);
|
||
}
|
||
|
||
function clear() {
|
||
if (props.disabled) return;
|
||
emit('clear');
|
||
}
|
||
|
||
function onCancel() {
|
||
if (props.disabled) return;
|
||
emit('cancel');
|
||
}
|
||
</script>
|
||
|
||
<style>
|
||
.kole-m-search {
|
||
--kole-m-search-height: 88rpx; /* 搜索框高度(88rpx = 44px,触控最小边长) */
|
||
--kole-m-search-radius: 8rpx; /* round=false 时的圆角 */
|
||
--kole-m-touch-target: 88rpx;
|
||
--kole-m-font-size-body: 32rpx;
|
||
--kole-m-font-size-label: 28rpx;
|
||
--kole-m-gutter: 32rpx;
|
||
box-sizing: border-box;
|
||
display: flex;
|
||
align-items: center;
|
||
width: 100%;
|
||
}
|
||
|
||
.kole-m-search--round { --kole-m-search-radius: 999rpx; }
|
||
|
||
.kole-m-search__form {
|
||
flex: 1;
|
||
box-sizing: border-box;
|
||
display: flex;
|
||
align-items: center;
|
||
min-height: var(--kole-m-search-height);
|
||
padding: 0 24rpx;
|
||
border: 1rpx solid var(--kole-color-border);
|
||
border-radius: var(--kole-m-search-radius);
|
||
background-color: var(--kole-color-card-bg);
|
||
color: var(--kole-color-text-body);
|
||
font-size: var(--kole-m-font-size-body);
|
||
}
|
||
|
||
.kole-m-search__form:focus-within { border-color: var(--kole-color-brand); }
|
||
|
||
/* 放大镜:纯装饰方块(uni 端不引图标字体,用边框圆点 + 短柄由 CSS 画) */
|
||
.kole-m-search__icon {
|
||
flex-shrink: 0;
|
||
width: 28rpx;
|
||
height: 28rpx;
|
||
border: 4rpx solid var(--kole-color-text-secondary);
|
||
border-radius: 50%;
|
||
}
|
||
|
||
.kole-m-search__control {
|
||
flex: 1;
|
||
min-width: 0;
|
||
height: var(--kole-m-search-height);
|
||
padding-left: 16rpx;
|
||
font-size: var(--kole-m-font-size-body);
|
||
color: inherit;
|
||
}
|
||
|
||
.kole-m-search__placeholder { color: var(--kole-color-text-placeholder); }
|
||
|
||
.kole-m-search__clear {
|
||
flex-shrink: 0;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 88rpx;
|
||
height: 88rpx;
|
||
margin-right: -24rpx;
|
||
color: var(--kole-color-text-placeholder);
|
||
font-size: var(--kole-m-font-size-label);
|
||
}
|
||
|
||
.kole-m-search__cancel {
|
||
flex-shrink: 0;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
min-width: 88rpx;
|
||
min-height: 88rpx;
|
||
padding: 0 16rpx;
|
||
color: var(--kole-color-brand);
|
||
font-size: var(--kole-m-font-size-body);
|
||
}
|
||
|
||
.kole-m-search.is-disabled .kole-m-search__form {
|
||
background-color: var(--kole-color-disabled-bg);
|
||
color: var(--kole-color-text-disabled);
|
||
}
|
||
</style>
|
||
</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 &
|
||
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-search.json(点击展开原始 JSON)</summary>
|
||
<div class="m-code"><pre><code>{
|
||
"schemaVersion": 1,
|
||
"sourceKind": "authored-spec",
|
||
"provenance": "authored-in-repo",
|
||
"specFile": "spec/移动端规格.md",
|
||
"specSection": "28 · 搜索框 Search",
|
||
"confidence": "high",
|
||
"slug": "mobile-search",
|
||
"name": "搜索框 Search",
|
||
"semanticTypeCandidates": [
|
||
"search",
|
||
"search-field",
|
||
"filter-input"
|
||
],
|
||
"variantDimensions": [
|
||
{
|
||
"name": "round",
|
||
"values": [
|
||
"true",
|
||
"false"
|
||
]
|
||
},
|
||
{
|
||
"name": "showCancel",
|
||
"values": [
|
||
"false",
|
||
"true"
|
||
]
|
||
}
|
||
],
|
||
"representativeVariants": [
|
||
{
|
||
"round": "true",
|
||
"showCancel": "true",
|
||
"label": "胶囊形 + 取消(页面顶部常用)"
|
||
},
|
||
{
|
||
"round": "false",
|
||
"showCancel": "false",
|
||
"label": "方角无取消(嵌在卡片或工具栏里)"
|
||
},
|
||
{
|
||
"round": "true",
|
||
"showCancel": "false",
|
||
"label": "胶囊形无取消"
|
||
}
|
||
],
|
||
"anatomy": {
|
||
"search": "根元素,一行里放进「搜索框 + 取消动作」",
|
||
"icon": "框内左侧放大镜,纯装饰(不承载语义,读屏由 label 承担)",
|
||
"control": "原生 input type=\"search\",占满剩余宽度",
|
||
"clear": "可选清除按钮,有值且清除可用时出现在图标与取消之间",
|
||
"cancel": "可选取消动作,默认文案「取消」,由 showCancel 控制显隐"
|
||
},
|
||
"structurePatterns": {
|
||
"round": "true(胶囊形,页面顶部常用)/ false(方角,嵌在卡片或工具栏里)",
|
||
"showCancel": "false(只有输入框)/ true(右侧出现取消动作)"
|
||
},
|
||
"usageHints": [
|
||
"用关键词从长列表里取回一小段结果",
|
||
"移动端的搜索框几乎总是页面顶部的独立一行",
|
||
"输入即过滤(不等回车)",
|
||
"触屏没有 Esc 键,用户清空关键词后仍需一键回到列表,因此要有明确的取消动作",
|
||
"组件不发请求、不做防抖:只回传关键词,节流策略由宿主决定"
|
||
],
|
||
"doNotInvent": [
|
||
"搜索的防抖时值与接口节流策略(由宿主决定)",
|
||
"搜索历史的存储与展示",
|
||
"搜索结果的高亮规则"
|
||
],
|
||
"unknowns": [
|
||
"取消文案是否允许替换(如「返回」)",
|
||
"是否需要自动聚焦并拉起键盘",
|
||
"语音/扫码等扩展入口是否放进框内"
|
||
],
|
||
"interaction": [
|
||
"搜索框高度不小于 44px,取消动作热区不小于 44px",
|
||
"输入即触发 input 事件(不等回车);键盘「搜索」键触发 search 事件",
|
||
"清除按钮只在有值时出现,点击清空并把焦点留在输入框",
|
||
"清除与取消都是 44px 热区;两者同时出现时先清除、再取消(自右向左层级递进)"
|
||
],
|
||
"accessibility": [
|
||
"输入框用原生 input type=\"search\"(iOS 键盘右下角键位变成「搜索」)",
|
||
"搜索图标是装饰性的,置 aria-hidden=\"true\",名称由 aria-label 给出",
|
||
"清除按钮是原生 button 且带 aria-label=\"清除\";取消动作是原生 button",
|
||
"取消按钮不用图标代替文字(触屏上文字比图标更好点)"
|
||
],
|
||
"api": {
|
||
"source": "implementation",
|
||
"note": "props / events / slots 为 6 端实现的公共接口(说明文字取自规格对应小节)。字段名与各端源码逐名核对:node tools/verify-mobile-docs.mjs",
|
||
"requiredNote": "「必传」按严格定义:实现里**没有默认值**时才为 Y(本门禁逐条核对 props 与各端源码的默认值,防止契约与实现脱节)。",
|
||
"props": [
|
||
{
|
||
"name": "value",
|
||
"type": "string",
|
||
"default": "''",
|
||
"desc": "受控关键词;有值时清除按钮才出现(规格 §28.5)",
|
||
"required": false
|
||
},
|
||
{
|
||
"name": "placeholder",
|
||
"type": "string",
|
||
"default": "''",
|
||
"desc": "占位文字,提示搜索范围(如「搜索商品」)(规格 §28.2 control)",
|
||
"required": false
|
||
},
|
||
{
|
||
"name": "round",
|
||
"type": "boolean",
|
||
"default": "true",
|
||
"desc": "变体 round:true 胶囊形,false 方角(规格 §28.3)",
|
||
"required": false
|
||
},
|
||
{
|
||
"name": "showCancel",
|
||
"type": "boolean",
|
||
"default": "false",
|
||
"desc": "变体 showCancel:右侧是否出现取消动作(规格 §28.3)",
|
||
"required": false
|
||
},
|
||
{
|
||
"name": "clearable",
|
||
"type": "boolean",
|
||
"default": "true",
|
||
"desc": "有值时是否允许清除(规格 §28.5)",
|
||
"required": false
|
||
},
|
||
{
|
||
"name": "disabled",
|
||
"type": "boolean",
|
||
"default": "false",
|
||
"desc": "状态 disabled:置灰且不可聚焦(规格 §28.4)",
|
||
"required": false
|
||
},
|
||
{
|
||
"name": "cancelText",
|
||
"type": "string",
|
||
"default": "'取消'",
|
||
"desc": "取消动作文案;不用图标代替文字(规格 §28.6)",
|
||
"required": false
|
||
},
|
||
{
|
||
"name": "label",
|
||
"type": "string",
|
||
"default": "'搜索'",
|
||
"desc": "无障碍名称,落到 aria-label(规格 §28.6)",
|
||
"required": false
|
||
}
|
||
],
|
||
"events": [
|
||
{
|
||
"name": "input",
|
||
"params": "(value)",
|
||
"desc": "输入即触发,不等回车(规格 §28.5)"
|
||
},
|
||
{
|
||
"name": "search",
|
||
"params": "(value)",
|
||
"desc": "键盘「搜索」键触发(规格 §28.5)"
|
||
},
|
||
{
|
||
"name": "clear",
|
||
"params": "—",
|
||
"desc": "点击清除按钮触发,值由宿主置空(规格 §28.5)"
|
||
},
|
||
{
|
||
"name": "cancel",
|
||
"params": "—",
|
||
"desc": "点击取消动作触发,由宿主退出搜索态(规格 §28.5)"
|
||
}
|
||
],
|
||
"slots": [
|
||
{
|
||
"name": "default",
|
||
"desc": "根元素内的追加内容(如右侧的筛选入口)(规格 §28.2 search)"
|
||
}
|
||
]
|
||
},
|
||
"variantClasses": {
|
||
"round": {
|
||
"true": [
|
||
".kole-m-search--round"
|
||
],
|
||
"false": []
|
||
},
|
||
"showCancel": {
|
||
"false": [],
|
||
"true": [
|
||
".kole-m-search__cancel"
|
||
]
|
||
}
|
||
},
|
||
"demos": [
|
||
{
|
||
"id": "basic",
|
||
"group": "01 组件类型",
|
||
"title": "基础用法",
|
||
"desc": "页面顶部一行:放大镜 + 输入区,输入即过滤(不等回车)。",
|
||
"variant": "round=true"
|
||
},
|
||
{
|
||
"id": "cancel",
|
||
"group": "01 组件类型",
|
||
"title": "带取消",
|
||
"desc": "showCancel=true:触屏没有 Esc 键,退出搜索需要一个明确的文字动作。",
|
||
"variant": "showCancel=true"
|
||
},
|
||
{
|
||
"id": "round",
|
||
"group": "01 组件类型",
|
||
"title": "圆角两态",
|
||
"desc": "round=true 胶囊形用于页面顶部;round=false 方角嵌在卡片或工具栏里。",
|
||
"variant": "round=true|false"
|
||
},
|
||
{
|
||
"id": "clear",
|
||
"group": "01 组件类型",
|
||
"title": "清除",
|
||
"desc": "有值时清除按钮才出现;点它清空并把焦点留在输入框。",
|
||
"variant": "clearable=true"
|
||
},
|
||
{
|
||
"id": "disabled",
|
||
"group": "02 组件状态",
|
||
"title": "禁用",
|
||
"desc": "置灰且不可聚焦,键盘与读屏都会跳过。",
|
||
"variant": "disabled=true"
|
||
}
|
||
],
|
||
"related": [
|
||
{
|
||
"slug": "mobile-input",
|
||
"why": "收集填写内容用输入框;目的就是从列表里取回结果时才用搜索框"
|
||
},
|
||
{
|
||
"slug": "cell",
|
||
"why": "「搜索入口」只做跳转时用单元格,点开才是真搜索页"
|
||
},
|
||
{
|
||
"slug": "mobile-list",
|
||
"why": "搜索结果用列表承载;搜索框只负责取关键词"
|
||
}
|
||
]
|
||
}</code></pre></div>
|
||
</details>
|
||
</section>
|
||
|
||
<footer class="m-foot">
|
||
<p>生成物:本页由 <code>node tools/build-mobile.mjs</code> 从契约 <code>components/mobile-search.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>
|