refactor: 按甲方确认重构为一款多码(档案编号标识款、批次码、按款统计)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -185,52 +185,56 @@
|
||||
</n-card>
|
||||
</n-grid-item>
|
||||
|
||||
<!-- 追溯码与区块链 -->
|
||||
<!-- 追溯码(一款多码) -->
|
||||
<n-grid-item>
|
||||
<n-card :title="t('pages.artwork.traceCode') + ' / ' + t('pages.blockchain.title')" :bordered="false">
|
||||
<div v-if="artwork?.traceCode">
|
||||
<n-descriptions :column="3" label-placement="left" bordered size="small">
|
||||
<n-descriptions-item :label="t('pages.traceCode.shortCode')">{{ artwork.traceCode.shortCode }}</n-descriptions-item>
|
||||
<n-descriptions-item :label="t('common.label.status')">
|
||||
<n-tag size="small" :type="statusType(artwork.traceCode.status)">{{ t(`common.status.${artwork.traceCode.status}`) }}</n-tag>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item :label="t('pages.traceCode.queryCount')">{{ artwork.traceCode.queryCount }}</n-descriptions-item>
|
||||
</n-descriptions>
|
||||
<div style="margin-top:12px; display:flex; gap:8px; flex-wrap:wrap">
|
||||
<n-button v-if="auth.canWrite" size="small" @click="unbind">{{ t('common.action.unbind') }}</n-button>
|
||||
<n-button v-if="auth.canWrite" size="small" type="primary" :loading="onchainLoading" @click="onchain">
|
||||
<template #icon><n-icon :component="LinkOutline" /></template>
|
||||
{{ t('common.action.onchain') }}
|
||||
<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>
|
||||
</div>
|
||||
<n-data-table
|
||||
v-if="artwork.traceCode.proofs?.length"
|
||||
style="margin-top:12px"
|
||||
size="small"
|
||||
:columns="proofColumns"
|
||||
:data="artwork.traceCode.proofs"
|
||||
:row-key="(r) => r.id"
|
||||
/>
|
||||
</div>
|
||||
<div v-else>
|
||||
<n-empty :description="t('pages.artwork.noTrace')" />
|
||||
<div v-if="auth.canWrite" style="margin-top:12px; display:flex; gap:8px; align-items:center">
|
||||
<n-select
|
||||
v-model:value="bindCodeId"
|
||||
:options="unboundOptions"
|
||||
filterable
|
||||
:placeholder="t('pages.traceCode.shortCode')"
|
||||
style="width: 240px"
|
||||
@focus="loadUnbound"
|
||||
/>
|
||||
<n-button type="primary" :disabled="!bindCodeId" @click="bind">{{ t('pages.artwork.bindCode') }}</n-button>
|
||||
</div>
|
||||
</div>
|
||||
<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"
|
||||
/>
|
||||
</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,9 +301,9 @@ 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 { ArrowBackOutline, AddOutline, LinkOutline } from '@vicons/ionicons5';
|
||||
import { ArrowBackOutline, AddOutline } from '@vicons/ionicons5';
|
||||
import { ArtworkStatus, CertType, NodeType } from '@artveris/shared';
|
||||
import { artworkApi, templateApi, traceCodeApi } from '@/api';
|
||||
import { artworkApi, templateApi, traceCodeApi, jobApi } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import MediaUpload from '@/components/MediaUpload.vue';
|
||||
import MediaSorter from '@/components/MediaSorter.vue';
|
||||
@@ -334,18 +338,6 @@ const artwork = ref<any>(null);
|
||||
const nodes = ref<any[]>([]);
|
||||
const certs = ref<any[]>([]);
|
||||
|
||||
const proofColumns: DataTableColumns<any> = [
|
||||
{ title: () => t('pages.blockchain.txHash'), key: 'txHash', ellipsis: { tooltip: true }, render: (r) => r.txHash || '-' },
|
||||
{ title: () => t('pages.blockchain.blockHeight'), key: 'blockHeight', width: 120, render: (r) => r.blockHeight || '-' },
|
||||
{
|
||||
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('pages.blockchain.onchainAt'), key: 'onchainAt', width: 160, render: (r) => fmt(r.onchainAt) },
|
||||
];
|
||||
|
||||
function onTemplateChange() {
|
||||
form.dynamicFields = {};
|
||||
}
|
||||
@@ -515,39 +507,48 @@ function removeCert(c: any) {
|
||||
});
|
||||
}
|
||||
|
||||
/* 追溯码 / 区块链 */
|
||||
const bindCodeId = ref<string | null>(null);
|
||||
const unbound = ref<any[]>([]);
|
||||
const unboundOptions = computed(() => unbound.value.map((c) => ({ label: c.shortCode, value: c.id })));
|
||||
const onchainLoading = ref(false);
|
||||
async function loadUnbound() {
|
||||
const res: any = await traceCodeApi.list({ status: 'UNBOUND', pageSize: 50 });
|
||||
unbound.value = res.list;
|
||||
}
|
||||
async function bind() {
|
||||
if (!bindCodeId.value) return;
|
||||
await traceCodeApi.bind(bindCodeId.value, artworkId.value);
|
||||
message.success(t('common.msg.saved'));
|
||||
bindCodeId.value = null;
|
||||
await loadArtwork();
|
||||
}
|
||||
async function unbind() {
|
||||
if (!artwork.value?.traceCode) return;
|
||||
await traceCodeApi.unbind(String(artwork.value.traceCode.id));
|
||||
message.success(t('common.msg.saved'));
|
||||
await loadArtwork();
|
||||
}
|
||||
async function onchain() {
|
||||
if (!artwork.value?.traceCode) return;
|
||||
onchainLoading.value = true;
|
||||
/* 追溯码(一款多码):生码 + 批次 */
|
||||
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 {
|
||||
await traceCodeApi.onchain(String(artwork.value.traceCode.id));
|
||||
message.success(t('pages.blockchain.triggered'));
|
||||
setTimeout(loadArtwork, 1500);
|
||||
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 {
|
||||
onchainLoading.value = false;
|
||||
generating.value = false;
|
||||
}
|
||||
}
|
||||
function goCodes() {
|
||||
router.push({ name: 'traceCodes', query: { artworkId: String(artworkId.value) } });
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadTemplates();
|
||||
@@ -563,6 +564,11 @@ onMounted(async () => {
|
||||
.mr8 {
|
||||
margin-right: 8px;
|
||||
}
|
||||
.batch-title {
|
||||
font-size: 13px;
|
||||
color: #6b7280;
|
||||
margin: 14px 0 8px;
|
||||
}
|
||||
.node-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
Reference in New Issue
Block a user