|
1 | 1 | <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> |
14 | 22 | </template> |
15 | 23 |
|
16 | 24 | <script setup lang="ts"> |
| 25 | + import type { ImageRenderToolbarProps } from 'naive-ui'; |
17 | 26 | import { open } from '@tauri-apps/plugin-dialog'; |
18 | 27 | import { WebviewWindow } from '@tauri-apps/api/webviewWindow'; |
19 | 28 | import { emit, listen } from '@tauri-apps/api/event'; |
|
27 | 36 | const userStore = useUserStore(); |
28 | 37 | const explorerRef = useTemplateRef('explorerRef'); |
29 | 38 | const cid = ref('0'); |
| 39 | + const imgPreviewVisible = ref(false); |
| 40 | + const imgPreviewList = ref<string[]>([]); |
| 41 | + const imgPreviewIndex = ref(0); |
30 | 42 |
|
31 | 43 | const { download: downloadFile, batchDownload: batchDownloadFiles } = useDownloadManager(); |
32 | 44 |
|
|
82 | 94 | } catch (e) { |
83 | 95 | console.error(e); |
84 | 96 | } |
| 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; |
85 | 111 | } |
86 | 112 | }; |
87 | 113 |
|
|
161 | 187 | message.error('上传任务添加失败'); |
162 | 188 | } |
163 | 189 | }; |
| 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 | + }; |
164 | 203 | </script> |
0 commit comments