WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2025-03-18 fdeb869c386da95150a087bc22bcebc4e57d0f76
forms/datePicker/CDatePicker.vue
@@ -1,10 +1,16 @@
/**
 * CDatePicker - 选择日期范围操作
 * 日期选择组件,用于在表单中选择日期或日期范围
 * 支持三种选择模式:日期选择、日期时间选择和日期范围选择
 * 可限制日期选择范围,支持清除功能和只读模式
 * @author Tevin
 */
<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 +23,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 +48,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 +78,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 +118,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() {},
};