fix: Fix the issue of calculating size incorrectly during sorting (#9474)

This commit is contained in:
2025-07-09 19:02:55 +08:00 committed by GitHub
parent 355e656caa
commit b20411f8f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -395,10 +395,10 @@
min-width="250" min-width="250"
fix fix
show-overflow-tooltip show-overflow-tooltip
sortable :sortable="'custom'"
prop="name" prop="name"
> >
<template #default="{ row, $index }"> <template #default="{ row }">
<div class="file-row"> <div class="file-row">
<div> <div>
<svg-icon <svg-icon
@ -427,7 +427,7 @@
></el-button> ></el-button>
<div v-else> <div v-else>
<el-button <el-button
v-if="hoveredRowIndex === $index" v-if="hoveredRowPath === row.path"
link link
icon="Star" icon="Star"
@click="addToFavorite(row)" @click="addToFavorite(row)"
@ -456,14 +456,14 @@
</el-link> </el-link>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column :label="$t('file.size')" prop="size" min-width="100" sortable> <el-table-column :label="$t('file.size')" prop="size" min-width="100" :sortable="'custom'">
<template #default="{ row, $index }"> <template #default="{ row }">
<el-button <el-button
type="primary" type="primary"
link link
small small
:loading="row.btnLoading" :loading="row.btnLoading"
@click="row.isDir ? getDirSize(row.path, $index) : getFileSize(row.path, $index)" @click="row.isDir ? getDirSize(row.path) : getFileSize(row.path)"
> >
<span v-if="row.isDir"> <span v-if="row.isDir">
<span v-if="row.dirSize === undefined"> <span v-if="row.dirSize === undefined">
@ -483,7 +483,7 @@
width="180" width="180"
:formatter="dateFormat" :formatter="dateFormat"
show-overflow-tooltip show-overflow-tooltip
sortable :sortable="'custom'"
></el-table-column> ></el-table-column>
<fu-table-operations <fu-table-operations
:ellipsis="mobile ? 0 : 2" :ellipsis="mobile ? 0 : 2"
@ -649,7 +649,7 @@ const moveOpen = ref(false);
const deleteRef = ref(); const deleteRef = ref();
const recycleBinRef = ref(); const recycleBinRef = ref();
const favoriteRef = ref(); const favoriteRef = ref();
const hoveredRowIndex = ref(-1); const hoveredRowPath = ref(null);
const favorites = ref([]); const favorites = ref([]);
const batchRoleRef = ref(); const batchRoleRef = ref();
const dialogVscodeOpenRef = ref(); const dialogVscodeOpenRef = ref();
@ -940,36 +940,34 @@ const formatFileSize = (size: number) => {
return computeSize(size); return computeSize(size);
}; };
const getFileSize = async (path: string, index: number) => { const getFileSize = async (path: string) => {
codeReq.path = path; codeReq.path = path;
codeReq.expand = true; codeReq.expand = true;
codeReq.isDetail = true; codeReq.isDetail = true;
data.value[index].btnLoading = true; updateByPath(path, { btnLoading: true });
await getFileContent(codeReq) try {
.then(async (res) => { const res = await getFileContent(codeReq);
let newData = [...data.value]; updateByPath(path, { dirSize: res.data.size });
newData[index].size = res.data.size; } finally {
data.value = newData; updateByPath(path, { btnLoading: false });
}) }
.finally(() => {
data.value[index].btnLoading = false;
});
}; };
const getDirSize = async (path: string, index: number) => { const getDirSize = async (path: string) => {
const req = { const req = {
path: path, path: path,
}; };
data.value[index].btnLoading = true; updateByPath(path, { btnLoading: true });
await computeDirSize(req) try {
.then(async (res) => { const res = await computeDirSize(req);
let newData = [...data.value]; updateByPath(path, { dirSize: res.data.size });
newData[index].dirSize = res.data.size; } finally {
data.value = newData; updateByPath(path, { btnLoading: false });
}) }
.finally(() => { };
data.value[index].btnLoading = false;
}); const updateByPath = (path: string, patch: Partial<(typeof data.value)[0]>) => {
data.value = data.value.map((item) => (item.path === path ? { ...item, ...patch } : item));
}; };
const getDirTotalSize = async (path: string) => { const getDirTotalSize = async (path: string) => {
@ -1247,18 +1245,18 @@ const changeSort = ({ prop, order }) => {
search(); search();
}; };
const showFavorite = (row: any) => { const showFavorite = (row: File.File) => {
hoveredRowIndex.value = data.value.findIndex((item) => item === row); hoveredRowPath.value = row.path;
}; };
const hideFavorite = () => { const hideFavorite = () => {
hoveredRowIndex.value = -1; hoveredRowPath.value = null;
}; };
const addToFavorite = async (row: File.File) => { const addToFavorite = async (row: File.File) => {
try { try {
await addFavorite(row.path); await addFavorite(row.path);
search(); await search();
} catch (error) {} } catch (error) {}
}; };
@ -1269,7 +1267,7 @@ const remove = async (id: number) => {
}).then(async () => { }).then(async () => {
try { try {
await removeFavorite(id); await removeFavorite(id);
search(); await search();
} catch (error) {} } catch (error) {}
}); });
}; };