chore: 移除 useTimeoutFn文件,使用 vueuse
parent
1b9f1e6c21
commit
23664aa943
|
@ -12,7 +12,7 @@
|
|||
<script lang="ts" setup name="LazyContainer" inheritAttrs="false">
|
||||
import { reactive, onMounted, ref, toRef } from 'vue'
|
||||
import { Skeleton } from 'ant-design-vue'
|
||||
import { useTimeoutFn } from '@/hooks/core/useTimeout'
|
||||
import { useTimeoutFn } from '@vueuse/core'
|
||||
import { useIntersectionObserver } from '@/hooks/event/useIntersectionObserver'
|
||||
|
||||
interface State {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Skeleton } from 'ant-design-vue'
|
|||
import { CollapseTransition } from '@/components/Transition'
|
||||
import CollapseHeader from './CollapseHeader.vue'
|
||||
import { triggerWindowResize } from '@/utils/event'
|
||||
import { useTimeoutFn } from '@/hooks/core/useTimeout'
|
||||
import { useTimeoutFn } from '@vueuse/core'
|
||||
import { useDesign } from '@/hooks/web/useDesign'
|
||||
|
||||
const collapseContainerProps = {
|
||||
|
|
|
@ -8,7 +8,7 @@ import { unref } from 'vue'
|
|||
import { uniq } from 'lodash-es'
|
||||
import { useMenuSetting } from '@/hooks/setting/useMenuSetting'
|
||||
import { getAllParentPath } from '@/router/helper/menuHelper'
|
||||
import { useTimeoutFn } from '@/hooks/core/useTimeout'
|
||||
import { useTimeoutFn } from '@vueuse/core'
|
||||
|
||||
export function useOpenKeys(menuState: MenuState, menus: Ref<MenuType[]>, mode: Ref<MenuModeEnum>, accordion: Ref<boolean>) {
|
||||
const { getCollapsed, getIsMixSidebar } = useMenuSetting()
|
||||
|
@ -18,22 +18,23 @@ export function useOpenKeys(menuState: MenuState, menus: Ref<MenuType[]>, mode:
|
|||
return
|
||||
}
|
||||
const native = unref(getIsMixSidebar)
|
||||
useTimeoutFn(
|
||||
() => {
|
||||
const menuList = toRaw(menus.value)
|
||||
if (menuList?.length === 0) {
|
||||
menuState.openKeys = []
|
||||
return
|
||||
}
|
||||
if (!unref(accordion)) {
|
||||
menuState.openKeys = uniq([...menuState.openKeys, ...getAllParentPath(menuList, path)])
|
||||
} else {
|
||||
menuState.openKeys = getAllParentPath(menuList, path)
|
||||
}
|
||||
},
|
||||
16,
|
||||
!native
|
||||
)
|
||||
const handle = () => {
|
||||
const menuList = toRaw(menus.value)
|
||||
if (menuList?.length === 0) {
|
||||
menuState.openKeys = []
|
||||
return
|
||||
}
|
||||
if (!unref(accordion)) {
|
||||
menuState.openKeys = uniq([...menuState.openKeys, ...getAllParentPath(menuList, path)])
|
||||
} else {
|
||||
menuState.openKeys = getAllParentPath(menuList, path)
|
||||
}
|
||||
}
|
||||
if (native) {
|
||||
handle()
|
||||
} else {
|
||||
useTimeoutFn(handle, 16)
|
||||
}
|
||||
}
|
||||
|
||||
const getOpenKeys = computed(() => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Ref, unref, watchEffect } from 'vue'
|
||||
import { useTimeoutFn } from '@/hooks/core/useTimeout'
|
||||
import { useTimeoutFn } from '@vueuse/core'
|
||||
|
||||
export interface UseModalDragMoveContext {
|
||||
draggable: Ref<boolean>
|
||||
|
|
|
@ -7,8 +7,7 @@ import { unref } from 'vue'
|
|||
import { uniq } from 'lodash-es'
|
||||
import { getAllParentPath } from '@/router/helper/menuHelper'
|
||||
|
||||
import { useTimeoutFn } from '@/hooks/core/useTimeout'
|
||||
import { useDebounceFn } from '@vueuse/core'
|
||||
import { useTimeoutFn, useDebounceFn } from '@vueuse/core'
|
||||
|
||||
export function useOpenKeys(
|
||||
menuState: MenuState,
|
||||
|
@ -21,25 +20,26 @@ export function useOpenKeys(
|
|||
async function setOpenKeys(path: string) {
|
||||
const native = !mixSider.value
|
||||
const menuList = toRaw(menus.value)
|
||||
useTimeoutFn(
|
||||
() => {
|
||||
if (menuList?.length === 0) {
|
||||
menuState.activeSubMenuNames = []
|
||||
menuState.openNames = []
|
||||
return
|
||||
}
|
||||
const keys = getAllParentPath(menuList, path)
|
||||
const handle = () => {
|
||||
if (menuList?.length === 0) {
|
||||
menuState.activeSubMenuNames = []
|
||||
menuState.openNames = []
|
||||
return
|
||||
}
|
||||
const keys = getAllParentPath(menuList, path)
|
||||
|
||||
if (!unref(accordion)) {
|
||||
menuState.openNames = uniq([...menuState.openNames, ...keys])
|
||||
} else {
|
||||
menuState.openNames = keys
|
||||
}
|
||||
menuState.activeSubMenuNames = menuState.openNames
|
||||
},
|
||||
30,
|
||||
native
|
||||
)
|
||||
if (!unref(accordion)) {
|
||||
menuState.openNames = uniq([...menuState.openNames, ...keys])
|
||||
} else {
|
||||
menuState.openNames = keys
|
||||
}
|
||||
menuState.activeSubMenuNames = menuState.openNames
|
||||
}
|
||||
if (native) {
|
||||
handle()
|
||||
} else {
|
||||
useTimeoutFn(handle, 30)
|
||||
}
|
||||
}
|
||||
|
||||
const getOpenKeys = computed(() => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { BasicTableProps, FetchParams, SorterResult } from '../types/table'
|
||||
import type { PaginationProps } from '../types/pagination'
|
||||
import { ref, unref, ComputedRef, computed, onMounted, watch, reactive, Ref, watchEffect } from 'vue'
|
||||
import { useTimeoutFn } from '@/hooks/core/useTimeout'
|
||||
import { useTimeoutFn } from '@vueuse/core'
|
||||
import { buildUUID } from '@/utils/uuid'
|
||||
import { isFunction, isBoolean, isObject } from '@/utils/is'
|
||||
import { get, cloneDeep, merge } from 'lodash-es'
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
import { ref, watch } from 'vue'
|
||||
import { tryOnUnmounted } from '@vueuse/core'
|
||||
import { isFunction } from '@/utils/is'
|
||||
|
||||
export function useTimeoutFn(handle: Fn<any>, wait: number, native = false) {
|
||||
if (!isFunction(handle)) {
|
||||
throw new Error('handle is not Function!')
|
||||
}
|
||||
|
||||
const { readyRef, stop, start } = useTimeoutRef(wait)
|
||||
if (native) {
|
||||
handle()
|
||||
} else {
|
||||
watch(
|
||||
readyRef,
|
||||
(maturity) => {
|
||||
maturity && handle()
|
||||
},
|
||||
{ immediate: false }
|
||||
)
|
||||
}
|
||||
return { readyRef, stop, start }
|
||||
}
|
||||
|
||||
export function useTimeoutRef(wait: number) {
|
||||
const readyRef = ref(false)
|
||||
|
||||
let timer: TimeoutHandle
|
||||
function stop(): void {
|
||||
readyRef.value = false
|
||||
timer && window.clearTimeout(timer)
|
||||
}
|
||||
function start(): void {
|
||||
stop()
|
||||
timer = setTimeout(() => {
|
||||
readyRef.value = true
|
||||
}, wait)
|
||||
}
|
||||
|
||||
start()
|
||||
|
||||
tryOnUnmounted(stop)
|
||||
|
||||
return { readyRef, stop, start }
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
import type { EChartsOption } from 'echarts'
|
||||
import type { Ref } from 'vue'
|
||||
import { useTimeoutFn } from '@/hooks/core/useTimeout'
|
||||
import { tryOnUnmounted } from '@vueuse/core'
|
||||
import { useTimeoutFn, tryOnUnmounted } from '@vueuse/core'
|
||||
import { unref, nextTick, watch, computed, ref } from 'vue'
|
||||
import { useDebounceFn } from '@vueuse/core'
|
||||
import { useEventListener } from '@/hooks/event/useEventListener'
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<template>
|
||||
<div>开发中</div>
|
||||
</template>
|
Loading…
Reference in New Issue