Commit 01d86a8f by Lin

feat: 日期切换防抖处理

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