@dfsj/echarts
Version:
专业的水文曲线组件或构造函数以及通用的echart二次封装图表
62 lines (58 loc) • 1.39 kB
JavaScript
/**
*
* @dfsj/echarts: 专业的水文曲线组件或构造函数以及通用的echart二次封装图表
* 版本: v3.7.0-alpha.5
* 作者:yangbo <1747837358@qq.com>
* 日期:2025-11-21 13:30:34
*
*
*/
import { watch, ref } from 'vue';
import { tryOnUnmounted } from '@vueuse/core';
import { isFunction } from '@dfsj/utils';
function useTimeoutFn(handle, wait) {
var _native = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
if (!isFunction(handle)) {
throw new Error('handle is not Function!');
}
var _useTimeoutRef = useTimeoutRef(wait),
readyRef = _useTimeoutRef.readyRef,
stop = _useTimeoutRef.stop,
start = _useTimeoutRef.start;
if (_native) {
handle();
} else {
watch(readyRef, function (maturity) {
maturity && handle();
}, {
immediate: false
});
}
return {
readyRef: readyRef,
stop: stop,
start: start
};
}
function useTimeoutRef(wait) {
var readyRef = ref(false);
var timer;
function stop() {
readyRef.value = false;
timer && window.clearTimeout(timer);
}
function start() {
stop();
timer = setTimeout(function () {
readyRef.value = true;
}, wait);
}
start();
tryOnUnmounted(stop);
return {
readyRef: readyRef,
stop: stop,
start: start
};
}
export { useTimeoutFn, useTimeoutRef };