默认
<cu-code-input :value="v1" @input="onV1" @change="onChange" @finish="onFinish" />
验证码输入用于分格展示已输入的验证码,支持方框与横线两种格子样式。
整目录放进工程即用:easycom 按标签逐个解析,页面写哪个组件就只编译哪个,不写 import,也没有全局注册这一步;单个组件也可以显式引入(第 4 步,可选);主题层在 App.uvue 引入一次即可。
# 1 整目录放进工程(easycom 自动解析) your-project/ └── uni_modules/ └── colorui-x/ # 2 App.uvue 全局引入主题层(一次) @import 'uni_modules/colorui-x/theme/base.css'; @import 'uni_modules/colorui-x/theme/layout.css'; @import 'uni_modules/colorui-x/theme/color.scss'; // 颜色工具类(.bg-* / .text-*) # 3 页面里直接用,不写 import(只编译用到的组件) <cu-code-input /> # 4 单个组件也可以显式引入(可选,不用 easycom 时) import CuCodeInput from '@/uni_modules/colorui-x/components/cu-code-input/cu-code-input.uvue'
组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。
| Android | iOS | HarmonyOS | Web(H5) | 微信小程序 | 支付宝小程序 |
|---|---|---|---|---|---|
| √ | — | — | √ | — | — |
Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。
Web 列只表示已编出可运行的预览产物,非真机渲染。
其余三端没有任何实测证据,不作支持承诺。
<cu-code-input :value="v1" @input="onV1" @change="onChange" @finish="onFinish" />
<cu-code-input mode="box" :value="v2a" @input="onV2a" /> <cu-code-input mode="line" :value="v2b" @input="onV2b" />
<cu-code-input :maxlength="1" /> <cu-code-input :maxlength="4" :value="v3" @input="onV3" /> <cu-code-input :maxlength="8" />
<cu-code-input :dot="true" value="123" /> <cu-code-input :dot="true" :maxlength="4" />
<cu-code-input :hairline="false" :maxlength="4" /> <cu-code-input :hairline="true" :maxlength="4" /> <cu-code-input mode="line" :hairline="true" :maxlength="4" />
<cu-code-input :size="20" :maxlength="4" />
<cu-code-input value="123" color="#e54d42" /> <cu-code-input value="123" borderColor="#0081ff" /> <cu-code-input mode="line" value="123" borderColor="#0081ff" /> <cu-code-input :dot="true" value="123" color="#e54d42" />
<cu-code-input :disabledDot="true" :maxlength="6" />
<cu-code-input :focus="autoFocus" :maxlength="4" /> <cu-code-input :adjustPosition="true" :maxlength="6" value="12" />
<cu-code-input :maxlength="4" :value="v10" @input="onV10" @finish="onFinish10" />
<cu-code-input value="" /> <cu-code-input :maxlength="0" />
<cu-code-input :customStyle="styleDemo" :maxlength="4" /> <cu-code-input customClass="custom-class" :maxlength="4" />
这一节的交互由演示页脚本驱动,效果见右侧实时预览。
这一节的交互由演示页脚本驱动,效果见右侧实时预览。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| 输入与取值 | |||
| value | 已输入的验证码文本,超出 maxlength 的部分截断;回写该值可做受控 | String | '' |
| maxlength | 格子数量,同时是最大输入位数 | Number | 6 |
| focus | true ⇒ 自动聚焦并拉起系统键盘 | Boolean | false |
| disabledKeyboard | true ⇒ 禁用原生输入域,配合自绘数字键盘使用 | Boolean | false |
| disabledDot | true ⇒ 输入小数点时自动剔除,且该次不抛事件 | Boolean | true |
| 格子外观 | |||
| mode | box 方框 / line 底部横线,两种格子形态 | String | 'box' |
| dot | true ⇒ 已输入的格子显示圆点,不露明文 | Boolean | false |
| size | 单格边长,px 契约值;运行时 ×2 换算成 rpx,宽高同值 | Number | 35 |
| space | 格子间距,px 契约值;运行时 ×2 换算成 rpx,为 0 时方框合并成一条 | Number | 10 |
| hairline | true ⇒ 底部横线改细档(4rpx 对默认 8rpx) | Boolean | false |
| 文字与描边样式 | |||
| color | 单格文字与圆点的颜色;空串走 token 默认 | String | '' |
| fontSize | 单格文字字号,px 契约值;运行时 ×2 换算成 rpx | Number | 18 |
| bold | true ⇒ 单格文字加粗 | Boolean | false |
| borderColor | 方框描边与底部横线的颜色;空串走 token 默认 | String | '' |
| 交互与样式 | |||
| customStyle | 根节点内联样式 | Object | (): UTSJSONObject => ({}) |
| customClass | 追加到根节点的类名 | String | '' |
| 声明保留但不被消费 | |||
| adjustPosition | 原生输入域获焦时是否顶起页面;本仓不读取,传参不生效 | Boolean | true |
| url | 不产生跳转,请在 finish 里自行跳转 | String | '' |
| linkType | 不产生跳转,同上 | String | 'navigateTo' |
| 事件 | 说明 | 类型 | 默认值 | 平台差异说明 |
|---|---|---|---|---|
| @change | 输入变化时触发,回传当前完整文本;把该值回写 value 不会再次触发 | Handler | - | 各端一致 |
| @input | 与 change 同一次变化内紧接抛出,回传同一份文本 | Handler | - | 各端一致 |
| @finish | 输入长度达到 maxlength 时触发,回传当前文本 | Handler | - | 各端一致 |
| slot | 说明 |
|---|---|
| (默认) | 自定义内容;不填时按 maxlength 渲染对应数量的格子 |
自绘键盘 :开 disabledKeyboard 后点格子与 focus 都拉不起键盘,只能由自绘键盘回写 value;而回写只更新格子,不会补发 change 或 finish,完成判断要自己做。
圆点非加密 :dot 只把已输入的格子画成圆点,value 与三个事件里仍是明文,做密码或 PIN 场景时不要把它当脱敏。