diff --git a/src/utils/functions/debounce.ts b/src/utils/functions/debounce.ts new file mode 100644 index 0000000..eb54b02 --- /dev/null +++ b/src/utils/functions/debounce.ts @@ -0,0 +1,18 @@ +type CallbackFunc = (...args: T) => void + +export function debounce( + func: CallbackFunc, + wait: number, +): (...args: T) => void { + let timeoutId: ReturnType | undefined + + return (...args: T) => { + const later = () => { + clearTimeout(timeoutId) + func(...args) + } + + clearTimeout(timeoutId) + timeoutId = setTimeout(later, wait) + } +} diff --git a/src/views/chat/layout/sider/List.vue b/src/views/chat/layout/sider/List.vue index 0f5ddae..1d652f8 100644 --- a/src/views/chat/layout/sider/List.vue +++ b/src/views/chat/layout/sider/List.vue @@ -4,6 +4,7 @@ import { NInput, NPopconfirm, NScrollbar } from 'naive-ui' import { SvgIcon } from '@/components/common' import { useAppStore, useChatStore } from '@/store' import { useBasicLayout } from '@/hooks/useBasicLayout' +import { debounce } from '@/utils/functions/debounce' const { isMobile } = useBasicLayout() @@ -36,6 +37,8 @@ function handleDelete(index: number, event?: MouseEvent | TouchEvent) { appStore.setSiderCollapsed(true) } +const handleDeleteDebounce = debounce(handleDelete, 600) + function handleEnter({ uuid }: Chat.History, isEdit: boolean, event: KeyboardEvent) { event?.stopPropagation() if (event.key === 'Enter') @@ -69,8 +72,7 @@ function isActive(uuid: number) {
{{ item.title }} @@ -85,7 +87,7 @@ function isActive(uuid: number) { - +