Skip to content

Commit b49950a

Browse files
committed
fix: fix useTimeoutFn not work
1 parent f7aa93f commit b49950a

File tree

13 files changed

+64
-14
lines changed

13 files changed

+64
-14
lines changed

src/components/Container/src/LazyContainer.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import { defineComponent, reactive, onMounted, ref, toRef, toRefs } from 'vue';
2323
2424
import { Skeleton } from 'ant-design-vue';
25-
import { useTimeoutFn } from '@vueuse/core';
25+
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
2626
import { useIntersectionObserver } from '/@/hooks/event/useIntersectionObserver';
2727
interface State {
2828
isInit: boolean;
@@ -40,9 +40,9 @@
4040
4141
// The viewport where the component is located. If the component is scrolling in the page container, the viewport is the container
4242
viewport: {
43-
type: (typeof window !== 'undefined' ? window.HTMLElement : Object) as PropType<
44-
HTMLElement
45-
>,
43+
type: (typeof window !== 'undefined'
44+
? window.HTMLElement
45+
: Object) as PropType<HTMLElement>,
4646
default: () => null,
4747
},
4848

src/components/Container/src/collapse/CollapseContainer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
3333
import { triggerWindowResize } from '/@/utils/event/triggerWindowResizeEvent';
3434
// hook
35-
import { useTimeoutFn } from '@vueuse/core';
35+
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
3636
3737
export default defineComponent({
3838
components: {

src/components/Modal/src/Modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Modal } from 'ant-design-vue';
22
import { defineComponent, watchEffect } from 'vue';
33
import { basicProps } from './props';
4-
import { useTimeoutFn } from '@vueuse/core';
4+
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
55
import { extendSlots } from '/@/utils/helper/tsxHelper';
66

77
export default defineComponent({

src/components/Table/src/hooks/useDataSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { PaginationProps } from '../types/pagination';
33

44
import { watch, ref, unref, ComputedRef, computed, onMounted, Ref } from 'vue';
55

6-
import { useTimeoutFn } from '@vueuse/core';
6+
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
77

88
import { buildUUID } from '/@/utils/uuid';
99
import { isFunction, isBoolean } from '/@/utils/is';

src/components/Verify/src/DragVerify.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineComponent, ref, computed, unref, reactive, watch, watchEffect } from 'vue';
2-
import { useTimeoutFn } from '@vueuse/core';
2+
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
33
import { useEventListener } from '/@/hooks/event/useEventListener';
44
import { basicProps } from './props';
55
import { getSlot } from '/@/utils/helper/tsxHelper';

src/components/Verify/src/ImgRotate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { MoveData, DragVerifyActionType } from './types';
22

33
import { defineComponent, computed, unref, reactive, watch, ref, getCurrentInstance } from 'vue';
4-
import { useTimeoutFn } from '@vueuse/core';
4+
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
55

66
import BasicDragVerify from './DragVerify';
77

src/components/Verify/src/VerifyModal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="tsx">
22
import { defineComponent, ref, unref } from 'vue';
33
import { BasicModal } from '/@/components/Modal/index';
4-
import { useTimeoutFn } from '@vueuse/core';
4+
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
55
66
import { RotateDragVerify, DragVerifyActionType } from '/@/components/Verify/index';
77
export default defineComponent({

src/hooks/core/useTimeout.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { ref, watch } from 'vue';
2+
import { tryOnUnmounted } from '/@/utils/helper/vueHelper';
3+
4+
import { isFunction } from '/@/utils/is';
5+
6+
export function useTimeoutFn(handle: Fn<any>, wait: number) {
7+
if (!isFunction(handle)) {
8+
throw new Error('handle is not Function!');
9+
}
10+
11+
const { readyRef, stop, start } = useTimeoutRef(wait);
12+
13+
watch(
14+
readyRef,
15+
(maturity) => {
16+
maturity && handle();
17+
},
18+
{ immediate: false }
19+
);
20+
return { readyRef, stop, start };
21+
}
22+
23+
export function useTimeoutRef(wait: number) {
24+
const readyRef = ref(false);
25+
26+
let timer: ReturnType<typeof setTimeout> | undefined;
27+
function stop(): void {
28+
readyRef.value = false;
29+
timer && window.clearTimeout(timer);
30+
}
31+
function start(): void {
32+
stop();
33+
timer = setTimeout(() => {
34+
readyRef.value = true;
35+
}, wait);
36+
}
37+
38+
start();
39+
40+
tryOnUnmounted(stop);
41+
42+
return { readyRef, stop, start };
43+
}

src/hooks/web/useApexCharts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useTimeoutFn } from '@vueuse/core';
1+
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
22
import { tryOnUnmounted } from '/@/utils/helper/vueHelper';
33
import { unref, Ref, nextTick } from 'vue';
44

src/hooks/web/useECharts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useTimeoutFn } from '@vueuse/core';
1+
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
22
import { tryOnUnmounted } from '/@/utils/helper/vueHelper';
33
import { unref, Ref, nextTick } from 'vue';
44
import type { EChartOption, ECharts } from 'echarts';

0 commit comments

Comments
 (0)