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