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

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

+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) =>