修改日期组件多个弹框

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

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

Loading…
Cancel
Save