WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2023-11-22 39a56ab083f707e893bbb38d9284d6c4dc4f081e
forms/datePicker/CDatePicker.vue
@@ -4,7 +4,10 @@
 */
<template>
    <view class="c-date-picker">
    <view
        class="c-date-picker"
        :class="readOnly ? 'read-only':''"
    >
        <CDateRangeAction
            v-if="mode==='dateRange'"
            :value="itemRes.formData[itemRes.name]"
@@ -17,8 +20,17 @@
                :required="itemRes.required"
                :error="itemRes.error"
                :value="itemRes.formData[itemRes.name]"
                :placeholder="placeholder"
            >
                <view class="at-icon at-icon-chevron-right" />
                <view
                    v-show="!readOnly && !showClear"
                    class="at-icon at-icon-chevron-right"
                />
                <view
                    v-show="!readOnly && showClear"
                    class="at-icon at-icon-close"
                    @tap.stop="evt => handleClear()"
                ></view>
            </AtInput>
        </CDateRangeAction>
        <CDateTimeAction
@@ -33,13 +45,25 @@
                :required="itemRes.required"
                :error="itemRes.error"
                :value="itemRes.formData[itemRes.name]"
                :placeholder="placeholder"
            >
                <view class="at-icon at-icon-chevron-right" />
                <view
                    v-show="!readOnly && !showClear"
                    class="at-icon at-icon-chevron-right"
                />
                <view
                    v-show="!readOnly && showClear"
                    class="at-icon at-icon-close"
                    @tap.stop="evt => handleClear()"
                ></view>
            </AtInput>
        </CDateTimeAction>
        <view v-else-if="mode==='date'">
            <picker
                mode="date"
                :start="limitStart || pickerStart"
                :end="limitEnd || pickerEnd"
                :fields="fields"
                :value="itemRes.formData[itemRes.name]"
                @change="evt=>handleChange(evt.detail.value)"
            >
@@ -51,7 +75,15 @@
                    :value="itemRes.formData[itemRes.name]"
                    :placeholder="placeholder"
                >
                    <view class="at-icon at-icon-chevron-right" />
                    <view
                        v-show="!readOnly && !showClear"
                        class="at-icon at-icon-chevron-right"
                    />
                    <view
                        v-show="!readOnly && showClear"
                        class="at-icon at-icon-close"
                        @tap.stop="evt => handleClear()"
                    ></view>
                </AtInput>
            </picker>
        </view>
@@ -83,15 +115,48 @@
        },
        // 占位提示
        placeholder: String,
        // 开始日期
        limitStart: String,
        // 结束日期
        limitEnd: String,
        // 日期选择粒度 year、month、day
        fields: {
            type: String,
            default: 'day',
        },
        // 是否只读
        readOnly: {
            type: Boolean,
            default: false,
        },
        // 允许清除
        allowClear: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {};
        const year = new Date().getFullYear();
        return {
            pickerStart: year - 30 + '-01-01',
            pickerEnd: year + 30 + '-12-31',
        };
    },
    computed: {},
    computed: {
        showClear() {
            if (!this.allowClear) {
                return false;
            }
            return !!this.itemRes.formData[this.itemRes.name];
        },
    },
    methods: {
        handleChange(val) {
            this.itemRes.onChange(val);
        },
        handleClear() {
            this.itemRes.onChange('');
        },
    },
    mounted() {},
};