This commit is contained in:
2026-01-05 12:47:14 +08:00
commit 1fc846fae3
1614 changed files with 162035 additions and 0 deletions

View File

@@ -0,0 +1,373 @@
"use strict";
const common_vendor = require("../../../../common/vendor.js");
const uni_modules_nutuiUni_components__constants_event = require("../_constants/event.js");
const uni_modules_nutuiUni_components__constants_prefix = require("../_constants/prefix.js");
const uni_modules_nutuiUni_components__utils_env = require("../_utils/env.js");
const uni_modules_nutuiUni_components__utils_style = require("../_utils/style.js");
const form = require("../../../../form.js");
const uni_modules_nutuiUni_components__utils_is = require("../_utils/is.js");
const uni_modules_nutuiUni_components__utils_props = require("../_utils/props.js");
const uni_modules_nutuiUni_components_input_util = require("./util.js");
const inputProps = {
...uni_modules_nutuiUni_components__utils_props.commonProps,
/**
* @description 输入框类型,支持原生 `input` 标签的所有 `type` 属性,另外还支持 `number` `digit`
*/
type: uni_modules_nutuiUni_components__utils_props.makeStringProp("text"),
/**
* @description 输入值,双向绑定
*/
modelValue: uni_modules_nutuiUni_components__utils_props.makeNumericProp(""),
/**
* @description 输入框自定义类名
*/
inputClass: {
type: [String, Object, Array],
default: ""
},
/**
* @description 输入框自定义样式
*/
inputStyle: {
type: [String, Object, Array],
default: ""
},
/**
* @description 输入框为空时占位符
*/
placeholder: uni_modules_nutuiUni_components__utils_props.makeStringProp(""),
/**
* @description 指定 placeholder 的样式
*/
placeholderStyle: uni_modules_nutuiUni_components__utils_props.makeStringProp(""),
/**
* @description 指定 placeholder 的样式类
*/
placeholderClass: uni_modules_nutuiUni_components__utils_props.makeStringProp("input-placeholder"),
/**
* @description 输入框内容对齐方式,可选值 `left`、`center`、`right`
*/
inputAlign: uni_modules_nutuiUni_components__utils_props.makeStringProp("left"),
/**
* @description 是否显示必填字段的标签旁边的红色星号
*/
required: Boolean,
/**
* @description 是否禁用
*/
disabled: uni_modules_nutuiUni_components__utils_props.nullableBooleanProp,
/**
* @description 是否只读
*/
readonly: Boolean,
/**
* @description 是否标红
*/
error: Boolean,
/**
* @description 限制最长输入字符
*/
maxLength: uni_modules_nutuiUni_components__utils_props.makeNumericProp(140),
/**
* @description 展示清除 `Icon`
*/
clearable: Boolean,
/**
* @description 清除图标的 `font-size` 大小
*/
clearSize: uni_modules_nutuiUni_components__utils_props.makeNumericProp("14"),
/**
* @description 是否显示下边框
*/
border: uni_modules_nutuiUni_components__utils_props.truthProp,
/**
* @description 格式化函数触发的时机,可选值为 `onChange`、`onBlur`
*/
formatTrigger: uni_modules_nutuiUni_components__utils_props.makeStringProp("onChange"),
/**
* @description 输入内容格式化函数
*/
formatter: {
type: Function,
default: null
},
/**
* @description 是否显示限制最长输入字符,需要设置 `max-length` 属性
*/
showWordLimit: Boolean,
/**
* @description 是否自动获得焦点,`iOS` 系统不支持该属性
*/
autofocus: Boolean,
/**
* @description 键盘右下角按钮的文字,仅在`type='text'`时生效,可选值 `send`:发送、`search`:搜索、`next`:下一个、`go`:前往、`done`:完成
*/
confirmType: uni_modules_nutuiUni_components__utils_props.makeStringProp("done"),
/**
* @description 键盘弹起时,是否自动上推页面
*/
adjustPosition: uni_modules_nutuiUni_components__utils_props.truthProp,
/**
* @description 是否强制使用系统键盘和 `Web-view` 创建的 `input` 元素。为 `true` 时,`confirm-type`、`confirm-hold` 可能失效
*/
alwaysSystem: Boolean,
/**
* @description 是否在失去焦点后,继续展示清除按钮,在设置 `clearable` 时生效
*/
showClearIcon: Boolean,
/**
* @description 输入框模式
*/
inputMode: uni_modules_nutuiUni_components__utils_props.makeStringProp("text"),
/**
* @description 指定光标与键盘的距离,取 input 距离底部的距离和 cursor-spacing 指定的距离的最小值作为光标与键盘的距离
*/
cursorSpacing: uni_modules_nutuiUni_components__utils_props.makeNumberProp(0),
/**
* @description 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效)
*/
alwaysEmbed: Boolean,
/**
* @description 点击键盘右下角按钮时是否保持键盘不收起
*/
confirmHold: Boolean,
/**
* @description 指定focus时的光标位置
*/
cursor: Number,
/**
* @description 光标起始位置自动聚集时有效需与selection-end搭配使用
*/
selectionStart: uni_modules_nutuiUni_components__utils_props.makeNumberProp(-1),
/**
* @description 光标结束位置自动聚集时有效需与selection-start搭配使用
*/
selectionEnd: uni_modules_nutuiUni_components__utils_props.makeNumberProp(-1),
/**
* @description focus时点击页面的时候不收起键盘
*/
holdKeyboard: Boolean
};
const inputEmits = {
[uni_modules_nutuiUni_components__constants_event.CLICK_EVENT]: (evt) => evt instanceof Object,
clickInput: (evt) => evt instanceof Object,
[uni_modules_nutuiUni_components__constants_event.BLUR_EVENT]: (evt) => evt instanceof Object,
[uni_modules_nutuiUni_components__constants_event.FOCUS_EVENT]: (evt) => evt instanceof Object,
[uni_modules_nutuiUni_components__constants_event.CLEAR_EVENT]: () => true,
[uni_modules_nutuiUni_components__constants_event.CONFIRM_EVENT]: (evt) => evt instanceof Object,
[uni_modules_nutuiUni_components__constants_event.UPDATE_MODEL_EVENT]: (val1, val2) => (uni_modules_nutuiUni_components__utils_is.isString(val1) || uni_modules_nutuiUni_components__utils_is.isNumber(val1)) && (val2 instanceof Object || val2 === void 0),
[uni_modules_nutuiUni_components__constants_event.INPUT_EVENT]: (val, evt) => (uni_modules_nutuiUni_components__utils_is.isString(val) || uni_modules_nutuiUni_components__utils_is.isNumber(val)) && evt instanceof Object
};
if (!Math) {
NutIcon();
}
const NutIcon = () => "../icon/icon.js";
const componentName = `${uni_modules_nutuiUni_components__constants_prefix.PREFIX}-input`;
const __default__ = common_vendor.defineComponent({
name: componentName,
options: {
virtualHost: true,
addGlobalClass: true,
styleIsolation: "shared"
}
});
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
...__default__,
props: inputProps,
emits: inputEmits,
setup(__props, { emit: __emit }) {
const props = __props;
const emit = __emit;
const slots = common_vendor.useSlots();
function hasSlot(name) {
return Boolean(slots[name]);
}
const formDisabled = form.useFormDisabled(common_vendor.toRef(props, "disabled"));
function stringModelValue() {
if (props.modelValue == null)
return "";
return String(props.modelValue);
}
const innerValue = common_vendor.computed(() => {
return stringModelValue();
});
const classes = common_vendor.computed(() => {
return uni_modules_nutuiUni_components__utils_style.getMainClass(props, componentName, {
[`${componentName}--disabled`]: formDisabled.value,
[`${componentName}--required`]: props.required,
[`${componentName}--error`]: props.error,
[`${componentName}--border`]: props.border
});
});
const inputStyles = common_vendor.computed(() => {
return [props.inputStyle, {
textAlign: props.inputAlign
}];
});
const innerMaxLength = common_vendor.computed(() => {
if (props.maxLength == null)
return -1;
return Number(props.maxLength);
});
function updateValue(value, trigger = "onChange") {
if (innerMaxLength.value > 0 && value.length > innerMaxLength.value)
value = value.slice(0, innerMaxLength.value);
if (props.type === "number")
value = uni_modules_nutuiUni_components_input_util.formatNumber(value, false, false);
if (props.type === "digit")
value = uni_modules_nutuiUni_components_input_util.formatNumber(value, true, true);
if (props.formatter && trigger === props.formatTrigger)
value = props.formatter(value);
emit(uni_modules_nutuiUni_components__constants_event.UPDATE_MODEL_EVENT, value);
}
function _onInput(evt) {
updateValue(evt.detail.value);
common_vendor.nextTick$1(() => {
emit(uni_modules_nutuiUni_components__constants_event.INPUT_EVENT, innerValue.value, evt);
});
}
function handleInput(evt) {
if (uni_modules_nutuiUni_components__utils_env.isH5) {
const target = evt.target;
if (!target.composing)
_onInput(evt);
} else {
_onInput(evt);
}
}
function handleClick(evt) {
emit(uni_modules_nutuiUni_components__constants_event.CLICK_EVENT, evt);
}
function handleClickInput(evt) {
if (formDisabled.value)
return;
emit("clickInput", evt);
}
const active = common_vendor.ref(false);
const clearing = common_vendor.ref(false);
function handleFocus(evt) {
if (formDisabled.value || props.readonly)
return;
emit(uni_modules_nutuiUni_components__constants_event.FOCUS_EVENT, evt);
active.value = true;
}
function handleBlur(evt) {
if (formDisabled.value || props.readonly)
return;
emit(uni_modules_nutuiUni_components__constants_event.BLUR_EVENT, evt);
setTimeout(() => {
active.value = false;
}, 200);
if (clearing.value) {
clearing.value = false;
return;
}
updateValue(evt.detail.value, "onBlur");
}
function handleConfirm(evt) {
emit(uni_modules_nutuiUni_components__constants_event.CONFIRM_EVENT, evt);
}
function handleClear(evt) {
if (formDisabled.value)
return;
emit(uni_modules_nutuiUni_components__constants_event.UPDATE_MODEL_EVENT, "", evt);
emit(uni_modules_nutuiUni_components__constants_event.CLEAR_EVENT);
clearing.value = true;
}
function startComposing(evt) {
if (uni_modules_nutuiUni_components__utils_env.isH5) {
const target = evt.target;
target.composing = true;
}
}
function endComposing(evt) {
if (uni_modules_nutuiUni_components__utils_env.isH5) {
const target = evt.target;
if (target.composing) {
target.composing = false;
target.dispatchEvent(new Event("input"));
}
}
}
common_vendor.watch(
() => props.modelValue,
(value) => {
if (value === innerValue.value)
return;
updateValue(stringModelValue());
}
);
common_vendor.onMounted(() => {
updateValue(stringModelValue(), props.formatTrigger);
});
return (_ctx, _cache) => {
return common_vendor.e({
a: hasSlot("left")
}, hasSlot("left") ? {} : {}, {
b: common_vendor.n(props.inputClass),
c: common_vendor.s(inputStyles.value),
d: innerValue.value,
e: props.type,
f: props.placeholder,
g: props.placeholderStyle,
h: props.placeholderClass,
i: common_vendor.unref(formDisabled),
j: props.readonly,
k: props.autofocus,
l: innerMaxLength.value,
m: props.formatTrigger,
n: props.autofocus ? true : void 0,
o: props.confirmType,
p: props.adjustPosition,
q: props.alwaysSystem,
r: props.inputMode,
s: props.cursorSpacing,
t: props.alwaysEmbed,
v: props.confirmHold,
w: props.cursor,
x: props.selectionStart,
y: props.selectionEnd,
z: props.holdKeyboard,
A: common_vendor.o(handleInput),
B: common_vendor.o(handleFocus),
C: common_vendor.o(handleBlur),
D: common_vendor.o(handleClickInput),
E: common_vendor.o(endComposing),
F: common_vendor.o(startComposing),
G: common_vendor.o(endComposing),
H: common_vendor.o(handleConfirm),
I: props.readonly
}, props.readonly ? {
J: common_vendor.o(handleClickInput)
} : {}, {
K: props.showWordLimit && innerMaxLength.value > 0
}, props.showWordLimit && innerMaxLength.value > 0 ? {
L: common_vendor.t(innerValue.value.length),
M: common_vendor.t(innerMaxLength.value)
} : {}, {
N: props.clearable && !props.readonly
}, props.clearable && !props.readonly ? common_vendor.e({
O: hasSlot("clear")
}, hasSlot("clear") ? {} : {
P: common_vendor.p({
name: "mask-close",
["custom-class"]: "nut-input__clear-icon",
size: props.clearSize,
width: props.clearSize,
height: props.clearSize
})
}, {
Q: !((active.value || props.showClearIcon) && innerValue.value.length > 0) ? 1 : "",
R: common_vendor.o(handleClear)
}) : {}, {
S: hasSlot("right")
}, hasSlot("right") ? {} : {}, {
T: common_vendor.n(classes.value),
U: common_vendor.s(props.customStyle),
V: common_vendor.o(handleClick)
});
};
}
});
wx.createComponent(_sfc_main);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/nutui-uni/components/input/input.js.map

