perf: 调整
This commit is contained in:
@ -25,7 +25,7 @@
|
||||
<div class="filter-row flex mb-20px">
|
||||
<div class="filter-row-item flex items-center">
|
||||
<span class="label">时间筛选</span>
|
||||
<DatePicker.RangePicker v-model:value="query.data_time" size="medium" allowClear format="YYYY-MM-DD" class="w-310" />
|
||||
<DatePicker.RangePicker v-model="data_time" size="medium" allowClear format="YYYY-MM-DD" class="w-310" @change="onDateChange" />
|
||||
</div>
|
||||
|
||||
<div class="filter-row-item flex items-center">
|
||||
@ -66,6 +66,9 @@ const props = defineProps({
|
||||
},
|
||||
});
|
||||
const emits = defineEmits(['onSearch', 'onReset', 'update:query']);
|
||||
|
||||
const data_time = ref([]);
|
||||
|
||||
// 获取最近7天的日期
|
||||
const getLast7Days = () => {
|
||||
const today = new Date();
|
||||
@ -76,6 +79,19 @@ const getLast7Days = () => {
|
||||
const handleSearch = () => {
|
||||
emits('onSearch', props.query);
|
||||
};
|
||||
|
||||
const onDateChange = (date) => {
|
||||
if (!date) {
|
||||
props.query.data_time = [];
|
||||
handleSearch();
|
||||
return;
|
||||
}
|
||||
|
||||
const [start, end] = date;
|
||||
const FORMAT_DATE = 'YYYY-MM-DD';
|
||||
props.query.data_time = [dayjs(start).startOf('day').format(FORMAT_DATE), dayjs(end).endOf('day').format(FORMAT_DATE)];
|
||||
handleSearch();
|
||||
};
|
||||
// 使用 computed 实现 v-model
|
||||
const localQuery = computed({
|
||||
get: () => props.query,
|
||||
@ -83,10 +99,14 @@ const localQuery = computed({
|
||||
});
|
||||
|
||||
const handleReset = () => {
|
||||
data_time.value = [];
|
||||
emits('onReset');
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
localQuery.value.data_time = getLast7Days();
|
||||
const defaultTime = getLast7Days();
|
||||
data_time.value = defaultTime;
|
||||
localQuery.value.data_time = defaultTime;
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user