修改日期组件多个弹框

main
陈博文 4 days ago
parent 945bf7672d
commit 5d9193b2c9

@ -1,5 +1,6 @@
<template>
<el-date-picker
ref="pickerRef"
v-model="value"
:type="type"
range-separator="至"
@ -10,21 +11,25 @@
class="date-picker"
:disabled-date="disabledDate"
v-bind="$attrs"
></el-date-picker>
/>
</template>
<script setup lang="jsx">
import { computed, defineProps, defineEmits } from 'vue';
import { computed, defineProps, defineEmits, ref } from 'vue';
import { ElDatePicker } from 'element-plus';
// props & emits
const props = defineProps({
modelValue: {},
type: { type: String, default: 'date' },
parse: { type: Function, default: (times) => times },
});
const emits = defineEmits(['update:modelValue']);
// picker ref
const pickerRef = ref();
//
const value = computed({
get() {
return props.modelValue;
@ -34,99 +39,34 @@ const value = computed({
},
});
const shortcuts = [
{
text: '前 1 小时',
value: () => {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 1);
return [start, end];
},
},
{
text: '前 6 小时',
value: () => {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 6);
return [start, end];
},
},
{
text: '前 12 小时',
value: () => {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 12);
return [start, end];
},
},
{
text: '前 1 天',
value: () => {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24);
return [start, end];
},
},
{
text: '前 2 天',
value: () => {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 2);
return [start, end];
},
},
{
text: '前 3 天',
//
function genShortcut(text, hoursAgo) {
return {
text,
value: () => {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 3);
const start = new Date(end.getTime() - hoursAgo * 3600 * 1000);
//
setTimeout(() => {
pickerRef.value?.handleClose?.();
}, 0);
return [start, end];
},
},
{
text: '前 1 周',
value: () => {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
return [start, end];
},
},
// {
// text: '',
// value: () => {
// const end = new Date();
// const start = new Date();
// start.setTime(start.getTime() - 3600 * 1000 * 24 * 14);
// return [start, end];
// },
// },
// {
// text: '',
// value: () => {
// const end = new Date();
// const start = new Date();
// start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
// return [start, end];
// },
// },
// {
// text: '',
// value: () => {
// const end = new Date();
// const start = new Date();
// start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
// return [start, end];
// },
// },
};
}
//
const shortcuts = [
genShortcut('前 1 小时', 1),
genShortcut('前 6 小时', 6),
genShortcut('前 12 小时', 12),
genShortcut('前 1 天', 24),
genShortcut('前 2 天', 48),
genShortcut('前 3 天', 72),
genShortcut('前 1 周', 168),
];
//
const disabledDate = (time) => {
return time.getTime() >= Date.now();
};

Loading…
Cancel
Save