WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2022-04-12 7cb91d0efcbff3297de5d8f64948033d13a86142
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':''"
    >
        <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,29 @@
        AtInput,
    },
    props: {
        type: String,
        placeholder: String,
        // 表单数据资源(表单组件内部机制专用)
        itemRes: Object,
        // 输入框类型,text、number、password、phone、idcard、digit
        type: String,
        // 占位提示
        placeholder: String,
        // 输入框单位
        unit: String,
    },
    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() {},
};