refactor: 精简出库上链批量导入页

This commit is contained in:
Nixevol
2026-07-04 07:26:54 +08:00
parent 0f076dff45
commit 5ae3b12fff
4 changed files with 42 additions and 219 deletions
+2 -1
View File
@@ -108,13 +108,14 @@
- 艺术品档案删除约束(2026-07-04):艺术品档案删除仅用于误建/草稿类数据,后端 `ArtworkService.remove` 仍为软删除但会先检查该档案是否已有追溯码或查询日志;一旦存在业务痕迹则返回 `ARTWORK_IN_USE`,提示改为停用或归档。后台艺术品档案列表新增删除图标,仅 `codeCount=0` 时可点,已有追溯码的档案删除按钮置灰。
- 追溯码列表表头筛选(2026-07-04):`TraceCodePanel` 工具栏保留短码/追溯码/档案号等输入查询,批次、出库状态、分组、追溯码状态改为表头下拉筛选,支持多条件叠加;追溯码列表新增创建时间列。后端 `QueryTraceCodeDto` / `ExportTraceCodeDto` 新增 `outboundStatus=OUTBOUND|NOT_OUTBOUND`,`TraceCodeService` 用 `AND` 合并出库状态和关键词等 OR 条件,避免筛选互相覆盖;导出当前筛选会带上出库状态。
- 后台上传组件修复(2026-07-04):`MediaUpload.vue` 不再使用 Naive UI `n-upload` 的受控 `file-list + custom-request` 组合,改为原生文件 input + 自管上传状态。选择文件后立即显示上传占位,成功后回写 `{ key,url,name,type }`,失败时明确提示;该组件覆盖出库实况图、认证文件、动态字段图片/文件等入口。`MediaSorter.vue` 仍用于作品/节点多媒体排序上传。
- 出库与上链页面去重(2026-07-04):独立菜单“出库与上链”不再提供单条录入 tab,仅保留批量导入模板下载、Excel 上传、任务结果展示。单件出库/上链登记统一从艺术品档案的“追溯码管理”页行操作进入,继续复用后端 `PUT /outbound/trace-codes/:id` 能力。
## 当前代码基准与注意事项
- 代码优先级:后续开发以 `apps/api/prisma/schema.prisma`、后端服务实现、admin/client 当前页面为准;PRD 与技术方案中仍可能有旧“一物一码/绑定防伪码/SKU”表述,仅作需求背景参考。
- 当前核心模型:一款/一个档案 `Artwork` 多个批次 `Batch`,每批次多个实物追溯码 `TraceCode`;`archiveNo` 是款级唯一档案编号,`TraceCode` 是每套实物的一物一码载体,查询统计按档案聚合。
- 生码入口:主入口在艺术品档案列表的“数据管理”进入“批次与追溯码管理”;隐藏全局明细页也可生码但必须指定作品档案/款式。不存在“未绑定码池 → 绑定作品”的旧流程。
- 出库导入:以短码定位具体一套码,导入列不再包含 SKU 或手填档案编号;档案编号由作品自动生成并在日志/导出/C 端展示。
- 出库/上链:单件登记入口在追溯码管理页行操作中;独立“出库与上链”页只做批量导入。导入以短码定位具体一套码,导入列不再包含 SKU 或手填档案编号;档案编号由作品自动生成并在日志/导出/C 端展示。
- 后台列表约定:新列表页优先复用 `apps/admin/src/composables/useTablePage.ts`,页面根容器使用 `class="page table-page"`,`n-data-table` 使用 `class="table-fill" flex-height` 且关闭内置分页,底部统一外置 `n-pagination`;后端列表查询如继承 `PaginationDto`,需遵守 `pageSize=0` 不分页语义。
- 后台筛选约定:列表中输入型检索保留在工具栏;枚举/下拉型筛选优先放到对应表头下拉中,并把所有筛选条件集中到同一个 query 对象后叠加请求。
- 后台上传约定:单文件或少量附件优先复用 `MediaUpload.vue`,多图/视频排序场景使用 `MediaSorter.vue`;上传组件必须在选择文件后立即显示可见反馈,不能只依赖第三方 Upload 内部列表状态。
-4
View File
@@ -286,13 +286,9 @@
"assignGroup": "Assign group"
},
"outbound": {
"single": "Single Entry",
"import": "Batch Import",
"archiveNo": "Archive No.",
"outTime": "Outbound Time",
"outImage": "Outbound Photo",
"selectCode": "Select Trace Code",
"selectCodePlaceholder": "Search by short code / trace code / archive no.",
"onchainSection": "On-chain info (optional; filling a hash records the result)",
"txHashTip": "Paste the on-chain transaction/attestation hash",
"moreOnchainInfo": "More On-chain Info",
-4
View File
@@ -286,13 +286,9 @@
"assignGroup": "设为分组"
},
"outbound": {
"single": "单条录入",
"import": "批量导入",
"archiveNo": "档案编号",
"outTime": "出库时间",
"outImage": "出库实况图",
"selectCode": "选择追溯码",
"selectCodePlaceholder": "输入短码 / 追溯码 / 档案号搜索",
"onchainSection": "上链信息(选填,填写哈希即登记上链结果)",
"txHashTip": "粘贴链上交易/存证哈希",
"moreOnchainInfo": "更多上链信息",
+40 -210
View File
@@ -1,112 +1,54 @@
<template>
<div class="page">
<n-card :bordered="false">
<n-tabs type="line" animated>
<!-- 单条录入 -->
<n-tab-pane name="single" :tab="t('pages.outbound.single')">
<n-form label-placement="top" style="max-width: 560px">
<n-form-item :label="t('pages.outbound.selectCode')" required>
<n-select
v-model:value="form.traceCodeId"
filterable
remote
clearable
:loading="searching"
:options="codeOptions"
:placeholder="t('pages.outbound.selectCodePlaceholder')"
@search="searchCodes"
@update:value="onPickCode"
/>
</n-form-item>
<n-grid :cols="2" :x-gap="16">
<n-form-item-gi :label="t('pages.outbound.outTime')">
<n-date-picker v-model:formatted-value="form.outTime" value-format="yyyy-MM-dd HH:mm" type="datetime" clearable style="width: 100%" />
</n-form-item-gi>
<n-form-item-gi :label="t('common.label.remark')">
<n-input v-model:value="form.remark" />
</n-form-item-gi>
</n-grid>
<n-form-item :label="t('pages.outbound.outImage')">
<media-upload v-model="outImages" type="image" :max="1" />
</n-form-item>
<n-card :title="t('pages.outbound.import')" :bordered="false">
<n-alert type="info" :show-icon="true" style="margin-bottom: 16px">
{{ t('pages.outbound.tip') }}
</n-alert>
<n-space>
<n-button @click="downloadTemplate">
<template #icon><n-icon :component="DownloadOutline" /></template>
{{ t('common.action.downloadTemplate') }}
</n-button>
<n-upload
:show-file-list="false"
accept=".xlsx,.xls"
:custom-request="doImport"
:disabled="importing || !auth.canWrite"
>
<n-button type="primary" :loading="importing">
<template #icon><n-icon :component="CloudUploadOutline" /></template>
{{ t('pages.outbound.selectFile') }}
</n-button>
</n-upload>
</n-space>
<n-divider style="margin: 4px 0 14px">{{ t('pages.outbound.onchainSection') }}</n-divider>
<n-grid :cols="2" :x-gap="16">
<n-form-item-gi span="2" :label="t('pages.blockchain.txHash')">
<n-input v-model:value="form.txHash" :placeholder="t('pages.outbound.txHashTip')" />
</n-form-item-gi>
<n-form-item-gi :label="t('pages.blockchain.onchainAt')">
<n-date-picker v-model:formatted-value="form.onchainAt" value-format="yyyy-MM-dd HH:mm" type="datetime" clearable style="width: 100%" />
</n-form-item-gi>
<n-form-item-gi span="2">
<n-collapse>
<n-collapse-item :title="t('pages.outbound.moreOnchainInfo')" name="more-onchain">
<n-form-item :label="t('pages.blockchain.blockHeight')">
<n-input-number v-model:value="form.blockHeight" :min="0" style="width: 100%" />
</n-form-item>
</n-collapse-item>
</n-collapse>
</n-form-item-gi>
</n-grid>
<n-button type="primary" :loading="saving" :disabled="!auth.canWrite || !form.traceCodeId" @click="saveSingle">
{{ t('common.action.save') }}
</n-button>
</n-form>
</n-tab-pane>
<!-- 批量导入 -->
<n-tab-pane name="import" :tab="t('pages.outbound.import')">
<n-alert type="info" :show-icon="true" style="margin-bottom: 16px">{{ t('pages.outbound.tip') }}</n-alert>
<n-space>
<n-button @click="downloadTemplate">
<template #icon><n-icon :component="DownloadOutline" /></template>
{{ t('common.action.downloadTemplate') }}
</n-button>
<n-upload
:show-file-list="false"
accept=".xlsx,.xls"
:custom-request="doImport"
:disabled="importing || !auth.canWrite"
>
<n-button type="primary" :loading="importing">
<template #icon><n-icon :component="CloudUploadOutline" /></template>
{{ t('pages.outbound.selectFile') }}
</n-button>
</n-upload>
</n-space>
<n-card v-if="result" embedded :title="t('pages.outbound.importResult')" style="margin-top: 16px">
<n-space align="center" size="large">
<n-statistic :label="t('common.label.total', { n: result.total })" :value="result.total" />
<n-statistic :label="t('pages.outbound.successCount')">
<span style="color: #138a72">{{ result.successCount }}</span>
</n-statistic>
<n-statistic :label="t('pages.outbound.failCount')">
<span style="color: #c0392b">{{ result.failCount }}</span>
</n-statistic>
<n-tag :type="statusType(result.status)">{{ t(`common.status.${result.status}`) }}</n-tag>
<n-button v-if="result.resultFileUrl" text tag="a" :href="result.resultFileUrl" target="_blank" type="primary">
<template #icon><n-icon :component="DownloadOutline" /></template>
{{ t('pages.outbound.downloadResult') }}
</n-button>
</n-space>
</n-card>
</n-tab-pane>
</n-tabs>
<n-card v-if="result" embedded :title="t('pages.outbound.importResult')" style="margin-top: 16px">
<n-space align="center" size="large">
<n-statistic :label="t('common.label.total', { n: result.total })" :value="result.total" />
<n-statistic :label="t('pages.outbound.successCount')">
<span style="color: #138a72">{{ result.successCount }}</span>
</n-statistic>
<n-statistic :label="t('pages.outbound.failCount')">
<span style="color: #c0392b">{{ result.failCount }}</span>
</n-statistic>
<n-tag :type="statusType(result.status)">{{ t(`common.status.${result.status}`) }}</n-tag>
<n-button v-if="result.resultFileUrl" text tag="a" :href="result.resultFileUrl" target="_blank" type="primary">
<template #icon><n-icon :component="DownloadOutline" /></template>
{{ t('pages.outbound.downloadResult') }}
</n-button>
</n-space>
</n-card>
</n-card>
</div>
</template>
<script setup lang="ts">
import { onBeforeUnmount, onMounted, reactive, ref } from 'vue';
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
import type { UploadCustomRequestOptions } from 'naive-ui';
import { DownloadOutline, CloudUploadOutline } from '@vicons/ionicons5';
import dayjs from 'dayjs';
import { jobApi, outboundApi, traceCodeApi, post } from '@/api';
import { jobApi, post } from '@/api';
import { useAuthStore } from '@/stores/auth';
import MediaUpload from '@/components/MediaUpload.vue';
import { message } from '@/utils/feedback';
import { statusType } from '@/utils/format';
import { downloadFile } from '@/utils/download';
@@ -114,117 +56,13 @@ import { downloadFile } from '@/utils/download';
const { t } = useI18n();
const auth = useAuthStore();
/* 单条录入 */
const saving = ref(false);
const searching = ref(false);
const codeOptions = ref<{ label: string; value: string; raw: any }[]>([]);
const outImages = ref<any[]>([]);
const form = reactive<any>({
traceCodeId: null,
outTime: null,
remark: '',
txHash: '',
onchainAt: null,
blockHeight: null,
});
let searchTimer: ReturnType<typeof setTimeout> | null = null;
let searchSeq = 0;
function formatDateTime(value?: string | Date | null) {
return value ? dayjs(value).format('YYYY-MM-DD HH:mm') : null;
}
function toNumber(value: unknown) {
if (value === null || value === undefined || value === '') return null;
const n = Number(value);
return Number.isFinite(n) ? n : null;
}
function fileName(key: string) {
return key.split('/').pop() || key;
}
function codeLabel(c: any) {
return [
c.shortCode,
c.artwork?.archiveNo,
c.artwork?.title,
c.batch?.batchNo,
].filter(Boolean).join(' · ');
}
function resetCodeDetail() {
form.outTime = null;
form.remark = '';
form.txHash = '';
form.onchainAt = null;
form.blockHeight = null;
outImages.value = [];
}
async function loadCodeOptions(keyword = '') {
const seq = ++searchSeq;
searching.value = true;
try {
const res: any = await traceCodeApi.list({ keyword: keyword || undefined, pageSize: 20 });
if (seq !== searchSeq) return;
codeOptions.value = res.list.map((c: any) => ({
label: codeLabel(c),
value: String(c.id),
raw: c,
}));
} finally {
if (seq === searchSeq) searching.value = false;
}
}
function searchCodes(keyword: string) {
if (searchTimer) clearTimeout(searchTimer);
searchTimer = setTimeout(() => loadCodeOptions(keyword), 300);
}
function onPickCode(id: string | null, opt: any) {
if (!id) {
resetCodeDetail();
return;
}
const c = opt?.raw;
if (!c) return;
const latestProof = c.latestProof;
form.outTime = formatDateTime(c.outTime);
form.remark = c.remark || '';
form.txHash = latestProof?.txHash || '';
form.onchainAt = formatDateTime(latestProof?.onchainAt);
form.blockHeight = toNumber(latestProof?.blockHeight);
outImages.value = c.outImage ? [{ key: c.outImage, url: c.outImageUrl || c.outImage, name: fileName(c.outImage) }] : [];
}
async function saveSingle() {
if (!form.traceCodeId) return;
saving.value = true;
try {
await outboundApi.updateSingle(form.traceCodeId, {
outTime: form.outTime ? dayjs(form.outTime).toISOString() : null,
outImageKey: outImages.value[0]?.key ?? null,
txHash: form.txHash || undefined,
onchainAt: form.onchainAt ? dayjs(form.onchainAt).toISOString() : undefined,
blockHeight: form.blockHeight ?? undefined,
remark: form.remark || null,
});
message.success(t('common.msg.saved'));
} finally {
saving.value = false;
}
}
/* 批量导入 */
const importing = ref(false);
const result = ref<any>(null);
async function downloadTemplate() {
await downloadFile('/outbound/import/template', 'outbound-import-template.xlsx');
}
async function doImport({ file, onFinish, onError }: UploadCustomRequestOptions) {
importing.value = true;
result.value = null;
@@ -249,12 +87,4 @@ async function doImport({ file, onFinish, onError }: UploadCustomRequestOptions)
importing.value = false;
}
}
onMounted(() => {
loadCodeOptions();
});
onBeforeUnmount(() => {
if (searchTimer) clearTimeout(searchTimer);
});
</script>