View File

@@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"nut-icon": "../icon/icon"
}
}

View File

@@ -0,0 +1 @@
<view class="{{T}}" style="{{U}}" bindtap="{{V}}"><view wx:if="{{a}}" class="nut-input__left"><slot name="left"/></view><view class="nut-input__value"><block wx:if="{{r0}}"><input class="{{['nut-input__input', b]}}" style="{{c}}" value="{{d}}" type="{{e}}" placeholder="{{f}}" placeholder-style="{{g}}" placeholder-class="{{h}}" disabled="{{i}}" readonly="{{j}}" focus="{{k}}" maxlength="{{l}}" format-trigger="{{m}}" auto-blur="{{n}}" confirm-type="{{o}}" adjust-position="{{p}}" always-system="{{q}}" inputmode="{{r}}" cursor-spacing="{{s}}" always-embed="{{t}}" confirm-hold="{{v}}" cursor="{{w}}" selection-start="{{x}}" selection-end="{{y}}" hold-keyboard="{{z}}" bindinput="{{A}}" bindfocus="{{B}}" bindblur="{{C}}" bindtap="{{D}}" bindchange="{{E}}" bindcompositionstart="{{F}}" bindcompositionend="{{G}}" bindconfirm="{{H}}"></input></block><view wx:if="{{I}}" class="nut-input__mask" bindtap="{{J}}"/><view wx:if="{{K}}" class="nut-input__word-limit"><text class="nut-input__word-num">{{L}}</text>/{{M}}</view></view><view wx:if="{{N}}" class="{{['nut-input__clear', Q && 'nut-hidden']}}" catchtap="{{R}}"><slot wx:if="{{O}}" name="clear"/><nut-icon wx:else u-i="0910be30-0" bind:__l="__l" u-p="{{P||''}}"/></view><view wx:if="{{S}}" class="nut-input__right"><slot name="right"/></view></view>

