|
46 | 46 |
|
47 | 47 | <div |
48 | 48 | v-else |
49 | | - class="flex items-center justify-center py-1 flex-wrap gap-2 w-full gap-2 mt-1 mb-4 px-4" |
| 49 | + class="flex items-center justify-center py-1 flex-wrap gap-2 w-full mt-1 mb-4 px-4" |
50 | 50 | > |
51 | 51 | <template v-for="(file, index) in selectedFiles" :key="index"> |
52 | 52 | <div |
53 | 53 | class="text-sm text-lightDropzoneIcon dark:text-darkDropzoneIcon bg-lightDropzoneBackgroundHover dark:bg-darkDropzoneBackgroundHover rounded-md |
54 | 54 | flex items-center gap-1 px-2 py-1 group" |
55 | 55 | > |
56 | 56 | <IconFileSolid class="w-4 h-4 flex-shrink-0" /> |
57 | | - <span class="truncate max-w-[200px]">{{ file.name }}</span> |
| 57 | + <span |
| 58 | + class="truncate max-w-[200px]" |
| 59 | + :title="file.name" |
| 60 | + > |
| 61 | + {{ shortenFileName(file.name) }} |
| 62 | + </span> |
58 | 63 | <span class="text-xs">({{ humanifySize(file.size) }})</span> |
59 | 64 | <button |
60 | 65 | type="button" |
@@ -123,6 +128,19 @@ const selectedFiles: Ref<{ |
123 | 128 |
|
124 | 129 | const storedFiles: Ref<File[]> = ref([]); |
125 | 130 |
|
| 131 | +function shortenFileName(name: string, maxLength = 24) { |
| 132 | + if (name.length <= maxLength) return name; |
| 133 | +
|
| 134 | + const lastDotIndex = name.lastIndexOf('.'); |
| 135 | + const hasExtension = lastDotIndex > 0 && lastDotIndex < name.length - 1; |
| 136 | + const extension = hasExtension ? name.slice(lastDotIndex + 1) : ''; |
| 137 | + const baseName = hasExtension ? name.slice(0, lastDotIndex) : name; |
| 138 | +
|
| 139 | + const startName = baseName.slice(0, 12); |
| 140 | + const endName = baseName.split('').reverse().slice(0, 4).reverse().join(''); |
| 141 | + return hasExtension ? `${startName}...${endName}.${extension}` : `${startName}...${endName}`; |
| 142 | +} |
| 143 | +
|
126 | 144 | watch(() => props.modelValue, (files) => { |
127 | 145 | if (files && files.length > 0) { |
128 | 146 | selectedFiles.value = Array.from(files).map(file => ({ |
|
0 commit comments