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

267 lines
11 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_wdTextarea_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-textarea",
options: {
virtualHost: true,
addGlobalClass: true,
styleIsolation: "shared"
}
};
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
...__default__,
props: uni_modules_wotDesignUni_components_wdTextarea_types.textareaProps,
emits: [
"update:modelValue",
"clear",
"blur",
"focus",
"input",
"keyboardheightchange",
"confirm",
"linechange",
"clickprefixicon",
"click"
],
setup(__props, { emit }) {
const props = __props;
const { translate } = uni_modules_wotDesignUni_components_composables_useTranslate.useTranslate("textarea");
const slots = common_vendor.useSlots();
const placeholderValue = common_vendor.computed$1(() => {
return uni_modules_wotDesignUni_components_common_util.isDef(props.placeholder) ? props.placeholder : translate("placeholder");
});
const clearing = common_vendor.ref(false);
const focused = common_vendor.ref(false);
const focusing = common_vendor.ref(false);
const inputValue = common_vendor.ref("");
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) : "";
},
{ immediate: true, deep: true }
);
const { parent: form } = uni_modules_wotDesignUni_components_composables_useParent.useParent(uni_modules_wotDesignUni_components_wdForm_types.FORM_KEY);
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 currentLength = common_vendor.computed$1(() => {
return Array.from(String(formatValue(props.modelValue))).length;
});
const rootClass = common_vendor.computed$1(() => {
return `wd-textarea ${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" : ""} ${props.autoHeight ? "is-auto-height" : ""} ${currentLength.value > 0 ? "is-not-empty" : ""} ${props.noBorder ? "is-no-border" : ""} ${props.customClass}`;
});
common_vendor.computed$1(() => {
return `wd-textarea__label ${props.customLabelClass}`;
});
const inputPlaceholderClass = common_vendor.computed$1(() => {
return `wd-textarea__placeholder ${props.placeholderClass}`;
});
const countClass = common_vendor.computed$1(() => {
return `${currentLength.value > 0 ? "wd-textarea__count-current" : ""} ${currentLength.value > props.maxlength ? "is-error" : ""}`;
});
const labelStyle = common_vendor.computed$1(() => {
return props.labelWidth ? uni_modules_wotDesignUni_components_common_util.objToStyle({
"min-width": props.labelWidth,
"max-width": props.labelWidth
}) : "";
});
common_vendor.onBeforeMount(() => {
initState();
});
function initState() {
inputValue.value = formatValue(inputValue.value);
emit("update:modelValue", inputValue.value);
}
function formatValue(value) {
if (value === null || value === void 0)
return "";
const { maxlength, showWordLimit } = props;
if (showWordLimit && maxlength !== -1 && String(value).length > maxlength) {
return value.toString().substring(0, maxlength);
}
return `${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({ detail }) {
await uni_modules_wotDesignUni_components_common_util.pause(150);
if (clearing.value) {
clearing.value = false;
return;
}
focusing.value = false;
emit("blur", {
value: inputValue.value,
cursor: detail.cursor ? detail.cursor : null
});
}
function handleFocus({ detail }) {
focusing.value = true;
emit("focus", detail);
}
function handleInput({ detail }) {
inputValue.value = formatValue(inputValue.value);
emit("update:modelValue", inputValue.value);
emit("input", detail);
}
function handleKeyboardheightchange({ detail }) {
emit("keyboardheightchange", detail);
}
function handleConfirm({ detail }) {
emit("confirm", detail);
}
function handleLineChange({ detail }) {
emit("linechange", detail);
}
function onClickPrefixIcon() {
emit("clickprefixicon");
}
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-textarea__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.s(common_vendor.unref(labelStyle))
}) : {}, {
l: common_vendor.n(`wd-textarea__inner ${_ctx.customTextareaClass}`),
m: common_vendor.unref(placeholderValue),
n: _ctx.disabled || _ctx.readonly,
o: _ctx.maxlength,
p: focused.value,
q: _ctx.autoFocus,
r: _ctx.placeholderStyle,
s: common_vendor.unref(inputPlaceholderClass),
t: _ctx.autoHeight,
v: _ctx.cursorSpacing,
w: _ctx.fixed,
x: _ctx.cursor,
y: _ctx.showConfirmBar,
z: _ctx.selectionStart,
A: _ctx.selectionEnd,
B: _ctx.adjustPosition,
C: _ctx.holdKeyboard,
D: _ctx.confirmType,
E: _ctx.confirmHold,
F: _ctx.disableDefaultPadding,
G: _ctx.ignoreCompositionEvent,
H: _ctx.inputmode,
I: common_vendor.o([($event) => inputValue.value = $event.detail.value, handleInput]),
J: common_vendor.o(handleFocus),
K: common_vendor.o(handleBlur),
L: common_vendor.o(handleConfirm),
M: common_vendor.o(handleLineChange),
N: common_vendor.o(handleKeyboardheightchange),
O: inputValue.value,
P: common_vendor.unref(errorMessage)
}, common_vendor.unref(errorMessage) ? {
Q: common_vendor.t(common_vendor.unref(errorMessage))
} : {}, {
R: props.readonly
}, props.readonly ? {} : {}, {
S: common_vendor.unref(showClear)
}, common_vendor.unref(showClear) ? {
T: common_vendor.o(handleClear),
U: common_vendor.p({
["custom-class"]: "wd-textarea__clear",
name: "error-fill"
})
} : {}, {
V: common_vendor.unref(showWordCount)
}, common_vendor.unref(showWordCount) ? {
W: common_vendor.t(common_vendor.unref(currentLength)),
X: common_vendor.n(common_vendor.unref(countClass)),
Y: common_vendor.t(_ctx.maxlength)
} : {}, {
Z: common_vendor.n(`wd-textarea__value ${common_vendor.unref(showClear) ? "is-suffix" : ""} ${_ctx.customTextareaContainerClass} ${common_vendor.unref(showWordCount) ? "is-show-limit" : ""}`),
aa: common_vendor.n(common_vendor.unref(rootClass)),
ab: common_vendor.s(_ctx.customStyle)
});
};
}
});
var Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2b9f99c9"], ["__file", "D:/\u7F51\u6291\u4E91Time/\u79C1\u6D3B/2000\u7B97\u5366/src/uni_modules/wot-design-uni/components/wd-textarea/wd-textarea.vue"]]);
wx.createComponent(Component);