🐛 fix: 保留上传收尾提示并支持重试取件码

* 在上传框持续显示校验提示、进度和明确的收尾失败状态
* 提供复用原上传会话的取件码重试入口,避免重复上传
* 调整忙碌与错误布局,验证桌面及手机状态提示和按钮可见性
This commit is contained in:
orion committed 2026-10-06 14:43:44 +08:00
1 parent b67d36d8a0
commit 9d29489be1
9 files changed
+85 -10

No files matched your search

+11 -6
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 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="[
isDarkMode
? 'bg-gray-800/60 border-gray-600 hover:border-[#9fc9bd]'
@@ -10,6 +10,7 @@
? 'border-indigo-400 bg-indigo-500/10 shadow-lg shadow-indigo-900/30'
: 'border-indigo-500 bg-indigo-50 shadow-lg shadow-indigo-100'
: '',
isUploading || hasError ? 'p-4' : 'p-8',
statusClass
]"
role="button"
@@ -51,13 +52,14 @@
<!-- 上传状态图标 -->
<component
:is="statusIcon"
:class="['relative z-10 w-16 h-16 transition-colors duration-300', statusIconClass]"
:class="['relative z-10 shrink-0 transition-colors duration-300', isUploading || hasError ? 'w-8 h-8' : 'w-16 h-16', statusIconClass]"
/>
<!-- 文件名或占位文本 -->
<p
:class="[
'relative z-10 mt-4 text-sm transition-colors duration-300 w-full text-center',
'relative z-10 text-sm transition-colors duration-300 w-full text-center',
isUploading || hasError ? 'mt-2' : 'mt-4',
isDarkMode
? 'text-gray-400 group-hover:text-indigo-400'
: 'text-gray-600 group-hover:text-indigo-600'
@@ -72,12 +74,12 @@
</p>
<!-- 状态描述或默认描述 -->
<p :class="['relative z-10 mt-2 text-xs text-center leading-5', statusDescriptionClass]">
<p role="status" aria-live="polite" :class="['relative z-10 mt-2 text-xs text-center leading-5', statusDescriptionClass]">
{{ statusDescription }}
</p>
<div
v-if="selectedFiles.length > 1"
v-if="selectedFiles.length > 1 && !isUploading && !hasError"
class="relative z-10 mt-4 flex flex-wrap items-center justify-center gap-2"
>
<span
@@ -113,7 +115,7 @@
v-if="hasError && allowRetry"
type="button"
@click.stop="handleRetry"
class="fcb-action mt-3 min-h-11 rounded-lg px-4 py-2 text-sm transition-colors duration-200"
class="fcb-action relative z-10 shrink-0 mt-2 min-h-9 rounded-lg px-4 py-2 text-sm transition-colors duration-200"
:class="[
isDarkMode
? 'bg-indigo-600 hover:bg-indigo-500 text-white'
@@ -272,6 +274,9 @@ const statusDescriptionClass = computed(() => {
if (isSuccess.value) {
return isDarkMode.value ? 'text-green-400' : 'text-green-500'
}
if (isUploading.value) {
return isDarkMode.value ? 'text-indigo-300 font-medium' : 'text-indigo-700 font-medium'
}
return isDarkMode.value ? 'text-gray-500' : 'text-gray-400'
})
+16 -1
View File
@@ -36,6 +36,9 @@ export function useSendFlow() {
const cleanupPending = ref(false)
const submitMessage = ref('')
const isFinalizing = ref(false)
const uploadErrorMessage = ref('')
const completionRetryPending = ref(false)
const uploadStatus = computed(() => isFinalizing.value ? 'confirming' : isSubmitting.value ? 'uploading' : uploadErrorMessage.value ? 'error' : 'idle')
const fileHash = ref('')
const sendRecords = computed(() => fileDataStore.shareData)
const uploadDescription = computed(() =>
@@ -62,7 +65,7 @@ export function useSendFlow() {
alertStore.showAlert(message, type)
}
const sentRecordActions = createSentRecordActions(notifyCopyResult)
const { requestCancel, needsCleanup, retryCleanup, isUploadInterrupted, resetPresignUpload, submitFile, submitText } = useSendSubmit({
const { requestCancel, needsCleanup, retryCleanup, isUploadInterrupted, canRetryCompletion, resetPresignUpload, submitFile, submitText } = useSendSubmit({
getMaxFileSize: () => configStore.uploadSizeLimit,
getChunkSizeMB: () => config.value.chunkSizeMB,
notify: (message, type) => alertStore.showAlert(message, type),
@@ -78,6 +81,11 @@ export function useSendFlow() {
}
})
watch([selectedFile, selectedFiles], () => {
uploadErrorMessage.value = ''
completionRetryPending.value = false
})
const checkOpenUpload = () => {
if (config.value.openUpload === 0 && !adminStore.hasToken) {
alertStore.showAlert(t('send.messages.guestUploadDisabled'), 'error')
@@ -224,6 +232,8 @@ export function useSendFlow() {
if (isSubmitting.value || cleanupPending.value) return
isSubmitting.value = true
submitMessage.value = ''
uploadErrorMessage.value = ''
completionRetryPending.value = false
try {
if (sendType.value === 'file' && !selectedFile.value && selectedFiles.value.length === 0) {
@@ -302,6 +312,10 @@ export function useSendFlow() {
} else {
cleanupPending.value = needsCleanup()
submitMessage.value = cleanupPending.value ? '传输已停止,临时文件清理未完成,请重试中断' : getErrorMessage(error, t('send.messages.sendFailed'))
completionRetryPending.value = isFinalizing.value && Boolean(selectedFile.value) && canRetryCompletion(error) && !cleanupPending.value
uploadErrorMessage.value = completionRetryPending.value
? t('send.uploadArea.status.confirmationFailed')
: submitMessage.value
alertStore.showAlert(submitMessage.value, 'error')
}
} finally {
@@ -364,6 +378,7 @@ export function useSendFlow() {
isSubmitting,
isCancelling, cleanupPending, submitMessage, cancelUpload,
isFinalizing,
uploadStatus, uploadErrorMessage, completionRetryPending,
sendRecords,
uploadDescription,
expirationOptions,
+2 -2
View File
@@ -1,4 +1,4 @@
import { FileService, PresignUploadService, uploadChunkedFile, UploadCancellation, UploadInterrupted, isUploadInterrupted } from '@/services'
import { FileService, PresignUploadService, uploadChunkedFile, UploadCancellation, UploadInterrupted, isUploadInterrupted, isTransientCompletionError } from '@/services'
import type { AlertType, ApiResponse, ExpireStyle, UploadProgress } from '@/types'
import { calculateFileHash, packFilesAsZip } from '@/utils/file-processing'
import { usePresignedUpload } from './usePresignedUpload'
@@ -139,7 +139,7 @@ export function useSendSubmit(options: UseSendSubmitOptions) {
FileService.uploadText(text, expireValue, expireStyle)
return {
requestCancel, needsCleanup, retryCleanup, isUploadInterrupted,
requestCancel, needsCleanup, retryCleanup, isUploadInterrupted, canRetryCompletion: isTransientCompletionError,
resetPresignUpload,
submitFile,
submitText
+2
View File
@@ -309,10 +309,12 @@ export default {
descriptionWithLimit: 'Supports common formats, up to {size}',
retry: 'Retry',
selectedFiles: '{count} files selected',
retryConfirmation: 'Retry retrieval code',
status: {
initializing: 'Preparing upload...',
uploading: 'Uploading files...',
confirming: 'Verifying file before creating a retrieval code…',
confirmationFailed: 'File uploaded, but no retrieval code was received. Retry without uploading again.',
success: 'Upload complete!'
}
},
+2
View File
@@ -309,10 +309,12 @@ export default {
descriptionWithLimit: '支持各种常见格式,最大{size}',
retry: '重试',
selectedFiles: '已选择 {count} 个文件',
retryConfirmation: '重试生成取件码',
status: {
initializing: '正在初始化上传...',
uploading: '正在上传文件...',
confirming: '正在校验文件,完成后生成取件码…',
confirmationFailed: '文件已上传,暂未取得取件码。请重试生成取件码,无需重新上传。',
success: '上传成功!'
}
},
+2
View File
@@ -13,3 +13,5 @@ export { LocalShareService } from './local-share'
export { UploadCancellation, UploadInterrupted, isUploadInterrupted } from './upload-cancellation'
export { DownloadCheckService } from './download-check'
export { isTransientCompletionError } from './upload-completion'
+6 -1
View File
@@ -31,7 +31,11 @@
:uploaded-bytes="uploadedBytes"
:total-bytes="totalBytes"
:disabled="isSubmitting || cleanupPending"
:upload-status="isFinalizing ? 'confirming' : isSubmitting ? 'uploading' : 'idle'"
:upload-status="uploadStatus"
:error-message="uploadErrorMessage"
:allow-retry="completionRetryPending"
:retry-text="t('send.uploadArea.retryConfirmation')"
@retry="handleSubmit"
:description="uploadDescription"
@file-selected="handleFileSelected"
@files-selected="handleFilesSelected"
@@ -177,6 +181,7 @@ const {
isSubmitting,
isCancelling, cleanupPending, submitMessage, cancelUpload,
isFinalizing,
uploadStatus, uploadErrorMessage, completionRetryPending,
sendRecords,
uploadDescription,
expirationOptions,
+36
View File
@@ -52,3 +52,39 @@ test('nonempty file initialization still carries its actual size',async()=>{
assert.equal(request.file_size,8);assert.equal(request.chunk_size,8);assert.equal(f.isSubmitting.value,false)
}finally{service.initChunkUpload=original}
})
test('waiting for a code remains busy, then completion failure stays visible and retry reuses the session',async t=>{
t.mock.timers.enable({apis:['setTimeout']})
const original={init:service.initChunkUpload,chunk:service.uploadChunk,complete:service.completeChunkUpload}
let inits=0,chunks=0,checks=0,release
service.initChunkUpload=async()=>{inits++;return {code:200,detail:{upload_id:'waiting-session',chunk_size:1024,uploaded_chunks:[]}}}
service.uploadChunk=async()=>{chunks++;return {code:200}}
service.completeChunkUpload=async id=>{
assert.equal(id,'waiting-session');checks++
if(checks===1)return new Promise(resolve=>{release=resolve})
throw Object.assign(Error('remote temporarily unavailable'),{response:{status:503}})
}
try{
const {f}=await flow();f.selectedFile.value=new File(['payload'],'waiting.bin')
// Flush the selection watcher before starting, as the browser does.
await Promise.resolve()
const pending=f.handleSubmit()
for(let i=0;i<30&&!release;i++)await new Promise(r=>setImmediate(r))
assert.ok(release);assert.equal(f.uploadStatus.value,'confirming');assert.equal(f.isSubmitting.value,true)
assert.equal(f.uploadedBytes.value,7);assert.equal(f.uploadProgress.value,99)
release({code:202})
for(let i=0;i<8;i++){await new Promise(r=>setImmediate(r));t.mock.timers.tick(3000)}
await pending
assert.equal(f.uploadStatus.value,'error');assert.equal(f.isSubmitting.value,false)
assert.equal(f.completionRetryPending.value,true)
assert.match(f.uploadErrorMessage.value,/暂未取得取件码/)
let retryRelease
service.completeChunkUpload=async id=>{assert.equal(id,'waiting-session');return new Promise(resolve=>{retryRelease=resolve})}
const retry=f.handleSubmit()
for(let i=0;i<30&&!retryRelease;i++)await new Promise(r=>setImmediate(r))
assert.ok(retryRelease);assert.equal(f.uploadStatus.value,'confirming');assert.equal(f.uploadErrorMessage.value,'')
assert.equal(inits,1);assert.equal(chunks,1)
// A transport-style error with HTTP 403 must not offer completion retry.
retryRelease(Promise.reject(Object.assign(Error('forbidden'),{response:{status:403}})));await retry
assert.equal(f.completionRetryPending.value,false)
}finally{service.initChunkUpload=original.init;service.uploadChunk=original.chunk;service.completeChunkUpload=original.complete;t.mock.timers.reset()}
})
+8
View File
@@ -24,3 +24,11 @@ test('retrieve form enables both complete legacy and current codes without trunc
}
const html=await render(Form,{modelValue:'ABC',inputStatus:{readonly:false,loading:false}});assert.ok(/<button[^>]* disabled(?:=|>| )/.test(html))
})
test('verification status is announced in the upload box and failure exposes a retry action',async()=>{
const waiting=await render(Area,{selectedFile:new File(['data'],'waiting.apk'),uploadStatus:'confirming',uploadedBytes:4,totalBytes:4,progress:99})
assert.match(waiting,/role="status" aria-live="polite"/);assert.match(waiting,/正在校验文件,完成后生成取件码/)
assert.match(waiting,/aria-busy="true"/);assert.match(waiting,/animate-spin/);assert.match(waiting,/disabled/)
assert.ok(!waiting.includes('支持各种常见格式'))
const failed=await render(Area,{uploadStatus:'error',errorMessage:zh.send.uploadArea.status.confirmationFailed,retryText:zh.send.uploadArea.retryConfirmation})
assert.match(failed,/暂未取得取件码/);assert.match(failed,/重试生成取件码/);assert.match(failed,/aria-busy="false"/)
})