Skip to content

Commit

Permalink
fix: fix useTimeoutFn not work
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Nov 21, 2020
1 parent f7aa93f commit b49950a
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/components/Container/src/LazyContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import { defineComponent, reactive, onMounted, ref, toRef, toRefs } from 'vue';
import { Skeleton } from 'ant-design-vue';
import { useTimeoutFn } from '@vueuse/core';
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { useIntersectionObserver } from '/@/hooks/event/useIntersectionObserver';
interface State {
isInit: boolean;
Expand All @@ -40,9 +40,9 @@
// The viewport where the component is located. If the component is scrolling in the page container, the viewport is the container
viewport: {
type: (typeof window !== 'undefined' ? window.HTMLElement : Object) as PropType<
HTMLElement
>,
type: (typeof window !== 'undefined'
? window.HTMLElement
: Object) as PropType<HTMLElement>,
default: () => null,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import { triggerWindowResize } from '/@/utils/event/triggerWindowResizeEvent';
// hook
import { useTimeoutFn } from '@vueuse/core';
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
export default defineComponent({
components: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modal/src/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Modal } from 'ant-design-vue';
import { defineComponent, watchEffect } from 'vue';
import { basicProps } from './props';
import { useTimeoutFn } from '@vueuse/core';
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { extendSlots } from '/@/utils/helper/tsxHelper';

export default defineComponent({
Expand Down
2 changes: 1 addition & 1 deletion src/components/Table/src/hooks/useDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { PaginationProps } from '../types/pagination';

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

import { useTimeoutFn } from '@vueuse/core';
import { useTimeoutFn } from '/@/hooks/core/useTimeout';

import { buildUUID } from '/@/utils/uuid';
import { isFunction, isBoolean } from '/@/utils/is';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Verify/src/DragVerify.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineComponent, ref, computed, unref, reactive, watch, watchEffect } from 'vue';
import { useTimeoutFn } from '@vueuse/core';
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { useEventListener } from '/@/hooks/event/useEventListener';
import { basicProps } from './props';
import { getSlot } from '/@/utils/helper/tsxHelper';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Verify/src/ImgRotate.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { MoveData, DragVerifyActionType } from './types';

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

import BasicDragVerify from './DragVerify';

Expand Down
2 changes: 1 addition & 1 deletion src/components/Verify/src/VerifyModal.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="tsx">
import { defineComponent, ref, unref } from 'vue';
import { BasicModal } from '/@/components/Modal/index';
import { useTimeoutFn } from '@vueuse/core';
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { RotateDragVerify, DragVerifyActionType } from '/@/components/Verify/index';
export default defineComponent({
Expand Down
43 changes: 43 additions & 0 deletions src/hooks/core/useTimeout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ref, watch } from 'vue';
import { tryOnUnmounted } from '/@/utils/helper/vueHelper';

import { isFunction } from '/@/utils/is';

export function useTimeoutFn(handle: Fn<any>, wait: number) {
if (!isFunction(handle)) {
throw new Error('handle is not Function!');
}

const { readyRef, stop, start } = useTimeoutRef(wait);

watch(
readyRef,
(maturity) => {
maturity && handle();
},
{ immediate: false }
);
return { readyRef, stop, start };
}

export function useTimeoutRef(wait: number) {
const readyRef = ref(false);

let timer: ReturnType<typeof setTimeout> | undefined;
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 };
}
2 changes: 1 addition & 1 deletion src/hooks/web/useApexCharts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useTimeoutFn } from '@vueuse/core';
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { tryOnUnmounted } from '/@/utils/helper/vueHelper';
import { unref, Ref, nextTick } from 'vue';

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/web/useECharts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useTimeoutFn } from '@vueuse/core';
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { tryOnUnmounted } from '/@/utils/helper/vueHelper';
import { unref, Ref, nextTick } from 'vue';
import type { EChartOption, ECharts } from 'echarts';
Expand Down
7 changes: 7 additions & 0 deletions src/hooks/web/useMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function getIcon(iconType: string) {
return <CloseCircleFilled class="modal-icon-error" />;
}
}

function renderContent({ content }: Pick<ModalOptionsEx, 'content'>) {
return <div innerHTML={`<div>${content as string}</div>`}></div>;
}
Expand All @@ -64,6 +65,7 @@ function createConfirm(options: ModalOptionsEx): ConfirmOptions {
};
return Modal.confirm(opt) as any;
}

const baseOptions = {
okText: '确定',
centered: true,
Expand All @@ -77,15 +79,19 @@ function createModalOptions(options: ModalOptionsPartial, icon: string): ModalOp
icon: getIcon(icon),
};
}

function createSuccessModal(options: ModalOptionsPartial) {
return Modal.success(createModalOptions(options, 'success'));
}

function createErrorModal(options: ModalOptionsPartial) {
return Modal.error(createModalOptions(options, 'close'));
}

function createInfoModal(options: ModalOptionsPartial) {
return Modal.info(createModalOptions(options, 'info'));
}

function createWarningModal(options: ModalOptionsPartial) {
return Modal.warning(createModalOptions(options, 'warning'));
}
Expand All @@ -94,6 +100,7 @@ notification.config({
placement: 'topRight',
duration: 3,
});

/**
* @description: message
*/
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/web/useTabs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useTimeoutFn } from '@vueuse/core';
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { PageEnum } from '/@/enums/pageEnum';
import { TabItem, tabStore } from '/@/store/modules/tab';
import { appStore } from '/@/store/modules/app';
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/logo/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { computed, defineComponent, PropType, ref, watch } from 'vue';
// hooks
import { useSetting } from '/@/hooks/core/useSetting';
import { useTimeoutFn } from '@vueuse/core';
import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { useGo } from '/@/hooks/web/usePage';
import { PageEnum } from '/@/enums/pageEnum';
Expand Down

0 comments on commit b49950a

Please sign in to comment.