feat: Add debounce effect to file selection (#10330)

This commit is contained in:
ssongliu 2025-09-10 17:04:52 +08:00 committed by GitHub
parent 8bdf02c4c0
commit c5f70eae4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 9 deletions

View file

@ -45,8 +45,14 @@
{{ $t('commons.button.createNewFile') }}
</el-button>
</div>
<div>
<el-table :data="data" highlight-current-row height="40vh" @row-click="openDir" class="cursor-pointer">
<div v-loading="loading">
<el-table
:data="data"
highlight-current-row
height="40vh"
@row-click="handleRowClick"
class="cursor-pointer"
>
<el-table-column prop="name" show-overflow-tooltip fix>
<template #default="{ row }">
<svg-icon
@ -129,7 +135,7 @@ import { onUpdated, reactive, ref } from 'vue';
import i18n from '@/lang';
import { MsgSuccess, MsgWarning } from '@/utils/message';
import { useSearchableForSelect } from '@/views/host/file-management/hooks/searchable';
import { computeSize } from '@/utils/util';
import { computeSize, debounce } from '@/utils/util';
const data = ref([]);
const loading = ref(false);
@ -200,12 +206,19 @@ const openDir = async (row: File.File, column: any, event: any) => {
} else {
req.path = req.path + '/' + name;
}
await search(req);
if (form.isAll || form.dir) {
selectRow.value.path = req.path;
} else {
selectRow.value.path = '';
}
loading.value = true;
await search(req)
.then(() => {
loading.value = false;
if (form.isAll || form.dir) {
selectRow.value.path = req.path;
} else {
selectRow.value.path = '';
}
})
.catch(() => {
loading.value = false;
});
return;
}
if (!form.isAll && !form.dir) {
@ -214,6 +227,10 @@ const openDir = async (row: File.File, column: any, event: any) => {
}
selectRow.value.path = '';
};
const handleRowClick = (row: File.File, column: any, event: any) => {
debouncedOpenDir(row, column, event);
};
const debouncedOpenDir = debounce(openDir, 300);
const jump = async (index: number) => {
oldUrl.value = req.path;

View file

@ -29,6 +29,18 @@ export function randomNum(min: number, max: number): number {
return num;
}
export function debounce(func: Function, wait: number) {
let timeout: NodeJS.Timeout | null = null;
return function executedFunction(...args: any[]) {
const later = () => {
if (timeout) clearTimeout(timeout);
func(...args);
};
if (timeout) clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
export function getBrowserLang() {
let browserLang = navigator.language ? navigator.language : navigator.browserLanguage;
let defaultBrowserLang = '';