Commit fa18365c211ea9819f1ffcf18ad6435c527aab49

Authored by vben
1 parent feadf64e

chore: 移除 useTimeoutFn文件,使用 vueuse

packages/hooks/src/index.ts
1 1 export * from './onMountedOrActivated';
2 2 export * from './useAttrs';
3 3 export * from './useRefs';
  4 +
  5 +export { useTimeoutFn } from '@vueuse/core';
... ...
src/components/Container/src/LazyContainer.vue
... ... @@ -19,8 +19,8 @@
19 19 <script lang="ts">
20 20 import type { PropType } from 'vue';
21 21 import { defineComponent, reactive, onMounted, ref, toRef, toRefs } from 'vue';
  22 + import { useTimeoutFn } from '@vben/hooks';
22 23 import { Skeleton } from 'ant-design-vue';
23   - import { useTimeoutFn } from '/@/hooks/core/useTimeout';
24 24 import { useIntersectionObserver } from '/@/hooks/event/useIntersectionObserver';
25 25  
26 26 interface State {
... ...
src/components/Container/src/collapse/CollapseContainer.vue
... ... @@ -2,10 +2,10 @@
2 2 import { ref, unref, defineComponent, type PropType, type ExtractPropTypes } from 'vue';
3 3 import { isNil } from 'lodash-es';
4 4 import { Skeleton } from 'ant-design-vue';
  5 + import { useTimeoutFn } from '@vben/hooks';
5 6 import { CollapseTransition } from '/@/components/Transition';
6 7 import CollapseHeader from './CollapseHeader.vue';
7 8 import { triggerWindowResize } from '/@/utils/event';
8   - import { useTimeoutFn } from '/@/hooks/core/useTimeout';
9 9 import { useDesign } from '/@/hooks/web/useDesign';
10 10  
11 11 const collapseContainerProps = {
... ...
src/components/Menu/src/useOpenKeys.ts
1 1 import { MenuModeEnum } from '/@/enums/menuEnum';
2 2 import type { Menu as MenuType } from '/@/router/types';
3 3 import type { MenuState } from './types';
4   -
5 4 import { computed, Ref, toRaw, unref } from 'vue';
6   -
  5 +import { useTimeoutFn } from '@vben/hooks';
7 6 import { uniq } from 'lodash-es';
8 7 import { useMenuSetting } from '/@/hooks/setting/useMenuSetting';
9 8 import { getAllParentPath } from '/@/router/helper/menuHelper';
10   -import { useTimeoutFn } from '/@/hooks/core/useTimeout';
11 9  
12 10 export function useOpenKeys(
13 11 menuState: MenuState,
... ... @@ -22,22 +20,23 @@ export function useOpenKeys(
22 20 return;
23 21 }
24 22 const native = unref(getIsMixSidebar);
25   - useTimeoutFn(
26   - () => {
27   - const menuList = toRaw(menus.value);
28   - if (menuList?.length === 0) {
29   - menuState.openKeys = [];
30   - return;
31   - }
32   - if (!unref(accordion)) {
33   - menuState.openKeys = uniq([...menuState.openKeys, ...getAllParentPath(menuList, path)]);
34   - } else {
35   - menuState.openKeys = getAllParentPath(menuList, path);
36   - }
37   - },
38   - 16,
39   - !native,
40   - );
  23 + const handle = () => {
  24 + const menuList = toRaw(menus.value);
  25 + if (menuList?.length === 0) {
  26 + menuState.openKeys = [];
  27 + return;
  28 + }
  29 + if (!unref(accordion)) {
  30 + menuState.openKeys = uniq([...menuState.openKeys, ...getAllParentPath(menuList, path)]);
  31 + } else {
  32 + menuState.openKeys = getAllParentPath(menuList, path);
  33 + }
  34 + };
  35 + if (native) {
  36 + handle();
  37 + } else {
  38 + useTimeoutFn(handle, 16);
  39 + }
41 40 }
42 41  
43 42 const getOpenKeys = computed(() => {
... ...
src/components/Modal/src/hooks/useModalDrag.ts
1 1 import { Ref, unref, watchEffect } from 'vue';
2   -import { useTimeoutFn } from '/@/hooks/core/useTimeout';
  2 +import { useTimeoutFn } from '@vben/hooks';
3 3  
4 4 export interface UseModalDragMoveContext {
5 5 draggable: Ref<boolean>;
... ...
src/components/SimpleMenu/src/useOpenKeys.ts
1 1 import type { Menu as MenuType } from '/@/router/types';
2 2 import type { MenuState } from './types';
3   -
4 3 import { computed, Ref, toRaw, unref } from 'vue';
5   -
6 4 import { uniq } from 'lodash-es';
7 5 import { getAllParentPath } from '/@/router/helper/menuHelper';
8   -
9   -import { useTimeoutFn } from '/@/hooks/core/useTimeout';
  6 +import { useTimeoutFn } from '@vben/hooks';
10 7 import { useDebounceFn } from '@vueuse/core';
11 8  
12 9 export function useOpenKeys(
... ... @@ -20,25 +17,27 @@ export function useOpenKeys(
20 17 async function setOpenKeys(path: string) {
21 18 const native = !mixSider.value;
22 19 const menuList = toRaw(menus.value);
23   - useTimeoutFn(
24   - () => {
25   - if (menuList?.length === 0) {
26   - menuState.activeSubMenuNames = [];
27   - menuState.openNames = [];
28   - return;
29   - }
30   - const keys = getAllParentPath(menuList, path);
31 20  
32   - if (!unref(accordion)) {
33   - menuState.openNames = uniq([...menuState.openNames, ...keys]);
34   - } else {
35   - menuState.openNames = keys;
36   - }
37   - menuState.activeSubMenuNames = menuState.openNames;
38   - },
39   - 30,
40   - native,
41   - );
  21 + const handle = () => {
  22 + if (menuList?.length === 0) {
  23 + menuState.activeSubMenuNames = [];
  24 + menuState.openNames = [];
  25 + return;
  26 + }
  27 + const keys = getAllParentPath(menuList, path);
  28 +
  29 + if (!unref(accordion)) {
  30 + menuState.openNames = uniq([...menuState.openNames, ...keys]);
  31 + } else {
  32 + menuState.openNames = keys;
  33 + }
  34 + menuState.activeSubMenuNames = menuState.openNames;
  35 + };
  36 + if (native) {
  37 + handle();
  38 + } else {
  39 + useTimeoutFn(handle, 30);
  40 + }
42 41 }
43 42  
44 43 const getOpenKeys = computed(() => {
... ...
src/components/Table/src/hooks/useDataSource.ts
... ... @@ -11,7 +11,7 @@ import {
11 11 Ref,
12 12 watchEffect,
13 13 } from 'vue';
14   -import { useTimeoutFn } from '/@/hooks/core/useTimeout';
  14 +import { useTimeoutFn } from '@vben/hooks';
15 15 import { buildUUID } from '/@/utils/uuid';
16 16 import { isFunction, isBoolean, isObject } from '/@/utils/is';
17 17 import { get, cloneDeep, merge } from 'lodash-es';
... ...
src/components/Verify/src/DragVerify.vue
1 1 <script lang="tsx">
2 2 import type { Ref } from 'vue';
3 3 import { defineComponent, ref, computed, unref, reactive, watch, watchEffect } from 'vue';
4   - import { useTimeoutFn } from '/@/hooks/core/useTimeout';
  4 + import { useTimeoutFn } from '@vben/hooks';
5 5 import { useEventListener } from '/@/hooks/event/useEventListener';
6 6 import { basicProps } from './props';
7 7 import { getSlot } from '/@/utils/helper/tsxHelper';
... ...
src/components/Verify/src/ImgRotate.vue
1 1 <script lang="tsx">
2 2 import type { MoveData, DragVerifyActionType } from './typing';
3 3 import { defineComponent, computed, unref, reactive, watch, ref } from 'vue';
4   - import { useTimeoutFn } from '/@/hooks/core/useTimeout';
  4 + import { useTimeoutFn } from '@vben/hooks';
5 5 import BasicDragVerify from './DragVerify.vue';
6 6 import { hackCss } from '/@/utils/domUtils';
7 7 import { rotateProps } from './props';
... ...
src/hooks/core/useTimeout.ts deleted 100644 → 0
1   -import { ref, watch } from 'vue';
2   -import { tryOnUnmounted } from '@vueuse/core';
3   -import { isFunction } from '/@/utils/is';
4   -
5   -export function useTimeoutFn(handle: Fn<any>, wait: number, native = false) {
6   - if (!isFunction(handle)) {
7   - throw new Error('handle is not Function!');
8   - }
9   -
10   - const { readyRef, stop, start } = useTimeoutRef(wait);
11   - if (native) {
12   - handle();
13   - } else {
14   - watch(
15   - readyRef,
16   - (maturity) => {
17   - maturity && handle();
18   - },
19   - { immediate: false },
20   - );
21   - }
22   - return { readyRef, stop, start };
23   -}
24   -
25   -export function useTimeoutRef(wait: number) {
26   - const readyRef = ref(false);
27   -
28   - let timer: TimeoutHandle;
29   - function stop(): void {
30   - readyRef.value = false;
31   - timer && window.clearTimeout(timer);
32   - }
33   - function start(): void {
34   - stop();
35   - timer = setTimeout(() => {
36   - readyRef.value = true;
37   - }, wait);
38   - }
39   -
40   - start();
41   -
42   - tryOnUnmounted(stop);
43   -
44   - return { readyRef, stop, start };
45   -}
src/hooks/web/useECharts.ts
1 1 import type { EChartsOption } from 'echarts';
2 2 import type { Ref } from 'vue';
3   -import { useTimeoutFn } from '/@/hooks/core/useTimeout';
  3 +import { useTimeoutFn } from '@vben/hooks';
4 4 import { tryOnUnmounted, useDebounceFn } from '@vueuse/core';
5 5 import { unref, nextTick, watch, computed, ref } from 'vue';
6 6 import { useEventListener } from '/@/hooks/event/useEventListener';
... ...