From 910572f2c2bbd678c3983db0ca4a293fa5c0dd33 Mon Sep 17 00:00:00 2001
From: Tevin <tingquanren@163.com>
Date: Thu, 17 Aug 2023 16:01:04 +0800
Subject: [PATCH] 页面筛选组件,增加单项开关子组件

---
 forms/input/CInput.vue |   69 +++++++++++++++++++++++++++-------
 1 files changed, 54 insertions(+), 15 deletions(-)

diff --git a/forms/input/CInput.vue b/forms/input/CInput.vue
index 38ec252..7c8d604 100644
--- a/forms/input/CInput.vue
+++ b/forms/input/CInput.vue
@@ -1,22 +1,34 @@
 /**
- * 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>
-</template><script>
+        <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';
 
@@ -26,9 +38,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: {
+        hanldeChange(evt) {
+            // 去除首尾空格,小程序中还可以粘贴换行符进来
+            const changeValue = ((evt || '') + '')
+                .replace(/^\s+|\s+$/g, '')
+                .replace(/[\n\r\t]/g, '');
+            this.itemRes.onChange(changeValue);
+        },
     },
     mounted() {},
 };

--
Gitblit v1.9.1