| | |
| | | :value-format="valueFormat" |
| | | :format="DEFAULT_FORMATS_DATE" |
| | | :disabled-date="disabledDate" |
| | | :clearable="false" |
| | | :clearable="true" |
| | | :disabled="disabled" |
| | | @change="datePickerChange" |
| | | > |
| | |
| | | <div class="ml-2 inline-flex items-center space-x-2 text-[14px]"> |
| | | <div |
| | | @click="quickPickRangeClick(parseInt(item))" |
| | | class="border border-solid rounded-md px-2 cursor-pointer" |
| | | :class="{ 'bg-[#1677ff]': parseInt(item) === quickPickValue, 'text-white': parseInt(item) === quickPickValue }" |
| | | class="border border-solid rounded-md px-2 py-1 cursor-pointer" |
| | | :class="{ |
| | | 'bg-[#1677ff]': parseInt(item) === quickPickValue, |
| | | 'text-white': parseInt(item) === quickPickValue, |
| | | 'bg-[#f5f7fa]': disabled, |
| | | 'text-[#a9acb3]': disabled, |
| | | 'border-[#dcdfe6]': disabled, |
| | | '!cursor-not-allowed': disabled, |
| | | }" |
| | | v-for="item in Object.keys(timeRangeMapTitle)" |
| | | :key="item" |
| | | > |
| | |
| | | <script setup lang="ts"> |
| | | import { ElDatePicker } from 'element-plus'; |
| | | import { definePropType } from 'element-plus/es/utils/vue/props/runtime'; |
| | | import { ref, type PropType, computed, watch, nextTick } from 'vue'; |
| | | import moment from 'moment'; |
| | | import { computed, nextTick, onMounted, ref, type PropType } from 'vue'; |
| | | import type { TimeRangeParam } from '../types'; |
| | | import { TimeRangeEnum, TimeStepValue, monthTimeRangeEnumMapTitle } from './types'; |
| | | import { dayTimeRangeEnumMapTitle, timeRangeEnumMapValue } from './types'; |
| | | import type { TimeRangeEnum } from './types'; |
| | | import { TimeStepValue, dayTimeRangeEnumMapTitle, monthTimeRangeEnumMapTitle, timeRangeEnumMapValue } from './types'; |
| | | import { |
| | | CURRENT_DAY, |
| | | DEFAULT_FORMATS_DATE, |
| | | DEFAULT_FORMATS_TIME, |
| | | END_PLACEHOLDER, |
| | | RANGE_SEPARATOR, |
| | | START_PLACEHOLDER, |
| | | } from '/@/components/form/datepicker/constants'; |
| | | import { formatDate } from '/@/utils/formatTime'; |
| | | import moment from 'moment'; |
| | | |
| | | const valueFormat = DEFAULT_FORMATS_DATE + ' ' + DEFAULT_FORMATS_TIME; |
| | | const props = defineProps({ |
| | |
| | | disabled: { |
| | | type: Boolean, |
| | | default: false, |
| | | }, |
| | | quickActive: { |
| | | type: Number as PropType<TimeRangeEnum>, |
| | | required: false, |
| | | }, |
| | | }); |
| | | |
| | |
| | | |
| | | const dateChange = () => { |
| | | nextTick(() => { |
| | | if (dateValue.value?.[1]) { |
| | | dateValue.value[1] = dateValue.value[1].slice(0, 10) + ' 23:59:59'; |
| | | } |
| | | emit('change', dateValue.value); |
| | | }); |
| | | }; |
| | |
| | | quickPickValue.value = null; |
| | | }; |
| | | const quickPickValue = ref<TimeRangeEnum>(null); |
| | | |
| | | const pickQuickRange = (val: TimeRangeEnum) => { |
| | | // if(val==undefined) return; |
| | | quickPickValue.value = val; |
| | | dateValue.value = timeRangeEnumMapValue[val]().map((item) => formatDate(item)) as [string, string]; |
| | | }; |
| | | const quickPickRangeClick = (val: TimeRangeEnum) => { |
| | | if (props.disabled) return; |
| | | if (quickPickValue.value === val) return; |
| | | |
| | | quickPickValue.value = val; |
| | | dateValue.value = timeRangeEnumMapValue[val]().map((item) => formatDate(item)) as [string, string]; |
| | | pickQuickRange(val); |
| | | dateChange(); |
| | | }; |
| | | |
| | |
| | | resetQuickPickValue(); |
| | | dateChange(); |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | if(props.quickActive !=null){ |
| | | pickQuickRange(props.quickActive); |
| | | } |
| | | }); |
| | | defineExpose({ |
| | | formatDateValue: dateValue, |
| | | }); |