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

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> <template>
<div <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="[ :class="[
isDarkMode isDarkMode
? 'bg-gray-800/60 border-gray-600 hover:border-indigo-400' ? '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-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>
<span v-else class="block break-words line-clamp-2"> <span v-else class="block break-words line-clamp-2">
{{ displayText }} {{ displayText }}
@@ -214,6 +214,17 @@ const displayText = computed(() => {
return placeholderText.value 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(() => { const statusIcon = computed(() => {
if (isUploading.value) return LoaderIcon if (isUploading.value) return LoaderIcon
if (isSuccess.value) return CheckCircleIcon if (isSuccess.value) return CheckCircleIcon
+18
View File
@@ -31,6 +31,10 @@ export function useSendFlow() {
const selectedRecord = ref<SentFileRecord | null>(null) const selectedRecord = ref<SentFileRecord | null>(null)
const isSubmitting = ref(false) const isSubmitting = ref(false)
const fileHash = ref('') 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 sendRecords = computed(() => fileDataStore.shareData)
const uploadDescription = computed(() => const uploadDescription = computed(() =>
t('send.uploadArea.descriptionWithLimit', { t('send.uploadArea.descriptionWithLimit', {
@@ -62,7 +66,11 @@ export function useSendFlow() {
translate: t, translate: t,
onProgress: (progress) => { onProgress: (progress) => {
uploadProgress.value = 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) => { onHashCalculated: (hash) => {
fileHash.value = hash fileHash.value = hash
} }
@@ -207,6 +215,7 @@ export function useSendFlow() {
const handleSubmit = async () => { const handleSubmit = async () => {
if (isSubmitting.value) return if (isSubmitting.value) return
isSubmitting.value = true isSubmitting.value = true
uploadStatus.value = 'uploading'
try { try {
if (sendType.value === 'file' && !selectedFile.value && selectedFiles.value.length === 0) { if (sendType.value === 'file' && !selectedFile.value && selectedFiles.value.length === 0) {
@@ -273,6 +282,9 @@ export function useSendFlow() {
selectedFiles.value = [] selectedFiles.value = []
textContent.value = '' textContent.value = ''
uploadProgress.value = 0 uploadProgress.value = 0
uploadedBytes.value = 0
totalBytes.value = 0
uploadStatus.value = 'idle'
resetPresignUpload() resetPresignUpload()
selectedRecord.value = newRecord selectedRecord.value = newRecord
await sentRecordActions.copyLink(newRecord) await sentRecordActions.copyLink(newRecord)
@@ -280,6 +292,8 @@ export function useSendFlow() {
throw new Error(t('send.messages.serverError')) throw new Error(t('send.messages.serverError'))
} }
} catch (error: unknown) { } catch (error: unknown) {
uploadStatus.value = 'error'
uploadError.value = getErrorMessage(error, t('send.messages.sendFailed'))
alertStore.showAlert(getErrorMessage(error, t('send.messages.sendFailed')), 'error') alertStore.showAlert(getErrorMessage(error, t('send.messages.sendFailed')), 'error')
} finally { } finally {
uploadProgress.value = 0 uploadProgress.value = 0
@@ -319,6 +333,10 @@ export function useSendFlow() {
showDrawer, showDrawer,
selectedRecord, selectedRecord,
isSubmitting, isSubmitting,
uploadStatus,
uploadedBytes,
totalBytes,
uploadError,
sendRecords, sendRecords,
uploadDescription, uploadDescription,
expirationOptions, expirationOptions,
+12 -3
View File
@@ -14,6 +14,7 @@ type UseSendSubmitOptions = {
translate: Translate translate: Translate
onProgress: (progress: number) => void onProgress: (progress: number) => void
onHashCalculated: (hash: string) => void onHashCalculated: (hash: string) => void
onStatus?: (status: 'idle' | 'uploading' | 'success' | 'error') => void
} }
type SubmitFileOptions = { type SubmitFileOptions = {
@@ -106,9 +107,17 @@ export function useSendSubmit(options: UseSendSubmitOptions) {
throw new Error(options.translate('send.messages.selectFile')) throw new Error(options.translate('send.messages.selectFile'))
} }
return enableChunk options.onStatus?.('uploading')
? handleChunkUpload(fileToUpload, expireValue, expireStyle) try {
: handlePresignedUpload(fileToUpload, expireValue, expireStyle) 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) => const submitText = ({ text, expireValue, expireStyle }: SubmitTextOptions) =>
+9
View File
@@ -26,10 +26,15 @@
:selected-file="selectedFile" :selected-file="selectedFile"
:selected-files="selectedFiles" :selected-files="selectedFiles"
:progress="uploadProgress" :progress="uploadProgress"
:upload-status="uploadStatus"
:uploaded-bytes="uploadedBytes"
:total-bytes="totalBytes"
:error-message="uploadError"
:description="uploadDescription" :description="uploadDescription"
@file-selected="handleFileSelected" @file-selected="handleFileSelected"
@files-selected="handleFilesSelected" @files-selected="handleFilesSelected"
@file-drop="handleFileDrop" @file-drop="handleFileDrop"
@retry="handleSubmit"
/> />
</div> </div>
<div v-else key="text" class="grid grid-cols-1 gap-8"> <div v-else key="text" class="grid grid-cols-1 gap-8">
@@ -165,6 +170,10 @@ const {
showDrawer, showDrawer,
selectedRecord, selectedRecord,
isSubmitting, isSubmitting,
uploadStatus,
uploadedBytes,
totalBytes,
uploadError,
sendRecords, sendRecords,
uploadDescription, uploadDescription,
expirationOptions, expirationOptions,