From c4911f853e9c1c3ed6d1aeca934479e9043ec4d1 Mon Sep 17 00:00:00 2001
From: Tevin <tingquanren@163.com>
Date: Mon, 20 Mar 2023 18:41:19 +0800
Subject: [PATCH] 增加跨端通讯,全局通知容错能力

---
 forms/input/CInput.vue |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/forms/input/CInput.vue b/forms/input/CInput.vue
index 95f98ff..7c8d604 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"
@@ -46,15 +46,26 @@
         placeholder: String,
         // 输入框单位
         unit: String,
+        // 只读模式
+        readOnly: {
+            type: Boolean,
+            default: false,
+        },
     },
     computed: {
         value() {
-            return (itemRes.formData[itemRes.name] || '').replace(/[\n\r]/g, '');
+            return ((this.itemRes.formData[this.itemRes.name] || '') + '').replace(
+                /[\n\r]/g,
+                ''
+            );
         },
     },
     methods: {
         hanldeChange(evt) {
-            const changeValue = (evt || '').replace(/[\n\r]/g, '');
+            // 去除首尾空格,小程序中还可以粘贴换行符进来
+            const changeValue = ((evt || '') + '')
+                .replace(/^\s+|\s+$/g, '')
+                .replace(/[\n\r\t]/g, '');
             this.itemRes.onChange(changeValue);
         },
     },

--
Gitblit v1.9.1