View File

@@ -0,0 +1,154 @@
/**
* 这里是uni-app内置的常用样式变量
*
* uni-app 官方扩展插件及插件市场https://ext.dcloud.net.cn上很多三方插件均使用了这些样式变量
* 如果你是插件开发者建议你使用scss预处理并在插件代码中直接使用这些变量无需 import 这个文件方便用户通过搭积木的方式开发整体风格一致的App
*
*/
/**
* 如果你是App开发者插件使用者你可以通过修改这些变量来定制自己的插件主题实现自定义主题功能
*
* 如果你的项目同样使用了scss预处理你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
*/
/* 颜色变量 */
/* 行为相关颜色 */
/* 文字基本颜色 */
/* 背景颜色 */
/* 边框颜色 */
/* 尺寸变量 */
/* 文字尺寸 */
/* 图片尺寸 */
/* Border Radius */
/* 水平间距 */
/* 垂直间距 */
/* 透明度 */
/* 文章场景相关 */
/**
* 这里是uni-app内置的常用样式变量
*
* uni-app 官方扩展插件及插件市场https://ext.dcloud.net.cn上很多三方插件均使用了这些样式变量
* 如果你是插件开发者建议你使用scss预处理并在插件代码中直接使用这些变量无需 import 这个文件方便用户通过搭积木的方式开发整体风格一致的App
*
*/
/**
* 如果你是App开发者插件使用者你可以通过修改这些变量来定制自己的插件主题实现自定义主题功能
*
* 如果你的项目同样使用了scss预处理你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
*/
/* 颜色变量 */
/* 行为相关颜色 */
/* 文字基本颜色 */
/* 背景颜色 */
/* 边框颜色 */
/* 尺寸变量 */
/* 文字尺寸 */
/* 图片尺寸 */
/* Border Radius */
/* 水平间距 */
/* 垂直间距 */
/* 透明度 */
/* 文章场景相关 */
.nut-theme-dark .nut-input {
background: var(--nut-dark-background, #131313);
}
.nut-theme-dark .nut-input__input {
color: var(--nut-dark-color, var(--nut-white, #fff));
}
.nut-input {
position: relative;
box-sizing: border-box;
display: flex;
width: 100%;
padding: var(--nut-input-padding, 10px 25px);
font-size: var(--nut-input-font-size, var(--nut-font-size-2, 14px));
line-height: var(--nut-input-line-height, 20px);
background: var(--nut-white, #fff);
}
.nut-input__left, .nut-input__right {
position: relative;
display: flex;
align-items: center;
}
.nut-input__left {
margin-right: 4px;
}
.nut-input__right {
margin-left: 4px;
}
.nut-input__value {
position: relative;
display: flex;
flex: 1;
align-items: center;
}
.nut-input__input {
flex: 1;
padding: 0;
font-size: inherit;
line-height: inherit;
text-align: left;
text-decoration: none;
resize: none;
background: transparent;
border: 0;
outline: 0 none;
}
.nut-input__mask {
position: absolute;
top: 0;
left: 0;
z-index: 1;
width: 100%;
height: 100%;
}
.nut-input__word-limit {
display: flex;
justify-content: flex-end;
padding: 0 10px;
font-size: var(--nut-input-limit-font-size, var(--nut-font-size-1, 12px));
color: var(--nut-input-limit-color, #808080);
}
.nut-input__clear {
display: flex;
align-items: center;
}
.nut-input__clear-icon {
width: 16px;
height: 16px;
margin: 0 4px;
line-height: 1;
color: #c8c9cc;
cursor: pointer;
}
.nut-input--disabled {
color: var(--nut-input-disabled-color, #c8c9cc) !important;
}
.nut-input--disabled input:disabled {
color: var(--nut-input-disabled-color, #c8c9cc);
cursor: not-allowed;
background: none;
opacity: 1;
-webkit-text-fill-color: var(--nut-input-disabled-color, #c8c9cc);
}
.nut-input--required::before {
position: absolute;
left: 14px;
color: var(--nut-input-required-color, var(--nut-required-color, #fa2c19));
content: "*";
}
.nut-input--error::-webkit-input-placeholder {
color: var(--nut-input-required-color, var(--nut-required-color, #fa2c19));
-webkit-text-fill-color: var(--nut-input-required-color, var(--nut-required-color, #fa2c19));
}
.nut-input--error, .nut-input--error::placeholder {
color: var(--nut-input-required-color, var(--nut-required-color, #fa2c19));
-webkit-text-fill-color: var(--nut-input-required-color, var(--nut-required-color, #fa2c19));
}
.nut-input--border {
border-bottom: 1px solid var(--nut-input-border-bottom, #eaf0fb);
}
.nut-form-item .nut-input {
padding: 0;
margin: 0;
line-height: var(--nut-cell-line-height);
}

View File

@@ -0,0 +1,23 @@
"use strict";
function trimExtraChar(value, char, regExp) {
const index = value.indexOf(char);
if (index === -1)
return value;
if (char === "-" && index !== 0)
return value.slice(0, index);
return value.slice(0, index + 1) + value.slice(index).replace(regExp, "");
}
function formatNumber(value, allowDot = true, allowMinus = true) {
if (allowDot)
value = trimExtraChar(value, ".", /\./g);
else
value = value.split(".")[0];
if (allowMinus)
value = trimExtraChar(value, "-", /-/g);
else
value = value.replace(/-/, "");
const regExp = allowDot ? /[^-0-9.]/g : /[^-0-9]/g;
return value.replace(regExp, "");
}
exports.formatNumber = formatNumber;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/nutui-uni/components/input/util.js.map