修改日期组件多个弹框

main
陈博文 4 days ago
parent 4f4972c0d0
commit c7c8f36b2f

@ -44,7 +44,7 @@
<Block v-for="{ title, dataSource } in rangeConfig" :title="title" :key="title">
<template #extra>
<time-picker v-model="times" type="datetimerange" size="small" />
<time-picker v-model="times" type="datetimerange" size="small" :key="`time-picker-${title}`" />
</template>
<echarts-plus :options="getRangeOptions(dataSource)" style="height: 250px" />
</Block>

@ -7,8 +7,9 @@
start-placeholder="开始时间"
end-placeholder="结束时间"
unlink-panels
:teleported="false"
:shortcuts="type.includes('range') && shortcuts"
:teleported="false"
:append-to-body="false"
class="date-picker"
:disabled-date="disabledDate"
@visible-change="onVisibleChange"
@ -19,7 +20,7 @@
<script setup lang="jsx">
import { computed, defineProps, defineEmits, ref } from 'vue';
// Props Emits
// props emits
const props = defineProps({
modelValue: {},
type: { type: String, default: 'date' },
@ -27,16 +28,16 @@ const props = defineProps({
});
const emits = defineEmits(['update:modelValue']);
// picker
// ref
const pickerRef = ref();
const visible = ref(false);
//
//
const onVisibleChange = (val) => {
visible.value = val;
};
//
//
const value = computed({
get() {
return props.modelValue;
@ -46,7 +47,7 @@ const value = computed({
},
});
//
//
function genShortcut(text, hoursAgo) {
return {
text,
@ -54,7 +55,7 @@ function genShortcut(text, hoursAgo) {
const end = new Date();
const start = new Date(end.getTime() - hoursAgo * 3600 * 1000);
// time-picker
//
setTimeout(() => {
if (visible.value) {
pickerRef.value?.handleClose?.();
@ -66,7 +67,7 @@ function genShortcut(text, hoursAgo) {
};
}
//
//
const shortcuts = [
genShortcut('前 1 小时', 1),
genShortcut('前 6 小时', 6),
@ -77,7 +78,7 @@ const shortcuts = [
genShortcut('前 1 周', 168),
];
//
//
const disabledDate = (time) => {
return time.getTime() >= Date.now();
};

Loading…
Cancel
Save