修改日期组件多个弹框

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

@ -44,7 +44,7 @@
<Block v-for="{ title, dataSource } in rangeConfig" :title="title" :key="title"> <Block v-for="{ title, dataSource } in rangeConfig" :title="title" :key="title">
<template #extra> <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> </template>
<echarts-plus :options="getRangeOptions(dataSource)" style="height: 250px" /> <echarts-plus :options="getRangeOptions(dataSource)" style="height: 250px" />
</Block> </Block>

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

Loading…
Cancel
Save