From 500f7dc7482ec85a73ff5229f2fc1316bd4bc591 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Sun, 24 Apr 2022 10:38:58 +0800 Subject: [PATCH] 调整在线测试图片地址 --- forms/input/CInput.vue | 64 +++++++++++++++++++++++++------- 1 files changed, 50 insertions(+), 14 deletions(-) diff --git a/forms/input/CInput.vue b/forms/input/CInput.vue index 86acc3e..ca251f7 100644 --- a/forms/input/CInput.vue +++ b/forms/input/CInput.vue @@ -1,25 +1,36 @@ /** - * 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" + :value="value" + :onChange="evt => hanldeChange(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 +38,34 @@ 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: { + hanldeChange(evt) { + // 小程序中,可以粘贴换行符进来 + const changeValue = (evt || '').replace(/[\n\r]/g, ''); + this.itemRes.onChange(changeValue); + }, }, mounted() {}, }; -- Gitblit v1.9.1