Skip to content

Commit c0a9fd5

Browse files
committed
fix: 快速按下删除会话导致的问题 #917
1 parent 07123b7 commit c0a9fd5

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/utils/functions/debounce.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
type CallbackFunc<T extends unknown[]> = (...args: T) => void
2+
3+
export function debounce<T extends unknown[]>(
4+
func: CallbackFunc<T>,
5+
wait: number,
6+
): (...args: T) => void {
7+
let timeoutId: ReturnType<typeof setTimeout> | undefined
8+
9+
return (...args: T) => {
10+
const later = () => {
11+
clearTimeout(timeoutId)
12+
func(...args)
13+
}
14+
15+
clearTimeout(timeoutId)
16+
timeoutId = setTimeout(later, wait)
17+
}
18+
}

src/views/chat/layout/sider/List.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { NInput, NPopconfirm, NScrollbar } from 'naive-ui'
44
import { SvgIcon } from '@/components/common'
55
import { useAppStore, useChatStore } from '@/store'
66
import { useBasicLayout } from '@/hooks/useBasicLayout'
7+
import { debounce } from '@/utils/functions/debounce'
78
89
const { isMobile } = useBasicLayout()
910
@@ -36,6 +37,8 @@ function handleDelete(index: number, event?: MouseEvent | TouchEvent) {
3637
appStore.setSiderCollapsed(true)
3738
}
3839
40+
const handleDeleteDebounce = debounce(handleDelete, 600)
41+
3942
function handleEnter({ uuid }: Chat.History, isEdit: boolean, event: KeyboardEvent) {
4043
event?.stopPropagation()
4144
if (event.key === 'Enter')
@@ -69,8 +72,7 @@ function isActive(uuid: number) {
6972
<div class="relative flex-1 overflow-hidden break-all text-ellipsis whitespace-nowrap">
7073
<NInput
7174
v-if="item.isEdit"
72-
v-model:value="item.title"
73-
size="tiny"
75+
v-model:value="item.title" size="tiny"
7476
@keypress="handleEnter(item, false, $event)"
7577
/>
7678
<span v-else>{{ item.title }}</span>
@@ -85,7 +87,7 @@ function isActive(uuid: number) {
8587
<button class="p-1">
8688
<SvgIcon icon="ri:edit-line" @click="handleEdit(item, true, $event)" />
8789
</button>
88-
<NPopconfirm placement="bottom" @positive-click="handleDelete(index, $event)">
90+
<NPopconfirm placement="bottom" @positive-click="handleDeleteDebounce(index, $event)">
8991
<template #trigger>
9092
<button class="p-1">
9193
<SvgIcon icon="ri:delete-bin-line" />

0 commit comments

Comments
 (0)