2026-03-31 16:44:41 +08:00

296 lines
12 KiB
JavaScript

"use strict";
var common_vendor = require("../../../../common/vendor.js");
var uni_modules_wotDesignUni_components_common_util = require("../common/util.js");
var uni_modules_wotDesignUni_components_composables_useCell = require("../composables/useCell.js");
var uni_modules_wotDesignUni_components_wdForm_types = require("../wd-form/types.js");
var uni_modules_wotDesignUni_components_composables_useParent = require("../composables/useParent.js");
var uni_modules_wotDesignUni_components_composables_useTranslate = require("../composables/useTranslate.js");
var uni_modules_wotDesignUni_components_wdInput_types = require("./types.js");
require("../common/AbortablePromise.js");
require("../wd-cell-group/types.js");
require("../common/props.js");
require("../../locale/index.js");
require("../../locale/lang/zh-CN.js");
if (!Math) {
wdIcon();
}
const wdIcon = () => "../wd-icon/wd-icon.js";
const __default__ = {
name: "wd-input",
options: {
virtualHost: true,
addGlobalClass: true,
styleIsolation: "shared"
}
};
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
...__default__,
props: uni_modules_wotDesignUni_components_wdInput_types.inputProps,
emits: [
"update:modelValue",
"clear",
"blur",
"focus",
"input",
"keyboardheightchange",
"confirm",
"clicksuffixicon",
"clickprefixicon",
"click"
],
setup(__props, { emit }) {
const props = __props;
const slots = common_vendor.useSlots();
const { translate } = uni_modules_wotDesignUni_components_composables_useTranslate.useTranslate("input");
const isPwdVisible = common_vendor.ref(false);
const clearing = common_vendor.ref(false);
const focused = common_vendor.ref(false);
const focusing = common_vendor.ref(false);
const inputValue = common_vendor.ref(getInitValue());
const cell = uni_modules_wotDesignUni_components_composables_useCell.useCell();
common_vendor.watch(
() => props.focus,
(newValue) => {
focused.value = newValue;
},
{ immediate: true, deep: true }
);
common_vendor.watch(
() => props.modelValue,
(newValue) => {
inputValue.value = uni_modules_wotDesignUni_components_common_util.isDef(newValue) ? String(newValue) : "";
}
);
const { parent: form } = uni_modules_wotDesignUni_components_composables_useParent.useParent(uni_modules_wotDesignUni_components_wdForm_types.FORM_KEY);
const placeholderValue = common_vendor.computed$1(() => {
return uni_modules_wotDesignUni_components_common_util.isDef(props.placeholder) ? props.placeholder : translate("placeholder");
});
const showClear = common_vendor.computed$1(() => {
const { disabled, readonly, clearable, clearTrigger } = props;
if (clearable && !readonly && !disabled && inputValue.value && (clearTrigger === "always" || props.clearTrigger === "focus" && focusing.value)) {
return true;
} else {
return false;
}
});
const showWordCount = common_vendor.computed$1(() => {
const { disabled, readonly, maxlength, showWordLimit } = props;
return Boolean(!disabled && !readonly && uni_modules_wotDesignUni_components_common_util.isDef(maxlength) && maxlength > -1 && showWordLimit);
});
const errorMessage = common_vendor.computed$1(() => {
if (form && props.prop && form.errorMessages && form.errorMessages[props.prop]) {
return form.errorMessages[props.prop];
} else {
return "";
}
});
const isRequired = common_vendor.computed$1(() => {
let formRequired = false;
if (form && form.props.rules) {
const rules = form.props.rules;
for (const key in rules) {
if (Object.prototype.hasOwnProperty.call(rules, key) && key === props.prop && Array.isArray(rules[key])) {
formRequired = rules[key].some((rule) => rule.required);
}
}
}
return props.required || props.rules.some((rule) => rule.required) || formRequired;
});
const rootClass = common_vendor.computed$1(() => {
return `wd-input ${props.label || slots.label ? "is-cell" : ""} ${props.center ? "is-center" : ""} ${cell.border.value ? "is-border" : ""} ${props.size ? "is-" + props.size : ""} ${props.error ? "is-error" : ""} ${props.disabled ? "is-disabled" : ""} ${inputValue.value && String(inputValue.value).length > 0 ? "is-not-empty" : ""} ${props.noBorder ? "is-no-border" : ""} ${props.customClass}`;
});
const labelClass = common_vendor.computed$1(() => {
return `wd-input__label ${props.customLabelClass}`;
});
const inputPlaceholderClass = common_vendor.computed$1(() => {
return `wd-input__placeholder ${props.placeholderClass}`;
});
const labelStyle = common_vendor.computed$1(() => {
return props.labelWidth ? uni_modules_wotDesignUni_components_common_util.objToStyle({
"min-width": props.labelWidth,
"max-width": props.labelWidth
}) : "";
});
function getInitValue() {
const formatted = formatValue(props.modelValue);
if (!isValueEqual(formatted, props.modelValue)) {
emit("update:modelValue", formatted);
}
return formatted;
}
function formatValue(value) {
const { maxlength } = props;
if (uni_modules_wotDesignUni_components_common_util.isDef(maxlength) && maxlength !== -1 && String(value).length > maxlength) {
return value.toString().slice(0, maxlength);
}
return value;
}
function togglePwdVisible() {
isPwdVisible.value = !isPwdVisible.value;
}
async function handleClear() {
focusing.value = false;
inputValue.value = "";
if (props.focusWhenClear) {
clearing.value = true;
focused.value = false;
}
await uni_modules_wotDesignUni_components_common_util.pause();
if (props.focusWhenClear) {
focused.value = true;
focusing.value = true;
}
emit("update:modelValue", inputValue.value);
emit("clear");
}
async function handleBlur() {
await uni_modules_wotDesignUni_components_common_util.pause(150);
if (clearing.value) {
clearing.value = false;
return;
}
focusing.value = false;
emit("blur", {
value: inputValue.value
});
}
function handleFocus({ detail }) {
focusing.value = true;
emit("focus", detail);
}
function handleInput({ detail }) {
emit("update:modelValue", inputValue.value);
emit("input", detail);
}
function handleKeyboardheightchange({ detail }) {
emit("keyboardheightchange", detail);
}
function handleConfirm({ detail }) {
emit("confirm", detail);
}
function onClickSuffixIcon() {
emit("clicksuffixicon");
}
function onClickPrefixIcon() {
emit("clickprefixicon");
}
function handleClick(event) {
emit("click", event);
}
function isValueEqual(value1, value2) {
return uni_modules_wotDesignUni_components_common_util.isEqual(String(value1), String(value2));
}
return (_ctx, _cache) => {
return common_vendor.e({
a: _ctx.label || _ctx.$slots.label
}, _ctx.label || _ctx.$slots.label ? common_vendor.e({
b: common_vendor.unref(isRequired) && _ctx.markerSide === "before"
}, common_vendor.unref(isRequired) && _ctx.markerSide === "before" ? {} : {}, {
c: _ctx.prefixIcon || _ctx.$slots.prefix
}, _ctx.prefixIcon || _ctx.$slots.prefix ? common_vendor.e({
d: _ctx.prefixIcon && !_ctx.$slots.prefix
}, _ctx.prefixIcon && !_ctx.$slots.prefix ? {
e: common_vendor.o(onClickPrefixIcon),
f: common_vendor.p({
["custom-class"]: "wd-input__icon",
name: _ctx.prefixIcon
})
} : {}) : {}, {
g: _ctx.label && !_ctx.$slots.label
}, _ctx.label && !_ctx.$slots.label ? {
h: common_vendor.t(_ctx.label)
} : _ctx.$slots.label ? {} : {}, {
i: _ctx.$slots.label,
j: common_vendor.unref(isRequired) && _ctx.markerSide === "after"
}, common_vendor.unref(isRequired) && _ctx.markerSide === "after" ? {} : {}, {
k: common_vendor.n(common_vendor.unref(labelClass)),
l: common_vendor.s(common_vendor.unref(labelStyle))
}) : {}, {
m: (_ctx.prefixIcon || _ctx.$slots.prefix) && !_ctx.label
}, (_ctx.prefixIcon || _ctx.$slots.prefix) && !_ctx.label ? common_vendor.e({
n: _ctx.prefixIcon && !_ctx.$slots.prefix
}, _ctx.prefixIcon && !_ctx.$slots.prefix ? {
o: common_vendor.o(onClickPrefixIcon),
p: common_vendor.p({
["custom-class"]: "wd-input__icon",
name: _ctx.prefixIcon
})
} : {}) : {}, {
q: common_vendor.n(_ctx.prefixIcon ? "wd-input__inner--prefix" : ""),
r: common_vendor.n(common_vendor.unref(showWordCount) ? "wd-input__inner--count" : ""),
s: common_vendor.n(_ctx.alignRight ? "is-align-right" : ""),
t: common_vendor.n(_ctx.customInputClass),
v: _ctx.type,
w: _ctx.showPassword && !isPwdVisible.value,
x: common_vendor.unref(placeholderValue),
y: _ctx.disabled || _ctx.readonly,
z: _ctx.maxlength,
A: focused.value,
B: _ctx.confirmType,
C: _ctx.confirmHold,
D: _ctx.cursor,
E: _ctx.cursorSpacing,
F: _ctx.placeholderStyle,
G: _ctx.selectionStart,
H: _ctx.selectionEnd,
I: _ctx.adjustPosition,
J: _ctx.holdKeyboard,
K: _ctx.alwaysEmbed,
L: common_vendor.unref(inputPlaceholderClass),
M: _ctx.ignoreCompositionEvent,
N: _ctx.inputmode,
O: common_vendor.o([($event) => inputValue.value = $event.detail.value, handleInput]),
P: common_vendor.o(handleFocus),
Q: common_vendor.o(handleBlur),
R: common_vendor.o(handleConfirm),
S: common_vendor.o(handleKeyboardheightchange),
T: inputValue.value,
U: props.readonly
}, props.readonly ? {} : {}, {
V: common_vendor.unref(showClear) || _ctx.showPassword || _ctx.suffixIcon || common_vendor.unref(showWordCount) || _ctx.$slots.suffix
}, common_vendor.unref(showClear) || _ctx.showPassword || _ctx.suffixIcon || common_vendor.unref(showWordCount) || _ctx.$slots.suffix ? common_vendor.e({
W: common_vendor.unref(showClear)
}, common_vendor.unref(showClear) ? {
X: common_vendor.o(handleClear),
Y: common_vendor.p({
["custom-class"]: "wd-input__clear",
name: "error-fill"
})
} : {}, {
Z: _ctx.showPassword
}, _ctx.showPassword ? {
aa: common_vendor.o(togglePwdVisible),
ab: common_vendor.p({
["custom-class"]: "wd-input__icon",
name: isPwdVisible.value ? "view" : "eye-close"
})
} : {}, {
ac: common_vendor.unref(showWordCount)
}, common_vendor.unref(showWordCount) ? {
ad: common_vendor.t(String(inputValue.value).length),
ae: common_vendor.n(inputValue.value && String(inputValue.value).length > 0 ? "wd-input__count-current" : ""),
af: common_vendor.n(String(inputValue.value).length > _ctx.maxlength ? "is-error" : ""),
ag: common_vendor.t(_ctx.maxlength)
} : {}, {
ah: _ctx.suffixIcon && !_ctx.$slots.suffix
}, _ctx.suffixIcon && !_ctx.$slots.suffix ? {
ai: common_vendor.o(onClickSuffixIcon),
aj: common_vendor.p({
["custom-class"]: "wd-input__icon",
name: _ctx.suffixIcon
})
} : {}) : {}, {
ak: common_vendor.unref(errorMessage)
}, common_vendor.unref(errorMessage) ? {
al: common_vendor.t(common_vendor.unref(errorMessage))
} : {}, {
am: common_vendor.n(common_vendor.unref(rootClass)),
an: common_vendor.s(_ctx.customStyle),
ao: common_vendor.o(handleClick)
});
};
}
});
var Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-7d365853"], ["__file", "D:/\u7F51\u6291\u4E91Time/\u79C1\u6D3B/2000\u7B97\u5366/src/uni_modules/wot-design-uni/components/wd-input/wd-input.vue"]]);
wx.createComponent(Component);