From 9d5803a79aad859e201b94040e369298c7c348b0 Mon Sep 17 00:00:00 2001 From: chensiAb <chenchenco03@163.com> Date: Fri, 23 Aug 2024 10:59:53 +0800 Subject: [PATCH] fix:兼容加载失败时&没数据时,页面显示暂无数据 --- forms/input/CInput.vue | 29 ++++++++++++++++++++++++++--- 1 files changed, 26 insertions(+), 3 deletions(-) diff --git a/forms/input/CInput.vue b/forms/input/CInput.vue index 171f765..211d760 100644 --- a/forms/input/CInput.vue +++ b/forms/input/CInput.vue @@ -6,7 +6,7 @@ <template> <view class="c-input" - :class="unit?'c-input-unit':''" + :class="[unit?'c-input-unit':'', readOnly?'read-only':'']" > <AtInput :name="itemRes.name" @@ -15,8 +15,9 @@ :placeholder="placeholder" :required="itemRes.required" :error="itemRes.error" - :value="itemRes.formData[itemRes.name]" - :onChange="evt=>itemRes.onChange(evt)" + :cursorSpacing="0" + :value="value" + :onChange="evt => handleChange(evt)" > <slot v-if="!unit" /> <text @@ -45,6 +46,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