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 | 69 +++++++++++++++++++++++++++------- 1 files changed, 55 insertions(+), 14 deletions(-) diff --git a/forms/input/CInput.vue b/forms/input/CInput.vue index 86acc3e..d20866e 100644 --- a/forms/input/CInput.vue +++ b/forms/input/CInput.vue @@ -1,25 +1,39 @@ /** - * CInput + * CInput - 表单项,文本输入框 + * 用于在表单中收集用户的文本输入 + * 支持多种输入类型,可以设置占位提示文本,并且支持显示单位标识 * @author Tevin */ <template> - <AtInput - :name="itemRes.name" - :title="itemRes.label" - :type="type" - :placeholder="placeholder" - :required="itemRes.required" - :error="itemRes.error" - :value="itemRes.formData[itemRes.name]" - :onChange="evt=>itemRes.onChange(evt)" + <view + class="c-input" + :class="[unit?'c-input-unit':'', readOnly?'read-only':'']" > - <slot /> - </AtInput> + <AtInput + :name="itemRes.name" + :title="itemRes.label" + :type="type" + :placeholder="placeholder" + :required="itemRes.required" + :error="itemRes.error" + :cursorSpacing="0" + :cursor="-1" + :value="value" + :onChange="evt => handleChange(evt)" + > + <slot v-if="!unit" /> + <text + class="c-input-unit-text" + v-if="unit" + >{{unit}}</text> + </AtInput> + </view> </template> <script> import { AtInput } from 'taro-ui-vue'; +import './cInput.scss'; export default { name: 'CInput', @@ -27,9 +41,36 @@ AtInput, }, props: { - type: String, - placeholder: String, + // 表单数据资源(表单组件内部机制专用) itemRes: Object, + // 输入框类型,text、number、password、phone、idcard、digit + type: String, + // 占位提示 + 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