refactor: 合并档案与实物码管理入口

This commit is contained in:
Nixevol
2026-07-03 04:05:58 +08:00
parent 96552857f6
commit 8d8bf36d08
12 changed files with 610 additions and 561 deletions
+10 -87
View File
@@ -185,56 +185,23 @@
</n-card>
</n-grid-item>
<!-- 追溯码(一款多码) -->
<!-- 批次与实物码:每套实物一码 -->
<n-grid-item>
<n-card :title="t('pages.artwork.traceCodes')" :bordered="false">
<template #header-extra>
<n-space>
<n-button v-if="auth.canWrite" size="small" type="primary" @click="genModal = true">
<template #icon><n-icon :component="AddOutline" /></template>
{{ t('pages.artwork.genCodes') }}
</n-button>
<n-button size="small" @click="goCodes">{{ t('pages.artwork.viewCodes') }}</n-button>
</n-space>
</template>
<n-descriptions :column="4" label-placement="top" bordered size="small">
<n-descriptions-item :label="t('pages.artwork.archiveNo')">{{ artwork?.archiveNo || '-' }}</n-descriptions-item>
<n-descriptions-item :label="t('pages.artwork.codeCount')">{{ artwork?.codeStats?.total ?? 0 }}</n-descriptions-item>
<n-descriptions-item :label="t('pages.artwork.activeCount')">{{ artwork?.codeStats?.active ?? 0 }}</n-descriptions-item>
<n-descriptions-item :label="t('pages.artwork.queryTotal')">{{ artwork?.codeStats?.queryTotal ?? 0 }}</n-descriptions-item>
</n-descriptions>
<div class="batch-title">{{ t('pages.artwork.batches') }}</div>
<n-empty v-if="!artwork?.batches?.length" :description="t('common.msg.noData')" size="small" />
<n-data-table
v-else
size="small"
:columns="batchColumns"
:data="artwork.batches"
:row-key="(r) => r.id"
/>
<div class="trace-panel-wrap">
<trace-code-panel :artwork-id="artworkId" embedded />
</div>
</n-card>
</n-grid-item>
</template>
</n-grid>
<!-- 生码弹窗 -->
<n-modal v-model:show="genModal" preset="card" :title="t('pages.artwork.genCodes')" style="width:420px">
<n-form :model="genForm" label-placement="top">
<n-form-item :label="t('pages.traceCode.quantity')">
<n-input-number v-model:value="genForm.quantity" :min="1" :max="10000" style="width:100%" />
</n-form-item>
<n-form-item :label="t('pages.traceCode.batchNo')">
<n-input v-model:value="genForm.batchNo" placeholder="(auto)" />
</n-form-item>
</n-form>
<template #footer>
<div style="text-align:right">
<n-button class="mr8" @click="genModal = false">{{ t('common.action.cancel') }}</n-button>
<n-button type="primary" :loading="generating" @click="genCodes">{{ t('common.action.generate') }}</n-button>
</div>
</template>
</n-modal>
<!-- 节点弹窗 -->
<n-modal v-model:show="nodeModal" preset="card" :title="t('pages.artwork.addNode')" style="width:560px;max-width:94vw">
<n-form :model="nodeForm" label-placement="top">
@@ -297,15 +264,16 @@
import { computed, h, onMounted, reactive, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { NTag, type DataTableColumns, type FormInst, type FormRules } from 'naive-ui';
import { NTag, type FormInst, type FormRules } from 'naive-ui';
import { ArrowBackOutline, AddOutline } from '@vicons/ionicons5';
import { ArtworkStatus, CertType, NodeType } from '@artveris/shared';
import { artworkApi, templateApi, traceCodeApi, jobApi } from '@/api';
import { artworkApi, templateApi } from '@/api';
import { useAuthStore } from '@/stores/auth';
import MediaUpload from '@/components/MediaUpload.vue';
import MediaSorter from '@/components/MediaSorter.vue';
import TraceCodePanel from '@/components/TraceCodePanel.vue';
import { message, dialog } from '@/utils/feedback';
import { fmt, fmtDate, statusType } from '@/utils/format';
import { fmtDate } from '@/utils/format';
const { t } = useI18n();
const route = useRoute();
@@ -508,49 +476,6 @@ function removeCert(c: any) {
});
}
/* 追溯码(一款多码):生码 + 批次 */
const batchColumns: DataTableColumns<any> = [
{ title: () => t('pages.traceCode.batchNo'), key: 'batchNo' },
{ title: () => t('pages.traceCode.quantity'), key: 'quantity', width: 90 },
{ title: () => t('pages.traceCode.generatedCount'), key: 'generatedCount', width: 90 },
{
title: () => t('common.label.status'),
key: 'status',
width: 100,
render: (r) => h(NTag, { size: 'small', type: statusType(r.status) }, { default: () => t(`common.status.${r.status}`) }),
},
{ title: () => t('common.label.createdAt'), key: 'createdAt', width: 160, render: (r) => fmt(r.createdAt) },
];
const genModal = ref(false);
const generating = ref(false);
const genForm = reactive<{ quantity: number; batchNo: string }>({ quantity: 100, batchNo: '' });
async function genCodes() {
generating.value = true;
try {
const res: any = await traceCodeApi.generate({
artworkId: artworkId.value,
quantity: genForm.quantity,
batchNo: genForm.batchNo || undefined,
});
message.success(t('pages.traceCode.genSuccess'));
for (let i = 0; i < 30; i++) {
await new Promise((r) => setTimeout(r, 700));
const job: any = await jobApi.get(res.jobId);
if (['SUCCESS', 'FAILED', 'PARTIAL'].includes(job.status)) break;
}
genModal.value = false;
genForm.batchNo = '';
await loadArtwork();
} finally {
generating.value = false;
}
}
function goCodes() {
router.push({ name: 'traceCodes', query: { artworkId: String(artworkId.value) } });
}
onMounted(async () => {
await loadTemplates();
if (!isNew.value) await loadArtwork();
@@ -565,10 +490,8 @@ onMounted(async () => {
.mr8 {
margin-right: 8px;
}
.batch-title {
font-size: 13px;
color: #6b7280;
margin: 14px 0 8px;
.trace-panel-wrap {
margin-top: 14px;
}
.node-head {
display: flex;