Commit 01d86a8f by Lin

feat: 日期切换防抖处理

1 parent 00d6172c
......@@ -41,6 +41,8 @@
</template>
<script>
import util from '@/libs/util'
// 日期工具方法
const DateUtils = {
// 格式化日期为 YYYY-MM-DD
......@@ -390,12 +392,22 @@ export default {
deep: true
}
},
created() {
// 创建防抖版本的 notifyDateRangeChange
this.debouncedNotifyDateRangeChange = util.debounce(this.notifyDateRangeChange, 300);
},
mounted() {
// 初始化日期范围
if (!this.internalDateRange.startDate || !this.internalDateRange.endDate) {
this.initDateRange();
}
},
beforeDestroy() {
// 组件销毁时取消防抖函数的延迟执行
if (this.debouncedNotifyDateRangeChange && typeof this.debouncedNotifyDateRangeChange.cancel === 'function') {
this.debouncedNotifyDateRangeChange.cancel();
}
},
methods: {
// 处理时间范围类型切换
handleTimeRangeChange(type) {
......@@ -452,7 +464,7 @@ export default {
const now = new Date();
const range = this.currentStrategy.init(now);
this.internalDateRange = range;
this.notifyDateRangeChange();
this.debouncedNotifyDateRangeChange();
},
// 切换日期范围(左右箭头)
......@@ -470,7 +482,7 @@ export default {
if (newRange) {
this.internalDateRange = newRange;
this.notifyDateRangeChange();
this.debouncedNotifyDateRangeChange();
}
},
......@@ -557,7 +569,7 @@ export default {
this.selectedStartDate = null;
}
this.notifyDateRangeChange();
this.debouncedNotifyDateRangeChange();
} else if (!value) {
// 清空选择时,重置临时记录
if (this.limitHalfYear) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!