Skip to content

Commit 0a5f62f

Browse files
authored
feat: Optimize file management style and increase file calculation (#8851)
Refs: #6878
1 parent 2783674 commit 0a5f62f

File tree

1 file changed

+65
-26
lines changed
  • frontend/src/views/host/file-management

1 file changed

+65
-26
lines changed

frontend/src/views/host/file-management/index.vue

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<div class="flex gap-y-2 items-center gap-x-4">
3+
<div class="flex gap-y-2 items-center gap-x-4" ref="toolRef">
44
<div class="flex-shrink-0 flex items-center justify-between">
55
<el-tooltip :content="$t('file.back')" placement="top">
66
<el-button icon="Back" @click="back" circle />
@@ -179,9 +179,25 @@
179179
</el-dropdown-menu>
180180
</template>
181181
</el-dropdown>
182+
<el-dropdown class="mr-2.5">
183+
<el-button>
184+
{{ $t('commons.button.upload') }}/{{ $t('commons.button.download') }}
185+
<el-icon><arrow-down /></el-icon>
186+
</el-button>
187+
<template #dropdown>
188+
<el-dropdown-menu>
189+
<el-dropdown-item @click="openUpload">
190+
<el-icon><ElUpload /></el-icon>
191+
{{ $t('commons.button.upload') }}
192+
</el-dropdown-item>
193+
<el-dropdown-item @click="openWget">
194+
<el-icon><ElDownload /></el-icon>
195+
{{ $t('file.remoteFile') }}
196+
</el-dropdown-item>
197+
</el-dropdown-menu>
198+
</template>
199+
</el-dropdown>
182200
<el-button-group>
183-
<el-button plain @click="openUpload">{{ $t('commons.button.upload') }}</el-button>
184-
<el-button plain @click="openWget">{{ $t('file.remoteFile') }}</el-button>
185201
<el-button class="btn mr-2.5" @click="openRecycleBin">
186202
{{ $t('file.recycleBin') }}
187203
</el-button>
@@ -232,23 +248,26 @@
232248
</el-button>
233249
<template v-if="hostMount.length == 1">
234250
<el-button class="btn" @click.stop="jump(hostMount[0]?.path)">
235-
{{ hostMount[0]?.path }} ({{ $t('file.root') }}) {{ getFileSize(hostMount[0]?.free) }}
251+
{{ hostMount[0]?.path }} ({{ $t('file.root') }})
252+
{{ formatFileSize(hostMount[0]?.free) }}
236253
</el-button>
237254
</template>
238255
<template v-else>
239256
<el-dropdown class="mr-2.5" style="border-left: 1px solid #ccc">
240257
<el-button class="btn">
241258
{{ hostMount[0]?.path }} ({{ $t('file.root') }})
242-
{{ getFileSize(hostMount[0]?.free) }}
259+
{{ formatFileSize(hostMount[0]?.free) }}
243260
</el-button>
244261
<template #dropdown>
245262
<el-dropdown-menu>
246263
<template v-for="(mount, index) in hostMount" :key="mount.path">
247264
<el-dropdown-item v-if="index == 0" @click.stop="jump(mount.path)">
248-
{{ mount.path }} ({{ $t('file.root') }}) {{ getFileSize(mount.free) }}
265+
{{ mount.path }} ({{ $t('file.root') }})
266+
{{ formatFileSize(mount.free) }}
249267
</el-dropdown-item>
250268
<el-dropdown-item v-if="index != 0" @click.stop="jump(mount.path)">
251-
{{ mount.path }} ({{ $t('home.mount') }}) {{ getFileSize(mount.free) }}
269+
{{ mount.path }} ({{ $t('home.mount') }})
270+
{{ formatFileSize(mount.free) }}
252271
</el-dropdown-item>
253272
</template>
254273
</el-dropdown-menu>
@@ -430,21 +449,23 @@
430449
</el-table-column>
431450
<el-table-column :label="$t('file.size')" prop="size" min-width="100" sortable>
432451
<template #default="{ row, $index }">
433-
<span v-if="row.isDir">
434-
<el-button
435-
type="primary"
436-
link
437-
small
438-
@click="getDirSize(row.path, $index)"
439-
:loading="row.btnLoading"
440-
>
441-
<span v-if="row.dirSize == undefined">
452+
<el-button
453+
type="primary"
454+
link
455+
small
456+
:loading="row.btnLoading"
457+
@click="row.isDir ? getDirSize(row.path, $index) : getFileSize(row.path, $index)"
458+
>
459+
<span v-if="row.isDir">
460+
<span v-if="row.dirSize === undefined">
442461
{{ $t('file.calculate') }}
443462
</span>
444-
<span v-else>{{ getFileSize(row.dirSize) }}</span>
445-
</el-button>
446-
</span>
447-
<span v-else>{{ getFileSize(row.size) }}</span>
463+
<span v-else>{{ formatFileSize(row.dirSize) }}</span>
464+
</span>
465+
<span v-else>
466+
{{ formatFileSize(row.size) }}
467+
</span>
468+
</el-button>
448469
</template>
449470
</el-table-column>
450471
<el-table-column
@@ -477,7 +498,7 @@
477498
{{ $t('file.calculate') }}
478499
</span>
479500
<span v-else>
480-
{{ getFileSize(dirTotalSize) }}
501+
{{ formatFileSize(dirTotalSize) }}
481502
</span>
482503
</el-button>
483504
</div>
@@ -530,6 +551,7 @@ import { MsgWarning } from '@/utils/message';
530551
import { useSearchable } from './hooks/searchable';
531552
import { ResultData } from '@/api/interface';
532553
import { GlobalStore } from '@/store';
554+
import { Download as ElDownload, Upload as ElUpload } from '@element-plus/icons-vue';
533555
534556
import i18n from '@/lang';
535557
import CreateFile from './create/index.vue';
@@ -593,7 +615,7 @@ const fileCompress = reactive({ files: [''], name: '', dst: '', operate: 'compre
593615
const fileDeCompress = reactive({ path: '', name: '', dst: '', mimeType: '' });
594616
const fileEdit = reactive({ content: '', path: '', name: '', language: 'plaintext', extension: '' });
595617
const filePreview = reactive({ path: '', name: '', extension: '', fileType: '' });
596-
const codeReq = reactive({ path: '', expand: false, page: 1, pageSize: 100 });
618+
const codeReq = reactive({ path: '', expand: false, page: 1, pageSize: 100, isDetail: false });
597619
const fileUpload = reactive({ path: '' });
598620
const fileRename = reactive({ path: '', oldName: '' });
599621
const fileWget = reactive({ path: '' });
@@ -611,6 +633,7 @@ const wgetRef = ref();
611633
const moveRef = ref();
612634
const downloadRef = ref();
613635
const pathRef = ref();
636+
const toolRef = ref();
614637
const breadCrumbRef = ref();
615638
const chownRef = ref();
616639
const moveOpen = ref(false);
@@ -744,9 +767,9 @@ const moreButtons = ref([]);
744767
const updateButtons = async () => {
745768
await nextTick();
746769
if (!btnWrapper.value) return;
747-
const pathWidth = pathRef.value.offsetWidth;
770+
const pathWidth = toolRef.value.offsetWidth;
748771
const leftWidth = leftWrapper.value.offsetWidth;
749-
let num = Math.floor((pathWidth - leftWidth - 420) / 70);
772+
let num = Math.floor((pathWidth - leftWidth - 450) / 100);
750773
if (num < 0) {
751774
visibleButtons.value = toolButtons.value;
752775
moreButtons.value = [];
@@ -759,7 +782,7 @@ const updateButtons = async () => {
759782
const handlePath = () => {
760783
nextTick(function () {
761784
let breadCrumbWidth = breadCrumbRef.value.offsetWidth;
762-
let pathWidth = pathRef.value.offsetWidth;
785+
let pathWidth = toolRef.value.offsetWidth;
763786
if (pathWidth - breadCrumbWidth < 50 && paths.value.length > 1) {
764787
const removed = paths.value.shift();
765788
if (removed) hidePaths.value.push(removed);
@@ -896,10 +919,26 @@ const batchDelFiles = () => {
896919
deleteRef.value.acceptParams(selects.value);
897920
};
898921
899-
const getFileSize = (size: number) => {
922+
const formatFileSize = (size: number) => {
900923
return computeSize(size);
901924
};
902925
926+
const getFileSize = async (path: string, index: number) => {
927+
codeReq.path = path;
928+
codeReq.expand = true;
929+
codeReq.isDetail = true;
930+
data.value[index].btnLoading = true;
931+
await getFileContent(codeReq)
932+
.then(async (res) => {
933+
let newData = [...data.value];
934+
newData[index].size = res.data.size;
935+
data.value = newData;
936+
})
937+
.finally(() => {
938+
data.value[index].btnLoading = false;
939+
});
940+
};
941+
903942
const getDirSize = async (path: string, index: number) => {
904943
const req = {
905944
path: path,

0 commit comments

Comments
 (0)