feat: 支持出库实况图多选上传

This commit is contained in:
Nixevol
2026-07-16 16:27:08 +08:00
parent cd84e0ab11
commit 4afd89ef12
4 changed files with 50 additions and 26 deletions
+1 -1
View File
@@ -446,6 +446,6 @@
- 登记出库、上链详情和批量任务结果等 Teleport 弹窗不再依赖组件内 `scoped` 选择器控制根卡片宽度,统一仿照“新建溯源模板”在 `n-modal` 上直接设置宽度和 `max-width: 94vw`;高度继续由全局 modal 规则限制视口并让内容区滚动。
- 未出库追溯码可直接点击“录入实况图”。前端在文件格式/大小初检通过后,先用表单中的出库时间和备注静默创建 `OutboundRecord`,成功后再调用现有图片上传接口;已出库时按钮显示“补录实况图”。后端“图片必须归属既有出库记录”的约束保持不变。
- 出库实况图复用现有作品媒体卡片规范:分隔线居中显示标题,不显示总张数;图片以 96px 卡片排列,上传卡片位于图片列表末尾,无图片时单独居中显示。图片仍分页加载。追溯码管理页的当前页单选/多选工具栏新增批量出库、批量上链,直接复用现有 IDS 异步任务接口。
- 出库实况图复用现有作品媒体卡片规范:分隔线居中显示标题,不显示总张数;图片以 96px 卡片排列,上传卡片位于图片列表末尾,无图片时单独居中显示。上传卡使用原生多选文件框,一次选择多张后先统一校验、只确保一次出库记录,再顺序调用现有单图接口,单张失败不阻断其他图片;图片仍分页加载。追溯码管理页的当前页单选/多选工具栏新增批量出库、批量上链,直接复用现有 IDS 异步任务接口。
- 单件上链只保留确认、提交成功提示和列表状态刷新,不主动打开或登记为“批量任务进度”;只有多选/筛选批量操作打开逐码进度弹窗。出库管理 Tabs 补齐 pane wrapper 的 flex 高度链,空结果时数据表区域仍填满页面、分页固定在底部。
- 验证范围按用户要求收敛为管理端生产构建、语言 JSON 解析和 `git diff --check`,均通过;未启动服务、未连接数据库,也未使用内置浏览器。
@@ -48,14 +48,15 @@
</template>
</div>
<n-upload
v-if="!disabled"
:show-file-list="false"
accept=".jpg,.jpeg,.png,.webp,image/jpeg,image/png,image/webp"
:custom-request="upload"
:disabled="uploading"
style="width: auto"
>
<label v-if="!disabled" class="image-upload">
<input
type="file"
accept=".jpg,.jpeg,.png,.webp,image/jpeg,image/png,image/webp"
multiple
hidden
:disabled="uploading"
@change="onPick"
/>
<div :class="['upload-tile', { uploading }]">
<n-spin v-if="uploading" size="small" />
<template v-else>
@@ -63,7 +64,7 @@
<span>{{ t(recorded ? 'pages.outbound.addImage' : 'pages.outbound.recordImage') }}</span>
</template>
</div>
</n-upload>
</label>
</div>
<n-empty v-else :description="t('common.msg.noData')" class="empty-images" />
</n-spin>
@@ -83,7 +84,6 @@
<script setup lang="ts">
import { onMounted, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import type { UploadCustomRequestOptions } from 'naive-ui';
import { NIcon } from 'naive-ui';
import { AddOutline, ArrowDownOutline, ArrowUpOutline } from '@vicons/ionicons5';
import { outboundApi } from '@/api';
@@ -148,25 +148,40 @@ function validateFile(file: File) {
return true;
}
async function upload({ file, onFinish, onError }: UploadCustomRequestOptions) {
const raw = file.file;
if (!raw || !validateFile(raw)) {
onError();
return;
}
async function onPick(event: Event) {
const input = event.target as HTMLInputElement;
const files = Array.from(input.files || []).filter(validateFile);
input.value = '';
if (!files.length || uploading.value) return;
uploading.value = true;
try {
await props.beforeUpload?.();
const data = new FormData();
data.append('file', raw);
await outboundApi.uploadImage(props.traceCodeId, data);
page.value = 1;
await load();
emit('changed');
message.success(t('common.msg.operationSuccess'));
onFinish();
let uploaded = 0;
let failed = 0;
for (const file of files) {
try {
const data = new FormData();
data.append('file', file);
await outboundApi.uploadImage(props.traceCodeId, data);
uploaded += 1;
} catch {
// 单张失败不阻断本次选择中的其他图片。
failed += 1;
}
}
if (uploaded > 0) {
page.value = 1;
await load();
emit('changed');
if (failed > 0) {
message.warning(t('pages.outbound.imageUploadPartial', { success: uploaded, fail: failed }));
} else {
message.success(t('pages.outbound.imageUploadSuccess', { n: uploaded }));
}
}
} catch {
onError();
// 首次出库记录保存失败时不继续上传。
} finally {
uploading.value = false;
}
@@ -240,6 +255,11 @@ defineExpose({ reload: load });
.image-grid.empty {
justify-content: center;
}
.image-upload {
display: block;
width: 96px;
height: 96px;
}
.image-tile,
.upload-tile {
position: relative;
+2
View File
@@ -453,6 +453,8 @@
"moveImageDown": "Move later",
"imageFormatTip": "Only JPG, JPEG, PNG, and WebP images are supported",
"imageSizeTip": "Each image must not exceed 100MB",
"imageUploadSuccess": "Uploaded {n} outbound photo(s)",
"imageUploadPartial": "Upload partially completed: {success} succeeded, {fail} failed",
"deleteImageConfirm": "Delete this outbound photo?",
"selectFile": "Select File",
"importing": "Importing…",
+2
View File
@@ -453,6 +453,8 @@
"moveImageDown": "后移",
"imageFormatTip": "仅支持 JPG、JPEG、PNG、WebP 图片",
"imageSizeTip": "单张图片不能超过 100MB",
"imageUploadSuccess": "已上传 {n} 张出库实况图",
"imageUploadPartial": "部分上传完成:成功 {success} 张,失败 {fail} 张",
"deleteImageConfirm": "确认删除该出库实况图?",
"selectFile": "选择文件",
"importing": "导入中…",