fix: show existing files when editing version
- Load files data when fetching version info - Display uploaded file info with re-upload option - Preserve original file data when canceling re-upload - Add i18n for reupload button Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -101,6 +101,18 @@ async function fetchVersion() {
|
||||
formData.value.custom_download_url = ver.custom_download_url || ''
|
||||
formData.value.changelog = ver.changelog || ''
|
||||
formData.value.entry_file = ver.entry_file || ''
|
||||
|
||||
// 加载已有文件信息
|
||||
if (ver.file_path && ver.file_size) {
|
||||
uploadedData.value = {
|
||||
file_path: ver.file_path,
|
||||
file_size: ver.file_size,
|
||||
file_hash: ver.file_hash || '',
|
||||
files: ver.files || [],
|
||||
}
|
||||
// 保存原始数据
|
||||
originalUploadedData.value = { ...uploadedData.value }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
@@ -135,12 +147,18 @@ function handleFileSelect(event: Event) {
|
||||
}
|
||||
}
|
||||
|
||||
// 保存原始文件数据,用于取消重新上传时恢复
|
||||
const originalUploadedData = ref<UploadResponse | null>(null)
|
||||
|
||||
function removeFile() {
|
||||
formData.value.file = null
|
||||
uploadedData.value = null
|
||||
if (fileInputRef.value) {
|
||||
fileInputRef.value.value = ''
|
||||
}
|
||||
// 如果有原始文件数据,恢复显示
|
||||
if (originalUploadedData.value) {
|
||||
uploadedData.value = originalUploadedData.value
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadZipFile() {
|
||||
@@ -297,7 +315,34 @@ onMounted(() => {
|
||||
class="hidden"
|
||||
@change="handleFileSelect"
|
||||
>
|
||||
<div v-if="!formData.file" class="text-center">
|
||||
<!-- 显示已上传的文件 -->
|
||||
<div v-if="!formData.file && uploadedData" class="space-y-3">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-3">
|
||||
<FileArchive class="size-8 text-primary" />
|
||||
<div>
|
||||
<p class="text-sm font-medium text-green-600">
|
||||
{{ t('admin.versions.createForm.fileUploaded') }}
|
||||
</p>
|
||||
<p class="text-xs text-muted-foreground">
|
||||
{{ formatFileSize(uploadedData.file_size) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<UiButton variant="outline" size="sm" :disabled="saving || uploading" @click="fileInputRef?.click()">
|
||||
<Upload class="h-4 w-4 mr-2" />
|
||||
{{ t('admin.versions.createForm.reupload') }}
|
||||
</UiButton>
|
||||
</div>
|
||||
<div class="rounded-lg bg-muted/50 p-3">
|
||||
<div class="text-xs text-muted-foreground space-y-1">
|
||||
<p>{{ t('admin.versions.createForm.fileHash') }}: {{ uploadedData.file_hash.substring(0, 16) }}...</p>
|
||||
<p>{{ t('admin.versions.createForm.containsFiles', { count: uploadedData.files.length }) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 没有文件时显示上传区域 -->
|
||||
<div v-if="!formData.file && !uploadedData" class="text-center">
|
||||
<UploadCloud class="size-10 mx-auto text-muted-foreground mb-2" />
|
||||
<p class="text-sm text-muted-foreground mb-2">
|
||||
{{ t('admin.versions.createForm.dragOrClick') }}
|
||||
@@ -307,7 +352,8 @@ onMounted(() => {
|
||||
{{ t('admin.versions.createForm.selectFile') }}
|
||||
</UiButton>
|
||||
</div>
|
||||
<div v-else class="space-y-3">
|
||||
<!-- 选择新文件后显示 -->
|
||||
<div v-if="formData.file" class="space-y-3">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-3">
|
||||
<FileArchive class="size-8 text-primary" />
|
||||
@@ -322,7 +368,6 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<UiButton
|
||||
v-if="!uploadedData"
|
||||
size="sm"
|
||||
:disabled="uploading"
|
||||
@click="uploadZipFile"
|
||||
@@ -336,7 +381,7 @@ onMounted(() => {
|
||||
</UiButton>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="uploadedData" class="rounded-lg bg-muted/50 p-3">
|
||||
<div v-if="uploadedData && uploadedData.file_hash !== formData.file?.name" class="rounded-lg bg-muted/50 p-3">
|
||||
<div class="flex items-center gap-2 text-sm text-green-600 mb-2">
|
||||
<CheckCircle class="size-4" />
|
||||
<span>{{ t('admin.versions.createForm.fileUploaded') }}</span>
|
||||
|
||||
@@ -1504,6 +1504,7 @@
|
||||
"customDownloadUrlPlaceholder": "e.g., https://your-cdn.com/download/app.zip",
|
||||
"previewCustomDownloadUrl": "Download URL",
|
||||
"useDefault": "Use Default",
|
||||
"reupload": "Re-upload",
|
||||
"changelogPreview": "Changelog Preview",
|
||||
"noChangelog": "No changelog",
|
||||
"notUploaded": "Not uploaded",
|
||||
|
||||
@@ -1482,6 +1482,7 @@
|
||||
"customDownloadUrlPlaceholder": "例如: https://your-cdn.com/download/app.zip",
|
||||
"previewCustomDownloadUrl": "下载地址",
|
||||
"useDefault": "使用默认地址",
|
||||
"reupload": "重新上传",
|
||||
"changelogPreview": "更新日志预览",
|
||||
"noChangelog": "暂无更新日志",
|
||||
"notUploaded": "未上传",
|
||||
|
||||
Reference in New Issue
Block a user