From 4c07e237a361e9371d1df6ebd3f7a16db94a62b2 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Mon, 20 Mar 2023 16:54:17 +0800 Subject: [PATCH] 修复二维码组件性能消耗过大的问题 --- forms/input/CInput.vue | 65 ++++++++++++++++++++++++++------ 1 files changed, 52 insertions(+), 13 deletions(-) diff --git a/forms/input/CInput.vue b/forms/input/CInput.vue index c09081c..7c8d604 100644 --- a/forms/input/CInput.vue +++ b/forms/input/CInput.vue @@ -1,25 +1,36 @@ /** - * CInput + * CInput - 表单项,文本输入框 * @author Tevin */ <template> - <AtInput - :name="itemData.name" - :title="itemData.label" - :type="type" - :placeholder="placeholder" - :required="itemData.required" - :error="itemData.error" - :value="itemData.formData[itemData.name]" - :onChange="evt=>itemData.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,37 @@ AtInput, }, props: { + // 表单数据资源(表单组件内部机制专用) + itemRes: Object, + // 输入框类型,text、number、password、phone、idcard、digit type: String, + // 占位提示 placeholder: String, - itemData: Object, + // 输入框单位 + 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(/^\s+|\s+$/g, '') + .replace(/[\n\r\t]/g, ''); + this.itemRes.onChange(changeValue); + }, + }, + mounted() {}, }; </script> \ No newline at end of file -- Gitblit v1.9.1