Skip to content

Commit ee1e4bb

Browse files
committed
feat: 添加图片预览功能,支持多图展示和缩略图显示
1 parent 984b5d2 commit ee1e4bb

5 files changed

Lines changed: 70 additions & 15 deletions

File tree

components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ declare module 'vue' {
5252
NHighlight: typeof import('naive-ui')['NHighlight']
5353
NIcon: typeof import('naive-ui')['NIcon']
5454
NImage: typeof import('naive-ui')['NImage']
55+
NImageGroup: typeof import('naive-ui')['NImageGroup']
5556
NInput: typeof import('naive-ui')['NInput']
5657
NInputGroup: typeof import('naive-ui')['NInputGroup']
5758
NInputGroupLabel: typeof import('naive-ui')['NInputGroupLabel']
@@ -135,6 +136,7 @@ declare global {
135136
const NHighlight: typeof import('naive-ui')['NHighlight']
136137
const NIcon: typeof import('naive-ui')['NIcon']
137138
const NImage: typeof import('naive-ui')['NImage']
139+
const NImageGroup: typeof import('naive-ui')['NImageGroup']
138140
const NInput: typeof import('naive-ui')['NInput']
139141
const NInputGroup: typeof import('naive-ui')['NInputGroup']
140142
const NInputGroupLabel: typeof import('naive-ui')['NInputGroupLabel']

src/api/types/file.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ export interface MyFile {
265265
*/
266266
upt: number;
267267
v_img: string;
268+
/**
269+
* 图片缩略图地址
270+
*/
271+
thumb?: string;
272+
/**
273+
* 原图地址
274+
*/
275+
uo?: string;
268276
}
269277

270278
export interface FileLabel {

src/components/FileExplorer/FileExplorer.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,5 +573,9 @@
573573
getFileList();
574574
}
575575
576-
defineExpose({ navigate, refresh });
576+
function getItems(): MyFile[] {
577+
return data.value;
578+
}
579+
580+
defineExpose({ navigate, refresh, getItems });
577581
</script>

src/components/FileExplorer/components/FileItemView/FileItemView.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868

6969
<!-- 图标 -->
7070
<div class="w-16 h-16 flex items-center justify-center mb-2">
71-
<span class="text-4xl leading-none">{{ icon }}</span>
71+
<img v-if="item.thumb" :src="item.thumb" class="w-full h-full object-cover rounded" />
72+
<span v-else class="text-4xl leading-none">{{ icon }}</span>
7273
</div>
7374

7475
<!-- 文件名 -->
@@ -103,7 +104,8 @@
103104

104105
<!-- 图标 -->
105106
<div class="w-8 h-8 flex items-center justify-center shrink-0">
106-
<span class="text-xl leading-none">{{ icon }}</span>
107+
<img v-if="item.thumb" :src="item.thumb" class="w-full h-full object-cover rounded" />
108+
<span v-else class="text-xl leading-none">{{ icon }}</span>
107109
</div>
108110

109111
<!-- 名称 -->

src/views/Home/HomeView.vue

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
<template>
2-
<FileExplorer
3-
ref="explorerRef"
4-
v-model:cid="cid"
5-
v-model:view-mode="userStore.homeViewMode"
6-
v-model:sort-config="userStore.homeSortConfig"
7-
class="h-[calc(100vh-59px)]"
8-
@download="handleDownload"
9-
@batch-download="handleBatchDownload"
10-
@upload-file="handleUploadFiles"
11-
@upload-folder="handleUploadFolder"
12-
@open-file="handleOpenFile"
13-
/>
2+
<div>
3+
<FileExplorer
4+
ref="explorerRef"
5+
v-model:cid="cid"
6+
v-model:view-mode="userStore.homeViewMode"
7+
v-model:sort-config="userStore.homeSortConfig"
8+
class="h-[calc(100vh-59px)]"
9+
@download="handleDownload"
10+
@batch-download="handleBatchDownload"
11+
@upload-file="handleUploadFiles"
12+
@upload-folder="handleUploadFolder"
13+
@open-file="handleOpenFile"
14+
/>
15+
<NImageGroup
16+
v-model:show="imgPreviewVisible"
17+
v-model:current="imgPreviewIndex"
18+
:src-list="imgPreviewList"
19+
:render-toolbar="renderToolbar"
20+
/>
21+
</div>
1422
</template>
1523

1624
<script setup lang="ts">
25+
import type { ImageRenderToolbarProps } from 'naive-ui';
1726
import { open } from '@tauri-apps/plugin-dialog';
1827
import { WebviewWindow } from '@tauri-apps/api/webviewWindow';
1928
import { emit, listen } from '@tauri-apps/api/event';
@@ -27,6 +36,9 @@
2736
const userStore = useUserStore();
2837
const explorerRef = useTemplateRef('explorerRef');
2938
const cid = ref('0');
39+
const imgPreviewVisible = ref(false);
40+
const imgPreviewList = ref<string[]>([]);
41+
const imgPreviewIndex = ref(0);
3042
3143
const { download: downloadFile, batchDownload: batchDownloadFiles } = useDownloadManager();
3244
@@ -82,6 +94,20 @@
8294
} catch (e) {
8395
console.error(e);
8496
}
97+
} else if (file.uo) {
98+
// 收集当前目录下所有图片文件,支持多图预览
99+
const allItems = explorerRef.value?.getItems() || [];
100+
const imageFiles = allItems.filter((f) => f.uo);
101+
if (imageFiles.length > 0) {
102+
imgPreviewList.value = imageFiles.map((f) => f.uo!);
103+
const idx = imageFiles.findIndex((f) => f.fid === file.fid);
104+
imgPreviewIndex.value = idx >= 0 ? idx : 0;
105+
} else {
106+
// 兜底:至少预览当前点击的图片
107+
imgPreviewList.value = [file.uo];
108+
imgPreviewIndex.value = 0;
109+
}
110+
imgPreviewVisible.value = true;
85111
}
86112
};
87113
@@ -161,4 +187,17 @@
161187
message.error('上传任务添加失败');
162188
}
163189
};
190+
191+
const renderToolbar = ({ nodes }: ImageRenderToolbarProps) => {
192+
return [
193+
nodes.prev,
194+
nodes.next,
195+
nodes.rotateCounterclockwise,
196+
nodes.rotateClockwise,
197+
nodes.resizeToOriginalSize,
198+
nodes.zoomOut,
199+
nodes.zoomIn,
200+
nodes.close,
201+
];
202+
};
164203
</script>

0 commit comments

Comments
 (0)