修改日期组件多个弹框

main
陈博文 4 days ago
parent 5d9193b2c9
commit 2218e03376

@ -10,15 +10,15 @@
:shortcuts="type.includes('range') && shortcuts"
class="date-picker"
:disabled-date="disabledDate"
@visible-change="onVisibleChange"
v-bind="$attrs"
/>
</template>
<script setup lang="jsx">
import { computed, defineProps, defineEmits, ref } from 'vue';
import { ElDatePicker } from 'element-plus';
// props & emits
// Props Emits
const props = defineProps({
modelValue: {},
type: { type: String, default: 'date' },
@ -26,10 +26,16 @@ const props = defineProps({
});
const emits = defineEmits(['update:modelValue']);
// picker ref
// picker
const pickerRef = ref();
const visible = ref(false);
//
//
const onVisibleChange = (val) => {
visible.value = val;
};
//
const value = computed({
get() {
return props.modelValue;
@ -39,17 +45,21 @@ const value = computed({
},
});
//
//
function genShortcut(text, hoursAgo) {
return {
text,
value: () => {
const end = new Date();
const start = new Date(end.getTime() - hoursAgo * 3600 * 1000);
//
// time-picker
setTimeout(() => {
if (visible.value) {
pickerRef.value?.handleClose?.();
}
}, 0);
return [start, end];
},
};
@ -66,13 +76,13 @@ const shortcuts = [
genShortcut('前 1 周', 168),
];
//
//
const disabledDate = (time) => {
return time.getTime() >= Date.now();
};
</script>
<style>
<style scoped>
.date-picker {
max-width: 450px;
}

Loading…
Cancel
Save