From 3b03f87a02458f719e2eb4bf112a13441b427d14 Mon Sep 17 00:00:00 2001 From: ‘chensiAb’ <‘chenchenco03@163.com’> Date: Tue, 25 Mar 2025 13:54:34 +0800 Subject: [PATCH] Merge branch 'master' of ssh://dev.zhiheiot.com:29418/mob-components --- forms/input/CInput.vue | 31 ++++++++++++++++++++++++++++--- 1 files changed, 28 insertions(+), 3 deletions(-) diff --git a/forms/input/CInput.vue b/forms/input/CInput.vue index 0ca5c07..d20866e 100644 --- a/forms/input/CInput.vue +++ b/forms/input/CInput.vue @@ -1,12 +1,14 @@ /** * CInput - 表单项,文本输入框 + * 用于在表单中收集用户的文本输入 + * 支持多种输入类型,可以设置占位提示文本,并且支持显示单位标识 * @author Tevin */ <template> <view class="c-input" - :class="unit?'c-input-unit':''" + :class="[unit?'c-input-unit':'', readOnly?'read-only':'']" > <AtInput :name="itemRes.name" @@ -16,8 +18,9 @@ :required="itemRes.required" :error="itemRes.error" :cursorSpacing="0" - :value="itemRes.formData[itemRes.name]" - :onChange="evt=>itemRes.onChange(evt)" + :cursor="-1" + :value="value" + :onChange="evt => handleChange(evt)" > <slot v-if="!unit" /> <text @@ -46,6 +49,28 @@ placeholder: String, // 输入框单位 unit: String, + // 只读模式 + readOnly: { + type: Boolean, + default: false, + }, + }, + computed: { + value() { + return ((this.itemRes.formData[this.itemRes.name] || '') + '').replace( + /[\n\r]/g, + '', + ); + }, + }, + methods: { + handleChange(evt) { + // 去除首尾空格,小程序中还可以粘贴换行符进来 + const changeValue = ((evt || '') + '') + .replace(/^\s+|\s+$/g, '') + .replace(/[\n\r\t]/g, ''); + this.itemRes.onChange(changeValue); + }, }, mounted() {}, }; -- Gitblit v1.9.1