✨ 优化发送上传状态与移动端界面

This commit is contained in:
orion committed 2026-09-11 08:49:02 +08:00
1 parent c2f0bf1675
commit 84ddf92b20
4 files changed
+52 -5

No files matched your search

+13 -2
View File
@@ -1,6 +1,6 @@
<template>
<div
class="rounded-2xl p-8 flex flex-col items-center justify-center border-2 border-dashed transition-all duration-300 group cursor-pointer relative min-h-72 overflow-hidden"
class="rounded-2xl p-5 sm:p-8 flex flex-col items-center justify-center border-2 border-dashed transition-all duration-300 group cursor-pointer relative min-h-56 sm:min-h-72 overflow-hidden"
:class="[
isDarkMode
? 'bg-gray-800/60 border-gray-600 hover:border-indigo-400'
@@ -64,7 +64,7 @@
]"
>
<span v-if="selectedFiles && selectedFiles.length > 1" class="block">
<span v-for="(f, i) in selectedFiles" :key="i" class="block truncate">{{ f.name }}</span>
<span v-for="f in uniqueFiles.slice(0, 3)" :key="fileKey(f)" class="block truncate">{{ f.name }}</span>
</span>
<span v-else class="block break-words line-clamp-2">
{{ displayText }}
@@ -214,6 +214,17 @@ const displayText = computed(() => {
return placeholderText.value
})
const uniqueFiles = computed(() => {
const seen = new Set<string>()
return props.selectedFiles.filter((file) => {
const key = `${file.name}-${file.size}-${file.lastModified}`
if (seen.has(key)) return false
seen.add(key)
return true
})
})
const fileKey = (file: File) => `${file.name}-${file.size}-${file.lastModified}`
const statusIcon = computed(() => {
if (isUploading.value) return LoaderIcon
if (isSuccess.value) return CheckCircleIcon
+18
View File
@@ -31,6 +31,10 @@ export function useSendFlow() {
const selectedRecord = ref<SentFileRecord | null>(null)
const isSubmitting = ref(false)
const fileHash = ref('')
const uploadStatus = ref<'idle' | 'uploading' | 'success' | 'error'>('idle')
const uploadedBytes = ref(0)
const totalBytes = ref(0)
const uploadError = ref('')
const sendRecords = computed(() => fileDataStore.shareData)
const uploadDescription = computed(() =>
t('send.uploadArea.descriptionWithLimit', {
@@ -62,7 +66,11 @@ export function useSendFlow() {
translate: t,
onProgress: (progress) => {
uploadProgress.value = progress
const total = selectedFile.value?.size || selectedFiles.value.reduce((sum, file) => sum + file.size, 0)
totalBytes.value = total
uploadedBytes.value = Math.round((progress / 100) * total)
},
onStatus: (status) => { uploadStatus.value = status },
onHashCalculated: (hash) => {
fileHash.value = hash
}
@@ -207,6 +215,7 @@ export function useSendFlow() {
const handleSubmit = async () => {
if (isSubmitting.value) return
isSubmitting.value = true
uploadStatus.value = 'uploading'
try {
if (sendType.value === 'file' && !selectedFile.value && selectedFiles.value.length === 0) {
@@ -273,6 +282,9 @@ export function useSendFlow() {
selectedFiles.value = []
textContent.value = ''
uploadProgress.value = 0
uploadedBytes.value = 0
totalBytes.value = 0
uploadStatus.value = 'idle'
resetPresignUpload()
selectedRecord.value = newRecord
await sentRecordActions.copyLink(newRecord)
@@ -280,6 +292,8 @@ export function useSendFlow() {
throw new Error(t('send.messages.serverError'))
}
} catch (error: unknown) {
uploadStatus.value = 'error'
uploadError.value = getErrorMessage(error, t('send.messages.sendFailed'))
alertStore.showAlert(getErrorMessage(error, t('send.messages.sendFailed')), 'error')
} finally {
uploadProgress.value = 0
@@ -319,6 +333,10 @@ export function useSendFlow() {
showDrawer,
selectedRecord,
isSubmitting,
uploadStatus,
uploadedBytes,
totalBytes,
uploadError,
sendRecords,
uploadDescription,
expirationOptions,
+12 -3
View File
@@ -14,6 +14,7 @@ type UseSendSubmitOptions = {
translate: Translate
onProgress: (progress: number) => void
onHashCalculated: (hash: string) => void
onStatus?: (status: 'idle' | 'uploading' | 'success' | 'error') => void
}
type SubmitFileOptions = {
@@ -106,9 +107,17 @@ export function useSendSubmit(options: UseSendSubmitOptions) {
throw new Error(options.translate('send.messages.selectFile'))
}
return enableChunk
? handleChunkUpload(fileToUpload, expireValue, expireStyle)
: handlePresignedUpload(fileToUpload, expireValue, expireStyle)
options.onStatus?.('uploading')
try {
const response = enableChunk
? await handleChunkUpload(fileToUpload, expireValue, expireStyle)
: await handlePresignedUpload(fileToUpload, expireValue, expireStyle)
if (response?.code === 200) options.onStatus?.('success')
return response
} catch (error) {
options.onStatus?.('error')
throw error
}
}
const submitText = ({ text, expireValue, expireStyle }: SubmitTextOptions) =>
+9
View File
@@ -26,10 +26,15 @@
:selected-file="selectedFile"
:selected-files="selectedFiles"
:progress="uploadProgress"
:upload-status="uploadStatus"
:uploaded-bytes="uploadedBytes"
:total-bytes="totalBytes"
:error-message="uploadError"
:description="uploadDescription"
@file-selected="handleFileSelected"
@files-selected="handleFilesSelected"
@file-drop="handleFileDrop"
@retry="handleSubmit"
/>
</div>
<div v-else key="text" class="grid grid-cols-1 gap-8">
@@ -165,6 +170,10 @@ const {
showDrawer,
selectedRecord,
isSubmitting,
uploadStatus,
uploadedBytes,
totalBytes,
uploadError,
sendRecords,
uploadDescription,
expirationOptions,