Commit b49950a3906de6626eedb973590d02e4d95b98b9

Authored by vben
1 parent f7aa93f5

fix: fix useTimeoutFn not work

src/components/Container/src/LazyContainer.vue
... ... @@ -22,7 +22,7 @@
22 22 import { defineComponent, reactive, onMounted, ref, toRef, toRefs } from 'vue';
23 23  
24 24 import { Skeleton } from 'ant-design-vue';
25   - import { useTimeoutFn } from '@vueuse/core';
  25 + import { useTimeoutFn } from '/@/hooks/core/useTimeout';
26 26 import { useIntersectionObserver } from '/@/hooks/event/useIntersectionObserver';
27 27 interface State {
28 28 isInit: boolean;
... ... @@ -40,9 +40,9 @@
40 40  
41 41 // The viewport where the component is located. If the component is scrolling in the page container, the viewport is the container
42 42 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>,
46 46 default: () => null,
47 47 },
48 48  
... ...
src/components/Container/src/collapse/CollapseContainer.vue
... ... @@ -32,7 +32,7 @@
32 32  
33 33 import { triggerWindowResize } from '/@/utils/event/triggerWindowResizeEvent';
34 34 // hook
35   - import { useTimeoutFn } from '@vueuse/core';
  35 + import { useTimeoutFn } from '/@/hooks/core/useTimeout';
36 36  
37 37 export default defineComponent({
38 38 components: {
... ...
src/components/Modal/src/Modal.tsx
1 1 import { Modal } from 'ant-design-vue';
2 2 import { defineComponent, watchEffect } from 'vue';
3 3 import { basicProps } from './props';
4   -import { useTimeoutFn } from '@vueuse/core';
  4 +import { useTimeoutFn } from '/@/hooks/core/useTimeout';
5 5 import { extendSlots } from '/@/utils/helper/tsxHelper';
6 6  
7 7 export default defineComponent({
... ...
src/components/Table/src/hooks/useDataSource.ts
... ... @@ -3,7 +3,7 @@ import type { PaginationProps } from &#39;../types/pagination&#39;;
3 3  
4 4 import { watch, ref, unref, ComputedRef, computed, onMounted, Ref } from 'vue';
5 5  
6   -import { useTimeoutFn } from '@vueuse/core';
  6 +import { useTimeoutFn } from '/@/hooks/core/useTimeout';
7 7  
8 8 import { buildUUID } from '/@/utils/uuid';
9 9 import { isFunction, isBoolean } from '/@/utils/is';
... ...
src/components/Verify/src/DragVerify.tsx
1 1 import { defineComponent, ref, computed, unref, reactive, watch, watchEffect } from 'vue';
2   -import { useTimeoutFn } from '@vueuse/core';
  2 +import { useTimeoutFn } from '/@/hooks/core/useTimeout';
3 3 import { useEventListener } from '/@/hooks/event/useEventListener';
4 4 import { basicProps } from './props';
5 5 import { getSlot } from '/@/utils/helper/tsxHelper';
... ...
src/components/Verify/src/ImgRotate.tsx
1 1 import type { MoveData, DragVerifyActionType } from './types';
2 2  
3 3 import { defineComponent, computed, unref, reactive, watch, ref, getCurrentInstance } from 'vue';
4   -import { useTimeoutFn } from '@vueuse/core';
  4 +import { useTimeoutFn } from '/@/hooks/core/useTimeout';
5 5  
6 6 import BasicDragVerify from './DragVerify';
7 7  
... ...
src/components/Verify/src/VerifyModal.vue
1 1 <script lang="tsx">
2 2 import { defineComponent, ref, unref } from 'vue';
3 3 import { BasicModal } from '/@/components/Modal/index';
4   - import { useTimeoutFn } from '@vueuse/core';
  4 + import { useTimeoutFn } from '/@/hooks/core/useTimeout';
5 5  
6 6 import { RotateDragVerify, DragVerifyActionType } from '/@/components/Verify/index';
7 7 export default defineComponent({
... ...
src/hooks/core/useTimeout.ts 0 → 100644
  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
1   -import { useTimeoutFn } from '@vueuse/core';
  1 +import { useTimeoutFn } from '/@/hooks/core/useTimeout';
2 2 import { tryOnUnmounted } from '/@/utils/helper/vueHelper';
3 3 import { unref, Ref, nextTick } from 'vue';
4 4  
... ...
src/hooks/web/useECharts.ts
1   -import { useTimeoutFn } from '@vueuse/core';
  1 +import { useTimeoutFn } from '/@/hooks/core/useTimeout';
2 2 import { tryOnUnmounted } from '/@/utils/helper/vueHelper';
3 3 import { unref, Ref, nextTick } from 'vue';
4 4 import type { EChartOption, ECharts } from 'echarts';
... ...
src/hooks/web/useMessage.tsx
... ... @@ -46,6 +46,7 @@ function getIcon(iconType: string) {
46 46 return <CloseCircleFilled class="modal-icon-error" />;
47 47 }
48 48 }
  49 +
49 50 function renderContent({ content }: Pick<ModalOptionsEx, 'content'>) {
50 51 return <div innerHTML={`<div>${content as string}</div>`}></div>;
51 52 }
... ... @@ -64,6 +65,7 @@ function createConfirm(options: ModalOptionsEx): ConfirmOptions {
64 65 };
65 66 return Modal.confirm(opt) as any;
66 67 }
  68 +
67 69 const baseOptions = {
68 70 okText: '确定',
69 71 centered: true,
... ... @@ -77,15 +79,19 @@ function createModalOptions(options: ModalOptionsPartial, icon: string): ModalOp
77 79 icon: getIcon(icon),
78 80 };
79 81 }
  82 +
80 83 function createSuccessModal(options: ModalOptionsPartial) {
81 84 return Modal.success(createModalOptions(options, 'success'));
82 85 }
  86 +
83 87 function createErrorModal(options: ModalOptionsPartial) {
84 88 return Modal.error(createModalOptions(options, 'close'));
85 89 }
  90 +
86 91 function createInfoModal(options: ModalOptionsPartial) {
87 92 return Modal.info(createModalOptions(options, 'info'));
88 93 }
  94 +
89 95 function createWarningModal(options: ModalOptionsPartial) {
90 96 return Modal.warning(createModalOptions(options, 'warning'));
91 97 }
... ... @@ -94,6 +100,7 @@ notification.config({
94 100 placement: 'topRight',
95 101 duration: 3,
96 102 });
  103 +
97 104 /**
98 105 * @description: message
99 106 */
... ...
src/hooks/web/useTabs.ts
1   -import { useTimeoutFn } from '@vueuse/core';
  1 +import { useTimeoutFn } from '/@/hooks/core/useTimeout';
2 2 import { PageEnum } from '/@/enums/pageEnum';
3 3 import { TabItem, tabStore } from '/@/store/modules/tab';
4 4 import { appStore } from '/@/store/modules/app';
... ...
src/layouts/logo/index.vue
... ... @@ -8,7 +8,7 @@
8 8 import { computed, defineComponent, PropType, ref, watch } from 'vue';
9 9 // hooks
10 10 import { useSetting } from '/@/hooks/core/useSetting';
11   - import { useTimeoutFn } from '@vueuse/core';
  11 + import { useTimeoutFn } from '/@/hooks/core/useTimeout';
12 12 import { useGo } from '/@/hooks/web/usePage';
13 13  
14 14 import { PageEnum } from '/@/enums/pageEnum';
... ...