更新记录

1.0.1(2025-12-07) 下载此版本

适配鸿蒙系统

1.0.0(2025-12-07) 下载此版本

appx-input 是一款基于 UTS 语法开发的通用输入框组件,适配 uni-app 生态,支持文本、数字、密码等多种输入类型,提供前置 / 后置图标、清除按钮、字数统计、自定义样式等丰富功能,同时支持输入格式化、多状态样式控制,满足各类表单输入场景需求。


平台兼容性

uni-app x(4.87)

Chrome Safari Android iOS 鸿蒙 微信小程序

appx-input 输入框组件帮助文档

组件介绍

appx-input 是一款基于UTS语法开发的通用输入框组件,适配uni-app生态,支持文本、数字、密码等多种输入类型,提供前置/后置图标、清除按钮、字数统计、自定义样式等丰富功能,同时支持输入格式化、多状态样式控制,满足各类表单输入场景需求。

组件特性

  • 支持多输入类型:文本、数字、身份证、小数、密码等;
  • 内置清除按钮,可一键清空输入内容;
  • 支持前置/后置图标自定义,样式可灵活配置;
  • 提供字数统计功能,支持无限长度配置;
  • 支持输入内容格式化处理;
  • 多状态样式控制:禁用、聚焦、只读等;
  • 灵活的边框、形状、对齐方式配置;
  • 完整的事件回调:输入、确认、聚焦、失焦等。

基本使用

<template>
  <appx-input 
    v-model="inputValue" 
    placeholder="请输入内容" 
    clearable
    show-word-limit
    maxlength="20"
  />
</template>

<script lang="uts" setup>
const inputValue = ref('');
</script>

属性说明

属性名 类型 默认值 说明
value/v-model number | string '' 输入框绑定值
type 'text' | 'number' | 'idcard' | 'digit' | 'password' 'text' 输入框类型
disabled boolean false 是否禁用输入框
disabledColor string '#f5f7fa' 禁用状态下的背景色
clearable boolean|string false 是否显示清除按钮
password boolean false 是否为密码输入框(优先级高于type)
maxlength string | number -1 最大输入长度,-1表示无限制
placeholder string '' 占位提示文字
placeholderClass string 'input-placeholder' 占位符样式类名
placeholderStyle string | object 'color: #c0c4cc' 占位符样式
showWordLimit boolean false 是否显示字数统计(仅文本/多行文本类型生效)
confirmType 'send' | 'search' | 'next' | 'go' | 'done' 'done' 键盘确认按钮类型
confirmHold boolean false 点击确认按钮后是否保持键盘不收起
holdKeyboard boolean false 聚焦时是否保持键盘弹出状态
focus boolean false 是否自动聚焦
autoBlur boolean false 是否自动失焦
ignoreCompositionEvent boolean true 是否忽略输入法组合事件
disableDefaultPadding boolean false 是否禁用默认内边距
cursor string | number -1 指定光标位置,-1表示默认
cursorSpacing string | number 30 光标与输入框边缘的间距
selectionStart string | number -1 光标起始位置,-1表示默认
selectionEnd string | number -1 光标结束位置,-1表示默认
adjustPosition boolean true 输入框聚焦时是否自动上推页面
inputAlign 'left' | 'center' | 'right' 'left' 输入内容的对齐方式
fontSize string | number '15px' 输入内容的字体大小
color string '#303133' 输入内容的字体颜色
prefixIcon string '' 前置图标(支持文本/图标字体)
prefixIconStyle string | object '' 前置图标样式
suffixIcon string '' 后置图标(支持文本/图标字体)
suffixIconStyle string | object '' 后置图标样式
border 'surround' | 'bottom' | 'none' 'surround' 边框样式:环绕、仅底部、无
readonly boolean false 是否只读
shape 'circle' | 'square' 'square' 输入框形状:圆形(圆角极大)、方形
formatter (value: string) => string null 输入内容格式化函数,入参为输入值,返回格式化后的值
customStyle object {} 自定义容器样式

事件说明

事件名 触发条件 回调参数 说明
input 输入框内容变化时 value: number | string 返回当前输入框的值
confirm 点击键盘确认按钮时 value: number | string 返回当前输入框的值
focus 输入框聚焦时 e: UniApp.InputFocusEvent 返回聚焦事件对象
blur 输入框失焦时 e: UniApp.InputBlurEvent 返回失焦事件对象
compositionstart 输入法组合开始时(ignoreCompositionEvent为false时触发) e: UniApp.InputCompositionStartEvent 返回组合开始事件对象
compositionupdate 输入法组合更新时(ignoreCompositionEvent为false时触发) e: UniApp.InputCompositionUpdateEvent 返回组合更新事件对象
compositionend 输入法组合结束时(ignoreCompositionEvent为false时触发) e: UniApp.InputCompositionEndEvent 返回组合结束事件对象
clear 点击清除按钮时 - 清除按钮点击触发

高级用法

1. 带格式化的输入框

<template>
  <appx-input 
    v-model="phoneValue" 
    placeholder="请输入手机号" 
    :formatter="formatPhone"
    maxlength="11"
    type="number"
  />
</template>

<script lang="uts" setup>
const phoneValue = ref('');

// 手机号格式化:每3位加空格
const formatPhone = (value) => {
  // 去除所有非数字字符
  const pureNum = value.replace(/\D/g, '');
  // 格式化
  if (pureNum.length > 3 && pureNum.length <= 7) {
    return `${pureNum.slice(0,3)} ${pureNum.slice(3)}`;
  } else if (pureNum.length > 7) {
    return `${pureNum.slice(0,3)} ${pureNum.slice(3,7)} ${pureNum.slice(7)}`;
  }
  return pureNum;
};
</script>

2. 带前置/后置图标的输入框

<template>
  <appx-input 
    v-model="searchValue" 
    placeholder="请输入搜索内容" 
    prefixIcon="🔍"
    suffixIcon="✓"
    :prefixIconStyle="{color: '#409eff', fontSize: '16px'}"
    :suffixIconStyle="{color: '#67c23a', fontSize: '16px'}"
    border="bottom"
  />
</template>

<script lang="uts" setup>
const searchValue = ref('');
</script>

3. 圆形密码输入框

<template>
  <appx-input 
    v-model="pwdValue" 
    placeholder="请输入密码" 
    password
    shape="circle"
    clearable
    disabledColor="#f0f2f5"
  />
</template>

<script lang="uts" setup>
const pwdValue = ref('');
</script>

样式定制

组件支持通过以下方式定制样式:

  1. customStyle 属性:自定义容器整体样式;
  2. prefixIconStyle/suffixIconStyle:定制前置/后置图标样式;
  3. placeholderStyle:定制占位符样式;
  4. CSS变量:可通过:style覆盖内置CSS变量,如--input-color--border-radius等;
  5. 全局样式:通过非scoped的style标签覆盖组件内置类名样式。

注意事项

  1. password 属性优先级高于type,设置password=true时,输入框类型强制为密码框;
  2. 字数统计仅对type="text"type="textarea"生效;
  3. formatter 格式化函数会改变输入框的显示值,同时也会同步到绑定值中;
  4. 清除按钮点击时,会同时清空本地绑定值和DOM值,确保状态一致;
  5. 组件基于UTS语法开发,需确保uni-app项目支持UTS编译环境。

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。