refactor: 合并档案与实物码管理入口
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
## 项目概况
|
## 项目概况
|
||||||
|
|
||||||
- 整理“艺术品可信溯源与认证系统”的产品需求与开发方案。
|
- 整理“艺术品可信溯源与认证系统”的产品需求与开发方案。
|
||||||
- 系统当前代码模型为“一款多码、首次激活、多次查询”:`Artwork` 表示一款/一个艺术品档案,拥有款级唯一档案编号 `archiveNo`;每款可按批次生成多套 `TraceCode`,每套码独立激活、计数和上链。
|
- 系统当前代码模型为“款式档案 + 每套实物一码、首次激活、多次查询”:`Artwork` 表示一款/一个艺术品档案,拥有款级唯一档案编号 `archiveNo`;每款可按批次生成多套 `TraceCode`,每套 `TraceCode` 对应一套实物,独立激活、计数和上链,仍满足甲方“一物一码”口径。
|
||||||
|
|
||||||
## 已完成内容
|
## 已完成内容
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
- 后台建档 → 自动生成款级档案编号 `ARTVERIS-000001` 形式 → 选择作品生成批次码(随机短码 + 短链)→ 导出 → 按短码录入/导入出库与上链信息。
|
- 后台建档 → 自动生成款级档案编号 `ARTVERIS-000001` 形式 → 选择作品生成批次码(随机短码 + 短链)→ 导出 → 按短码录入/导入出库与上链信息。
|
||||||
- 用户打开短链 → 后端按短码定位到具体 `TraceCode` 及其所属 `Artwork` → 校验码状态与作品审核状态 → 未激活则激活并计数=1、记录首次激活时间,已激活则计数+1 → 展示详情/时间轴/水印证书/链上凭证/档案编号 → 写入查询日志。
|
- 用户打开短链 → 后端按短码定位到具体 `TraceCode` 及其所属 `Artwork` → 校验码状态与作品审核状态 → 未激活则激活并计数=1、记录首次激活时间,已激活则计数+1 → 展示详情/时间轴/水印证书/链上凭证/档案编号 → 写入查询日志。
|
||||||
- 当前数据模型:`Artwork 1:N Batch`、`Artwork 1:N TraceCode`、`Batch 1:N TraceCode`;生码时必须指定作品,已移除旧的绑定/解绑流程、`UNBOUND` 状态、电商 `sku` 字段和码级 `archiveNo`。
|
- 当前数据模型:`Artwork 1:N Batch`、`Artwork 1:N TraceCode`、`Batch 1:N TraceCode`;生码时必须指定作品档案/款式,每条 `TraceCode` 才是实物的一物一码载体。已移除旧的绑定/解绑流程、`UNBOUND` 状态、电商 `sku` 字段和码级 `archiveNo`。
|
||||||
|
|
||||||
## 待确认事项(天河链,开发先预留)
|
## 待确认事项(天河链,开发先预留)
|
||||||
|
|
||||||
@@ -89,12 +89,13 @@
|
|||||||
- 客户端工程重命名(2026-07-03):按用户要求全面移除工程命名中的 h5,不保留兼容命令。`apps/h5` 已重命名为 `apps/client`,包名改为 `@artveris/client`,根命令改为 `pnpm dev:client`,脚本启动第三端改为 `pnpm dev:client`;配置从 `h5_port` / `H5_ORIGIN` / `h5Origin` 改为 `client_port` / `CLIENT_ORIGIN` / `clientOrigin`;Dockerfile、full compose、Nginx 静态挂载与文档均同步到 client。full compose 项目名显式为 `artveris-full`,避免 Docker Desktop 继续显示默认 `docker` 组。保留用户可见的“C 端/客户端”业务称呼。
|
- 客户端工程重命名(2026-07-03):按用户要求全面移除工程命名中的 h5,不保留兼容命令。`apps/h5` 已重命名为 `apps/client`,包名改为 `@artveris/client`,根命令改为 `pnpm dev:client`,脚本启动第三端改为 `pnpm dev:client`;配置从 `h5_port` / `H5_ORIGIN` / `h5Origin` 改为 `client_port` / `CLIENT_ORIGIN` / `clientOrigin`;Dockerfile、full compose、Nginx 静态挂载与文档均同步到 client。full compose 项目名显式为 `artveris-full`,避免 Docker Desktop 继续显示默认 `docker` 组。保留用户可见的“C 端/客户端”业务称呼。
|
||||||
- 查询日志瘦身(2026-07-03):对照甲方原版 PRD,后台只要求查看产品查询次数和日志,未要求地区解析;按用户确认移除地区字段与 Geo 链路。`QueryLog.region` 从 Prisma schema 移除并新增迁移 `20260703000100_drop_query_log_region`,`PublicTraceService` 写日志只记录访问 IP(由 `extractIp` 从代理头取公网 IP)与 UA 解析结果;删除 `GeoModule/GeoService`、`GEO_DRIVER` 配置和后台“IP / 地区”拼接展示,后台查询日志 IP 列仅展示访问 IP。
|
- 查询日志瘦身(2026-07-03):对照甲方原版 PRD,后台只要求查看产品查询次数和日志,未要求地区解析;按用户确认移除地区字段与 Geo 链路。`QueryLog.region` 从 Prisma schema 移除并新增迁移 `20260703000100_drop_query_log_region`,`PublicTraceService` 写日志只记录访问 IP(由 `extractIp` 从代理头取公网 IP)与 UA 解析结果;删除 `GeoModule/GeoService`、`GEO_DRIVER` 配置和后台“IP / 地区”拼接展示,后台查询日志 IP 列仅展示访问 IP。
|
||||||
- TypeScript 后端配置修复(2026-07-03):`apps/api/tsconfig.json` 在已有 `outDir: ./dist` 的基础上显式补充 `rootDir: ./src`,消除 VS Code / TypeScript 7 关于 `outDir` 应配套 `rootDir` 的诊断提示;API 编译输入仍只包含 `src`,Prisma seed 与测试文件继续排除。
|
- TypeScript 后端配置修复(2026-07-03):`apps/api/tsconfig.json` 在已有 `outDir: ./dist` 的基础上显式补充 `rootDir: ./src`,消除 VS Code / TypeScript 7 关于 `outDir` 应配套 `rootDir` 的诊断提示;API 编译输入仍只包含 `src`,Prisma seed 与测试文件继续排除。
|
||||||
|
- 后台信息架构合并(2026-07-03):根据甲方微信口径重新校准“一款多码”的含义:一款是款式/档案层,可分批生产多套;每套实物仍独立编码,符合一物一码。后台取消侧边栏平级“追溯码管理”入口,将追溯码主流程内聚到“艺术品档案”详情的“批次与实物码”区域;新增复用组件 `TraceCodePanel`,在档案详情固定当前 `artworkId` 管理生码、筛选、分组、导出、批量启停和二维码预览;隐藏路由 `/trace-codes` 仍保留为全局明细页。后端 `GET /batches` 支持 `artworkId` 过滤,避免详情页混入其他档案批次。整理版 PRD 与技术方案已同步说明 `Artwork -> Batch -> TraceCode`,其中 `TraceCode` 是实物层一物一码载体。
|
||||||
|
|
||||||
## 当前代码基准与注意事项
|
## 当前代码基准与注意事项
|
||||||
|
|
||||||
- 代码优先级:后续开发以 `apps/api/prisma/schema.prisma`、后端服务实现、admin/client 当前页面为准;PRD 与技术方案中仍可能有旧“一物一码/绑定防伪码/SKU”表述,仅作需求背景参考。
|
- 代码优先级:后续开发以 `apps/api/prisma/schema.prisma`、后端服务实现、admin/client 当前页面为准;PRD 与技术方案中仍可能有旧“一物一码/绑定防伪码/SKU”表述,仅作需求背景参考。
|
||||||
- 当前核心模型:一款作品 `Artwork` 多个批次 `Batch`,每批次多个追溯码 `TraceCode`;`archiveNo` 是款级唯一档案编号,查询统计按款聚合。
|
- 当前核心模型:一款/一个档案 `Artwork` 多个批次 `Batch`,每批次多个实物追溯码 `TraceCode`;`archiveNo` 是款级唯一档案编号,`TraceCode` 是每套实物的一物一码载体,查询统计按档案聚合。
|
||||||
- 生码入口:后台追溯码管理和作品详情均可生码,但都必须指定作品;不存在“未绑定码池 → 绑定作品”的旧流程。
|
- 生码入口:主入口在艺术品档案详情的“批次与实物码”;隐藏全局明细页也可生码但必须指定作品档案/款式。不存在“未绑定码池 → 绑定作品”的旧流程。
|
||||||
- 出库导入:以短码定位具体一套码,导入列不再包含 SKU 或手填档案编号;档案编号由作品自动生成并在日志/导出/C 端展示。
|
- 出库导入:以短码定位具体一套码,导入列不再包含 SKU 或手填档案编号;档案编号由作品自动生成并在日志/导出/C 端展示。
|
||||||
- 客户端:当前 `Trace.vue` 依赖 `openMediaViewer.ts` + PhotoSwipe,不再使用旧 `MediaViewer.vue`;顶部语言菜单和追溯码复制是用户当前未提交改动的一部分,后续若继续修改客户端,需保护这些改动。
|
- 客户端:当前 `Trace.vue` 依赖 `openMediaViewer.ts` + PhotoSwipe,不再使用旧 `MediaViewer.vue`;顶部语言菜单和追溯码复制是用户当前未提交改动的一部分,后续若继续修改客户端,需保护这些改动。
|
||||||
- 文案残留:`apps/client/src/locales/*` 仍保留 `privacy.note`,但当前页面不显示底部隐私说明;若按合规要求恢复,需要在 `Trace.vue` 重新渲染对应文案。
|
- 文案残留:`apps/client/src/locales/*` 仍保留 `privacy.note`,但当前页面不显示底部隐私说明;若按合规要求恢复,需要在 `Trace.vue` 重新渲染对应文案。
|
||||||
|
|||||||
@@ -0,0 +1,522 @@
|
|||||||
|
<template>
|
||||||
|
<div :class="['trace-code-panel', { embedded }]">
|
||||||
|
<div class="panel-toolbar">
|
||||||
|
<n-select
|
||||||
|
v-model:value="query.groupId"
|
||||||
|
:options="groupFilterOptions"
|
||||||
|
clearable
|
||||||
|
:placeholder="t('pages.traceCode.allGroups')"
|
||||||
|
class="toolbar-control"
|
||||||
|
@update:value="onSearch"
|
||||||
|
/>
|
||||||
|
<n-select
|
||||||
|
v-model:value="query.batchId"
|
||||||
|
:options="batchOptions"
|
||||||
|
clearable
|
||||||
|
:placeholder="t('pages.traceCode.batchNo')"
|
||||||
|
class="toolbar-control wide"
|
||||||
|
@update:value="onSearch"
|
||||||
|
/>
|
||||||
|
<n-select
|
||||||
|
v-model:value="query.status"
|
||||||
|
:options="statusOptions"
|
||||||
|
clearable
|
||||||
|
:placeholder="t('common.label.status')"
|
||||||
|
class="toolbar-control narrow"
|
||||||
|
@update:value="onSearch"
|
||||||
|
/>
|
||||||
|
<n-input
|
||||||
|
v-model:value="query.keyword"
|
||||||
|
:placeholder="t('pages.traceCode.shortCode')"
|
||||||
|
clearable
|
||||||
|
class="toolbar-control"
|
||||||
|
@keyup.enter="onSearch"
|
||||||
|
/>
|
||||||
|
<n-button type="primary" @click="onSearch">
|
||||||
|
<template #icon><n-icon :component="SearchOutline" /></template>
|
||||||
|
{{ t('common.action.search') }}
|
||||||
|
</n-button>
|
||||||
|
<div class="spacer" />
|
||||||
|
<n-button v-if="auth.canWrite" @click="groupModal = true">
|
||||||
|
<template #icon><n-icon :component="FolderOutline" /></template>
|
||||||
|
{{ t('pages.traceCode.manageGroups') }}
|
||||||
|
</n-button>
|
||||||
|
<n-dropdown v-if="auth.canWrite" trigger="click" :options="exportOptions" @select="onExport">
|
||||||
|
<n-button>
|
||||||
|
<template #icon><n-icon :component="DownloadOutline" /></template>
|
||||||
|
{{ t('common.action.export') }}
|
||||||
|
</n-button>
|
||||||
|
</n-dropdown>
|
||||||
|
<n-button v-if="auth.canWrite" type="primary" @click="openGenerate">
|
||||||
|
<template #icon><n-icon :component="AddOutline" /></template>
|
||||||
|
{{ t('pages.traceCode.generate') }}
|
||||||
|
</n-button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<n-card v-if="auth.canWrite && checkedKeys.length" size="small" class="batch-bar" :bordered="false">
|
||||||
|
<n-space align="center">
|
||||||
|
<span>{{ t('pages.traceCode.selected', { n: checkedKeys.length }) }}</span>
|
||||||
|
<n-dropdown trigger="click" :options="groupAssignOptions" @select="batchAssignGroup">
|
||||||
|
<n-button size="small">
|
||||||
|
<template #icon><n-icon :component="FolderOutline" /></template>
|
||||||
|
{{ t('pages.traceCode.batchGroup') }}
|
||||||
|
</n-button>
|
||||||
|
</n-dropdown>
|
||||||
|
<n-button size="small" @click="batchStatus(false)">{{ t('pages.traceCode.batchEnable') }}</n-button>
|
||||||
|
<n-button size="small" type="warning" @click="batchStatus(true)">{{ t('pages.traceCode.batchDisable') }}</n-button>
|
||||||
|
</n-space>
|
||||||
|
</n-card>
|
||||||
|
|
||||||
|
<n-data-table
|
||||||
|
:columns="columns"
|
||||||
|
:data="rows"
|
||||||
|
:loading="loading"
|
||||||
|
:pagination="pagination"
|
||||||
|
remote
|
||||||
|
:row-key="(r) => r.id"
|
||||||
|
v-model:checked-row-keys="checkedKeys"
|
||||||
|
@update:page="onPage"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<n-modal v-model:show="genModal" preset="card" :title="t('pages.traceCode.generate')" style="width: 440px">
|
||||||
|
<n-form :model="genForm" label-placement="top">
|
||||||
|
<n-form-item v-if="!fixedArtworkId" :label="t('pages.artwork.selectArtwork')" required>
|
||||||
|
<n-select
|
||||||
|
v-model:value="genForm.artworkId"
|
||||||
|
filterable
|
||||||
|
remote
|
||||||
|
clearable
|
||||||
|
:loading="artworkSearching"
|
||||||
|
:options="artworkOptions"
|
||||||
|
:placeholder="t('pages.artwork.selectArtworkTip')"
|
||||||
|
@search="searchArtworks"
|
||||||
|
/>
|
||||||
|
</n-form-item>
|
||||||
|
<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.group')">
|
||||||
|
<n-select v-model:value="genForm.groupId" :options="groupPlainOptions" clearable :placeholder="t('pages.traceCode.noGroup')" />
|
||||||
|
</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>
|
||||||
|
<n-text v-if="generating" depth="3">{{ t('pages.traceCode.generating') }}</n-text>
|
||||||
|
<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="generate">{{ t('common.action.generate') }}</n-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</n-modal>
|
||||||
|
|
||||||
|
<n-modal v-model:show="qrModal" preset="card" :title="t('pages.traceCode.qrPreview')" style="width: 360px">
|
||||||
|
<div style="text-align: center">
|
||||||
|
<img :src="qrSrc" alt="qrcode" style="width: 280px; height: 280px" />
|
||||||
|
<div style="margin-top: 8px; opacity: 0.6; word-break: break-all">{{ qrUrl }}</div>
|
||||||
|
</div>
|
||||||
|
</n-modal>
|
||||||
|
|
||||||
|
<n-modal v-model:show="groupModal" preset="card" :title="t('pages.traceCode.manageGroups')" style="width: 520px">
|
||||||
|
<div class="panel-toolbar group-toolbar">
|
||||||
|
<n-input v-model:value="groupForm.name" :placeholder="t('pages.traceCode.groupName')" style="width: 200px" />
|
||||||
|
<n-button type="primary" :disabled="!groupForm.name" @click="saveGroup">
|
||||||
|
{{ editingGroup ? t('common.action.save') : t('pages.traceCode.createGroup') }}
|
||||||
|
</n-button>
|
||||||
|
<n-button v-if="editingGroup" @click="resetGroupForm">{{ t('common.action.cancel') }}</n-button>
|
||||||
|
</div>
|
||||||
|
<n-list bordered>
|
||||||
|
<n-list-item v-for="g in groups" :key="g.id">
|
||||||
|
<div class="group-row">
|
||||||
|
<span>{{ g.name }}<n-text depth="3">({{ g._count?.traceCodes ?? 0 }})</n-text></span>
|
||||||
|
<span>
|
||||||
|
<n-button text type="primary" size="small" @click="editGroup(g)">{{ t('common.action.edit') }}</n-button>
|
||||||
|
<n-button text type="error" size="small" style="margin-left: 10px" @click="removeGroup(g)">{{ t('common.action.delete') }}</n-button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</n-list-item>
|
||||||
|
</n-list>
|
||||||
|
</n-modal>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, h, onMounted, reactive, ref, watch } from 'vue';
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { NButton, NIcon, NTag, NText, type DataTableColumns } from 'naive-ui';
|
||||||
|
import { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline, FolderOutline, OpenOutline } from '@vicons/ionicons5';
|
||||||
|
import { TraceCodeStatus } from '@artveris/shared';
|
||||||
|
import { traceCodeApi, jobApi, artworkApi } from '@/api';
|
||||||
|
import { useAuthStore } from '@/stores/auth';
|
||||||
|
import { message, dialog } from '@/utils/feedback';
|
||||||
|
import { fmt, statusType } from '@/utils/format';
|
||||||
|
import { downloadFile } from '@/utils/download';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
artworkId?: number;
|
||||||
|
embedded?: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const { t } = useI18n();
|
||||||
|
const route = useRoute();
|
||||||
|
const auth = useAuthStore();
|
||||||
|
|
||||||
|
const fixedArtworkId = computed(() => props.artworkId || null);
|
||||||
|
const embedded = computed(() => props.embedded === true);
|
||||||
|
|
||||||
|
const rows = ref<any[]>([]);
|
||||||
|
const loading = ref(false);
|
||||||
|
const checkedKeys = ref<Array<string | number>>([]);
|
||||||
|
const query = reactive<{
|
||||||
|
artworkId: number | null;
|
||||||
|
groupId: number | null;
|
||||||
|
batchId: number | null;
|
||||||
|
status: string | null;
|
||||||
|
keyword: string;
|
||||||
|
page: number;
|
||||||
|
pageSize: number;
|
||||||
|
}>({
|
||||||
|
artworkId: fixedArtworkId.value,
|
||||||
|
groupId: null,
|
||||||
|
batchId: null,
|
||||||
|
status: null,
|
||||||
|
keyword: '',
|
||||||
|
page: 1,
|
||||||
|
pageSize: embedded.value ? 8 : 10,
|
||||||
|
});
|
||||||
|
const pagination = reactive({ page: 1, pageSize: query.pageSize, itemCount: 0 });
|
||||||
|
const statusOptions = Object.values(TraceCodeStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
|
||||||
|
|
||||||
|
const batchOptions = ref<{ label: string; value: number }[]>([]);
|
||||||
|
const groups = ref<any[]>([]);
|
||||||
|
const groupFilterOptions = computed(() => groups.value.map((g) => ({ label: g.name, value: g.id })));
|
||||||
|
const groupPlainOptions = computed(() => groups.value.map((g) => ({ label: g.name, value: g.id })));
|
||||||
|
const groupAssignOptions = computed(() => [
|
||||||
|
{ label: t('pages.traceCode.noGroup'), key: '__none__' },
|
||||||
|
...groups.value.map((g) => ({ label: g.name, key: String(g.id) })),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const genModal = ref(false);
|
||||||
|
const generating = ref(false);
|
||||||
|
const genForm = reactive<{ artworkId: number | null; quantity: number; batchNo: string; groupId: number | null }>({
|
||||||
|
artworkId: fixedArtworkId.value,
|
||||||
|
quantity: 100,
|
||||||
|
batchNo: '',
|
||||||
|
groupId: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const artworkSearching = ref(false);
|
||||||
|
const artworkOptions = ref<{ label: string; value: number }[]>([]);
|
||||||
|
let artworkTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
|
const qrModal = ref(false);
|
||||||
|
const qrSrc = ref('');
|
||||||
|
const qrUrl = ref('');
|
||||||
|
|
||||||
|
const groupModal = ref(false);
|
||||||
|
const groupForm = reactive<{ name: string }>({ name: '' });
|
||||||
|
const editingGroup = ref<number | null>(null);
|
||||||
|
|
||||||
|
const columns = computed<DataTableColumns<any>>(() => {
|
||||||
|
const base: DataTableColumns<any> = [
|
||||||
|
{ type: 'selection' },
|
||||||
|
{ title: () => t('pages.traceCode.batchNo'), key: 'batch', width: 150, render: (r) => r.batch?.batchNo || '-' },
|
||||||
|
{ title: () => t('pages.traceCode.shortCode'), key: 'shortCode', width: 120 },
|
||||||
|
{
|
||||||
|
title: () => t('pages.traceCode.url'),
|
||||||
|
key: 'url',
|
||||||
|
ellipsis: { tooltip: true },
|
||||||
|
render: (r) =>
|
||||||
|
h(
|
||||||
|
'a',
|
||||||
|
{ href: r.url, target: '_blank', rel: 'noopener', style: 'color: var(--brand); text-decoration: none' },
|
||||||
|
[r.url, h(NIcon, { component: OpenOutline, style: 'vertical-align:-2px;margin-left:4px' })],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ title: () => t('pages.traceCode.group'), key: 'group', width: 110, render: (r) => r.group?.name || h(NText, { depth: 3 }, { default: () => t('pages.traceCode.noGroup') }) },
|
||||||
|
{
|
||||||
|
title: () => t('common.label.status'),
|
||||||
|
key: 'status',
|
||||||
|
width: 96,
|
||||||
|
render: (r) => h(NTag, { size: 'small', type: statusType(r.status) }, { default: () => t(`common.status.${r.status}`) }),
|
||||||
|
},
|
||||||
|
{ title: () => t('pages.traceCode.queryCount'), key: 'queryCount', width: 84 },
|
||||||
|
{ title: () => t('pages.traceCode.firstActivatedAt'), key: 'firstActivatedAt', width: 150, render: (r) => fmt(r.firstActivatedAt) },
|
||||||
|
{
|
||||||
|
title: () => t('common.label.operation'),
|
||||||
|
key: 'ops',
|
||||||
|
width: 70,
|
||||||
|
render: (r) =>
|
||||||
|
h(NButton, { quaternary: true, circle: true, size: 'small', onClick: () => showQr(r) }, { icon: () => h(NIcon, null, { default: () => h(QrCodeOutline) }) }),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!fixedArtworkId.value) {
|
||||||
|
base.splice(
|
||||||
|
4,
|
||||||
|
0,
|
||||||
|
{ title: () => t('pages.artwork.archiveNo'), key: 'archiveNo', width: 130, render: (r) => r.artwork?.archiveNo || '-' },
|
||||||
|
{ title: () => t('pages.artwork.title'), key: 'artwork', width: 130, render: (r) => r.artwork?.title || '-' },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return base;
|
||||||
|
});
|
||||||
|
|
||||||
|
function currentArtworkId() {
|
||||||
|
return fixedArtworkId.value || query.artworkId || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadBatches() {
|
||||||
|
const params: Record<string, unknown> = { pageSize: 100 };
|
||||||
|
const aid = currentArtworkId();
|
||||||
|
if (aid) params.artworkId = aid;
|
||||||
|
const res: any = await traceCodeApi.batches(params);
|
||||||
|
batchOptions.value = res.list.map((b: any) => ({ label: `${b.batchNo} (${b.generatedCount}/${b.quantity})`, value: b.id }));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadGroups() {
|
||||||
|
groups.value = await traceCodeApi.groups();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
loading.value = true;
|
||||||
|
checkedKeys.value = [];
|
||||||
|
try {
|
||||||
|
const res: any = await traceCodeApi.list({
|
||||||
|
artworkId: currentArtworkId() || undefined,
|
||||||
|
groupId: query.groupId || undefined,
|
||||||
|
batchId: query.batchId || undefined,
|
||||||
|
status: query.status || undefined,
|
||||||
|
keyword: query.keyword || undefined,
|
||||||
|
page: query.page,
|
||||||
|
pageSize: query.pageSize,
|
||||||
|
});
|
||||||
|
rows.value = res.list;
|
||||||
|
pagination.itemCount = res.total;
|
||||||
|
pagination.page = res.page;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSearch() {
|
||||||
|
query.page = 1;
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPage(p: number) {
|
||||||
|
query.page = p;
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
function openGenerate() {
|
||||||
|
genForm.artworkId = fixedArtworkId.value || query.artworkId;
|
||||||
|
genModal.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function searchArtworks(keyword: string) {
|
||||||
|
if (artworkTimer) clearTimeout(artworkTimer);
|
||||||
|
artworkTimer = setTimeout(async () => {
|
||||||
|
artworkSearching.value = true;
|
||||||
|
try {
|
||||||
|
const res: any = await artworkApi.list({ keyword: keyword || undefined, pageSize: 20 });
|
||||||
|
artworkOptions.value = res.list.map((a: any) => ({
|
||||||
|
label: `${a.archiveNo || '-'} - ${a.title}`,
|
||||||
|
value: a.id,
|
||||||
|
}));
|
||||||
|
} finally {
|
||||||
|
artworkSearching.value = false;
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function generate() {
|
||||||
|
const targetArtworkId = fixedArtworkId.value || genForm.artworkId;
|
||||||
|
if (!targetArtworkId) {
|
||||||
|
message.error(t('pages.artwork.selectArtworkTip'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
generating.value = true;
|
||||||
|
try {
|
||||||
|
const res: any = await traceCodeApi.generate({
|
||||||
|
artworkId: targetArtworkId,
|
||||||
|
quantity: genForm.quantity,
|
||||||
|
batchNo: genForm.batchNo || undefined,
|
||||||
|
groupId: genForm.groupId || 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 loadBatches();
|
||||||
|
await load();
|
||||||
|
} finally {
|
||||||
|
generating.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showQr(r: any) {
|
||||||
|
qrSrc.value = traceCodeApi.qrUrl(r.id);
|
||||||
|
qrUrl.value = r.url;
|
||||||
|
qrModal.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const exportOptions = computed(() => {
|
||||||
|
const cur = t('pages.traceCode.exportCurrent');
|
||||||
|
const opts: Array<{ label: string; key: string }> = [
|
||||||
|
{ label: `Excel - ${cur}`, key: 'filter:xlsx' },
|
||||||
|
{ label: `CSV - ${cur}`, key: 'filter:csv' },
|
||||||
|
];
|
||||||
|
if (checkedKeys.value.length) {
|
||||||
|
const sel = t('pages.traceCode.selected', { n: checkedKeys.value.length });
|
||||||
|
opts.push({ label: `Excel - ${sel}`, key: 'selected:xlsx' });
|
||||||
|
opts.push({ label: `CSV - ${sel}`, key: 'selected:csv' });
|
||||||
|
}
|
||||||
|
return opts;
|
||||||
|
});
|
||||||
|
|
||||||
|
async function onExport(key: string) {
|
||||||
|
const [scope, format] = key.split(':');
|
||||||
|
const params: Record<string, unknown> = { format };
|
||||||
|
if (scope === 'selected') {
|
||||||
|
params.ids = checkedKeys.value.map(String).join(',');
|
||||||
|
} else {
|
||||||
|
const aid = currentArtworkId();
|
||||||
|
if (aid) params.artworkId = aid;
|
||||||
|
if (query.groupId) params.groupId = query.groupId;
|
||||||
|
if (query.batchId) params.batchId = query.batchId;
|
||||||
|
if (query.status) params.status = query.status;
|
||||||
|
if (query.keyword) params.keyword = query.keyword;
|
||||||
|
}
|
||||||
|
await downloadFile('/trace-codes/export', `trace-codes.${format}`, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function batchAssignGroup(key: string) {
|
||||||
|
const groupId = key === '__none__' ? null : Number(key);
|
||||||
|
await traceCodeApi.batchGroup(checkedKeys.value.map(String), groupId);
|
||||||
|
message.success(t('common.msg.operationSuccess'));
|
||||||
|
await load();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function batchStatus(disabled: boolean) {
|
||||||
|
await traceCodeApi.batchStatus(checkedKeys.value.map(String), disabled);
|
||||||
|
message.success(t('common.msg.operationSuccess'));
|
||||||
|
await load();
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetGroupForm() {
|
||||||
|
editingGroup.value = null;
|
||||||
|
groupForm.name = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function editGroup(g: any) {
|
||||||
|
editingGroup.value = g.id;
|
||||||
|
groupForm.name = g.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveGroup() {
|
||||||
|
if (editingGroup.value) {
|
||||||
|
await traceCodeApi.updateGroup(editingGroup.value, { name: groupForm.name });
|
||||||
|
} else {
|
||||||
|
await traceCodeApi.createGroup({ name: groupForm.name });
|
||||||
|
}
|
||||||
|
message.success(t('common.msg.saved'));
|
||||||
|
resetGroupForm();
|
||||||
|
await loadGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeGroup(g: any) {
|
||||||
|
dialog.warning({
|
||||||
|
title: t('common.action.delete'),
|
||||||
|
content: t('common.msg.confirmDelete'),
|
||||||
|
positiveText: t('common.action.confirm'),
|
||||||
|
negativeText: t('common.action.cancel'),
|
||||||
|
onPositiveClick: async () => {
|
||||||
|
await traceCodeApi.removeGroup(g.id);
|
||||||
|
message.success(t('common.msg.deleted'));
|
||||||
|
await loadGroups();
|
||||||
|
await load();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => fixedArtworkId.value,
|
||||||
|
async (aid) => {
|
||||||
|
query.artworkId = aid;
|
||||||
|
genForm.artworkId = aid;
|
||||||
|
query.batchId = null;
|
||||||
|
query.page = 1;
|
||||||
|
await loadBatches();
|
||||||
|
await load();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
if (!fixedArtworkId.value) {
|
||||||
|
const aid = Number(route.query.artworkId);
|
||||||
|
if (aid) {
|
||||||
|
query.artworkId = aid;
|
||||||
|
genForm.artworkId = aid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await Promise.all([loadBatches(), loadGroups()]);
|
||||||
|
await load();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.trace-code-panel {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.panel-toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
.toolbar-control {
|
||||||
|
width: 170px;
|
||||||
|
}
|
||||||
|
.toolbar-control.wide {
|
||||||
|
width: 210px;
|
||||||
|
}
|
||||||
|
.toolbar-control.narrow {
|
||||||
|
width: 130px;
|
||||||
|
}
|
||||||
|
.spacer {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
.batch-bar {
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
.group-toolbar {
|
||||||
|
margin-bottom: 14px;
|
||||||
|
}
|
||||||
|
.group-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.mr8 {
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
@media (max-width: 720px) {
|
||||||
|
.toolbar-control,
|
||||||
|
.toolbar-control.wide,
|
||||||
|
.toolbar-control.narrow {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.panel-toolbar :deep(.n-button) {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -59,7 +59,6 @@ import {
|
|||||||
GridOutline,
|
GridOutline,
|
||||||
DocumentTextOutline,
|
DocumentTextOutline,
|
||||||
ImagesOutline,
|
ImagesOutline,
|
||||||
QrCodeOutline,
|
|
||||||
CubeOutline,
|
CubeOutline,
|
||||||
ListOutline,
|
ListOutline,
|
||||||
PeopleOutline,
|
PeopleOutline,
|
||||||
@@ -92,7 +91,6 @@ const menuOptions = computed<MenuOption[]>(() => {
|
|||||||
{ label: t('menu.dashboard'), key: 'dashboard', icon: renderIcon(GridOutline) },
|
{ label: t('menu.dashboard'), key: 'dashboard', icon: renderIcon(GridOutline) },
|
||||||
{ label: t('menu.templates'), key: 'templates', icon: renderIcon(DocumentTextOutline) },
|
{ label: t('menu.templates'), key: 'templates', icon: renderIcon(DocumentTextOutline) },
|
||||||
{ label: t('menu.artworks'), key: 'artworks', icon: renderIcon(ImagesOutline) },
|
{ label: t('menu.artworks'), key: 'artworks', icon: renderIcon(ImagesOutline) },
|
||||||
{ label: t('menu.traceCodes'), key: 'traceCodes', icon: renderIcon(QrCodeOutline) },
|
|
||||||
{ label: t('menu.outbound'), key: 'outbound', icon: renderIcon(CubeOutline) },
|
{ label: t('menu.outbound'), key: 'outbound', icon: renderIcon(CubeOutline) },
|
||||||
{ label: t('menu.audit'), key: 'audit', icon: renderIcon(ShieldCheckmarkOutline), auditOnly: true },
|
{ label: t('menu.audit'), key: 'audit', icon: renderIcon(ShieldCheckmarkOutline), auditOnly: true },
|
||||||
{ label: t('menu.queryLogs'), key: 'queryLogs', icon: renderIcon(ListOutline) },
|
{ label: t('menu.queryLogs'), key: 'queryLogs', icon: renderIcon(ListOutline) },
|
||||||
@@ -104,7 +102,7 @@ const menuOptions = computed<MenuOption[]>(() => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const activeKey = computed(() => (route.name === 'artwork-detail' ? 'artworks' : (route.name as string)));
|
const activeKey = computed(() => (['artwork-detail', 'traceCodes'].includes(route.name as string) ? 'artworks' : (route.name as string)));
|
||||||
const currentTitle = computed(() => (activeKey.value ? t(`menu.${activeKey.value}`) : ''));
|
const currentTitle = computed(() => (activeKey.value ? t(`menu.${activeKey.value}`) : ''));
|
||||||
|
|
||||||
const userOptions = computed(() => [
|
const userOptions = computed(() => [
|
||||||
|
|||||||
@@ -119,8 +119,8 @@
|
|||||||
"menu": {
|
"menu": {
|
||||||
"dashboard": "Dashboard",
|
"dashboard": "Dashboard",
|
||||||
"templates": "Templates",
|
"templates": "Templates",
|
||||||
"artworks": "Artworks",
|
"artworks": "Artwork Files",
|
||||||
"traceCodes": "Trace Codes",
|
"traceCodes": "Item Codes",
|
||||||
"outbound": "Outbound & Chain",
|
"outbound": "Outbound & Chain",
|
||||||
"audit": "Content Audit",
|
"audit": "Content Audit",
|
||||||
"queryLogs": "Query Logs",
|
"queryLogs": "Query Logs",
|
||||||
@@ -187,8 +187,8 @@
|
|||||||
"codeCount": "Codes",
|
"codeCount": "Codes",
|
||||||
"activeCount": "Activated",
|
"activeCount": "Activated",
|
||||||
"queryTotal": "Total Queries",
|
"queryTotal": "Total Queries",
|
||||||
"traceCodes": "Trace Codes (multi-code)",
|
"traceCodes": "Batches & Item Codes",
|
||||||
"genCodes": "Generate Codes",
|
"genCodes": "Generate Item Codes",
|
||||||
"viewCodes": "View All Codes",
|
"viewCodes": "View All Codes",
|
||||||
"batches": "Batches",
|
"batches": "Batches",
|
||||||
"selectArtwork": "Select Artwork",
|
"selectArtwork": "Select Artwork",
|
||||||
@@ -227,7 +227,7 @@
|
|||||||
"codes": "Trace Codes",
|
"codes": "Trace Codes",
|
||||||
"batchNo": "Batch No.",
|
"batchNo": "Batch No.",
|
||||||
"quantity": "Quantity",
|
"quantity": "Quantity",
|
||||||
"generate": "Generate",
|
"generate": "Generate Item Codes",
|
||||||
"generatedCount": "Generated",
|
"generatedCount": "Generated",
|
||||||
"shortCode": "Short Code",
|
"shortCode": "Short Code",
|
||||||
"code": "Trace Code",
|
"code": "Trace Code",
|
||||||
@@ -236,7 +236,7 @@
|
|||||||
"firstActivatedAt": "First Activated",
|
"firstActivatedAt": "First Activated",
|
||||||
"exportBatch": "Export Batch",
|
"exportBatch": "Export Batch",
|
||||||
"exportCurrent": "Current filter",
|
"exportCurrent": "Current filter",
|
||||||
"bindArtwork": "Bind Artwork",
|
"bindArtwork": "Link Artwork File",
|
||||||
"selectArtwork": "Select artwork",
|
"selectArtwork": "Select artwork",
|
||||||
"qrPreview": "QR Preview",
|
"qrPreview": "QR Preview",
|
||||||
"generating": "Generating, please wait…",
|
"generating": "Generating, please wait…",
|
||||||
@@ -263,7 +263,7 @@
|
|||||||
"outTime": "Outbound Time",
|
"outTime": "Outbound Time",
|
||||||
"outImage": "Outbound Photo",
|
"outImage": "Outbound Photo",
|
||||||
"selectCode": "Select Trace Code",
|
"selectCode": "Select Trace Code",
|
||||||
"selectCodePlaceholder": "Search by short code / SKU / archive no.",
|
"selectCodePlaceholder": "Search by short code / trace code / archive no.",
|
||||||
"onchainSection": "On-chain info (optional; filling a hash records the result)",
|
"onchainSection": "On-chain info (optional; filling a hash records the result)",
|
||||||
"txHashTip": "Paste the on-chain transaction/attestation hash",
|
"txHashTip": "Paste the on-chain transaction/attestation hash",
|
||||||
"selectFile": "Select File",
|
"selectFile": "Select File",
|
||||||
@@ -291,7 +291,7 @@
|
|||||||
"queriedAt": "Time",
|
"queriedAt": "Time",
|
||||||
"startTime": "Start",
|
"startTime": "Start",
|
||||||
"endTime": "End",
|
"endTime": "End",
|
||||||
"keywordPlaceholder": "Short code / trace code / SKU / archive no."
|
"keywordPlaceholder": "Short code / trace code / archive no."
|
||||||
},
|
},
|
||||||
"user": {
|
"user": {
|
||||||
"username": "Username",
|
"username": "Username",
|
||||||
|
|||||||
@@ -119,8 +119,8 @@
|
|||||||
"menu": {
|
"menu": {
|
||||||
"dashboard": "数据看板",
|
"dashboard": "数据看板",
|
||||||
"templates": "溯源模板",
|
"templates": "溯源模板",
|
||||||
"artworks": "艺术品建档",
|
"artworks": "艺术品档案",
|
||||||
"traceCodes": "追溯码管理",
|
"traceCodes": "实物码明细",
|
||||||
"outbound": "出库与上链",
|
"outbound": "出库与上链",
|
||||||
"audit": "内容审核",
|
"audit": "内容审核",
|
||||||
"queryLogs": "查询日志",
|
"queryLogs": "查询日志",
|
||||||
@@ -187,8 +187,8 @@
|
|||||||
"codeCount": "追溯码数",
|
"codeCount": "追溯码数",
|
||||||
"activeCount": "已激活",
|
"activeCount": "已激活",
|
||||||
"queryTotal": "查询总数",
|
"queryTotal": "查询总数",
|
||||||
"traceCodes": "追溯码(一款多码)",
|
"traceCodes": "批次与实物码",
|
||||||
"genCodes": "生成追溯码",
|
"genCodes": "生成实物码",
|
||||||
"viewCodes": "查看全部码",
|
"viewCodes": "查看全部码",
|
||||||
"batches": "批次列表",
|
"batches": "批次列表",
|
||||||
"selectArtwork": "选择作品",
|
"selectArtwork": "选择作品",
|
||||||
@@ -227,7 +227,7 @@
|
|||||||
"codes": "追溯码列表",
|
"codes": "追溯码列表",
|
||||||
"batchNo": "批次编号",
|
"batchNo": "批次编号",
|
||||||
"quantity": "数量",
|
"quantity": "数量",
|
||||||
"generate": "生成追溯码",
|
"generate": "生成实物码",
|
||||||
"generatedCount": "已生成",
|
"generatedCount": "已生成",
|
||||||
"shortCode": "短码",
|
"shortCode": "短码",
|
||||||
"code": "追溯码",
|
"code": "追溯码",
|
||||||
@@ -236,7 +236,7 @@
|
|||||||
"firstActivatedAt": "首次激活时间",
|
"firstActivatedAt": "首次激活时间",
|
||||||
"exportBatch": "导出本批",
|
"exportBatch": "导出本批",
|
||||||
"exportCurrent": "当前筛选",
|
"exportCurrent": "当前筛选",
|
||||||
"bindArtwork": "绑定作品",
|
"bindArtwork": "关联作品档案",
|
||||||
"selectArtwork": "选择作品",
|
"selectArtwork": "选择作品",
|
||||||
"qrPreview": "二维码预览",
|
"qrPreview": "二维码预览",
|
||||||
"generating": "正在生成,请稍候…",
|
"generating": "正在生成,请稍候…",
|
||||||
@@ -263,7 +263,7 @@
|
|||||||
"outTime": "出库时间",
|
"outTime": "出库时间",
|
||||||
"outImage": "出库实况图",
|
"outImage": "出库实况图",
|
||||||
"selectCode": "选择追溯码",
|
"selectCode": "选择追溯码",
|
||||||
"selectCodePlaceholder": "输入短码 / SKU / 档案号搜索",
|
"selectCodePlaceholder": "输入短码 / 追溯码 / 档案号搜索",
|
||||||
"onchainSection": "上链信息(选填,填写哈希即登记上链结果)",
|
"onchainSection": "上链信息(选填,填写哈希即登记上链结果)",
|
||||||
"txHashTip": "粘贴链上交易/存证哈希",
|
"txHashTip": "粘贴链上交易/存证哈希",
|
||||||
"selectFile": "选择文件",
|
"selectFile": "选择文件",
|
||||||
@@ -291,7 +291,7 @@
|
|||||||
"queriedAt": "查询时间",
|
"queriedAt": "查询时间",
|
||||||
"startTime": "开始时间",
|
"startTime": "开始时间",
|
||||||
"endTime": "结束时间",
|
"endTime": "结束时间",
|
||||||
"keywordPlaceholder": "短码 / 追溯码 / SKU / 档案号"
|
"keywordPlaceholder": "短码 / 追溯码 / 档案号"
|
||||||
},
|
},
|
||||||
"user": {
|
"user": {
|
||||||
"username": "用户名",
|
"username": "用户名",
|
||||||
|
|||||||
@@ -185,56 +185,23 @@
|
|||||||
</n-card>
|
</n-card>
|
||||||
</n-grid-item>
|
</n-grid-item>
|
||||||
|
|
||||||
<!-- 追溯码(一款多码) -->
|
<!-- 批次与实物码:每套实物一码 -->
|
||||||
<n-grid-item>
|
<n-grid-item>
|
||||||
<n-card :title="t('pages.artwork.traceCodes')" :bordered="false">
|
<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 :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.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.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.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-item :label="t('pages.artwork.queryTotal')">{{ artwork?.codeStats?.queryTotal ?? 0 }}</n-descriptions-item>
|
||||||
</n-descriptions>
|
</n-descriptions>
|
||||||
<div class="batch-title">{{ t('pages.artwork.batches') }}</div>
|
<div class="trace-panel-wrap">
|
||||||
<n-empty v-if="!artwork?.batches?.length" :description="t('common.msg.noData')" size="small" />
|
<trace-code-panel :artwork-id="artworkId" embedded />
|
||||||
<n-data-table
|
</div>
|
||||||
v-else
|
|
||||||
size="small"
|
|
||||||
:columns="batchColumns"
|
|
||||||
:data="artwork.batches"
|
|
||||||
:row-key="(r) => r.id"
|
|
||||||
/>
|
|
||||||
</n-card>
|
</n-card>
|
||||||
</n-grid-item>
|
</n-grid-item>
|
||||||
</template>
|
</template>
|
||||||
</n-grid>
|
</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-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">
|
<n-form :model="nodeForm" label-placement="top">
|
||||||
@@ -297,15 +264,16 @@
|
|||||||
import { computed, h, onMounted, reactive, ref } from 'vue';
|
import { computed, h, onMounted, reactive, ref } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
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 { ArrowBackOutline, AddOutline } from '@vicons/ionicons5';
|
||||||
import { ArtworkStatus, CertType, NodeType } from '@artveris/shared';
|
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 { useAuthStore } from '@/stores/auth';
|
||||||
import MediaUpload from '@/components/MediaUpload.vue';
|
import MediaUpload from '@/components/MediaUpload.vue';
|
||||||
import MediaSorter from '@/components/MediaSorter.vue';
|
import MediaSorter from '@/components/MediaSorter.vue';
|
||||||
|
import TraceCodePanel from '@/components/TraceCodePanel.vue';
|
||||||
import { message, dialog } from '@/utils/feedback';
|
import { message, dialog } from '@/utils/feedback';
|
||||||
import { fmt, fmtDate, statusType } from '@/utils/format';
|
import { fmtDate } from '@/utils/format';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const route = useRoute();
|
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 () => {
|
onMounted(async () => {
|
||||||
await loadTemplates();
|
await loadTemplates();
|
||||||
if (!isNew.value) await loadArtwork();
|
if (!isNew.value) await loadArtwork();
|
||||||
@@ -565,10 +490,8 @@ onMounted(async () => {
|
|||||||
.mr8 {
|
.mr8 {
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
.batch-title {
|
.trace-panel-wrap {
|
||||||
font-size: 13px;
|
margin-top: 14px;
|
||||||
color: #6b7280;
|
|
||||||
margin: 14px 0 8px;
|
|
||||||
}
|
}
|
||||||
.node-head {
|
.node-head {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -1,422 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<div class="page-toolbar">
|
<trace-code-panel />
|
||||||
<n-select
|
|
||||||
v-model:value="query.groupId"
|
|
||||||
:options="groupFilterOptions"
|
|
||||||
clearable
|
|
||||||
:placeholder="t('pages.traceCode.allGroups')"
|
|
||||||
style="width: 170px"
|
|
||||||
@update:value="onSearch"
|
|
||||||
/>
|
|
||||||
<n-select
|
|
||||||
v-model:value="query.batchId"
|
|
||||||
:options="batchOptions"
|
|
||||||
clearable
|
|
||||||
:placeholder="t('pages.traceCode.batchNo')"
|
|
||||||
style="width: 190px"
|
|
||||||
@update:value="onSearch"
|
|
||||||
/>
|
|
||||||
<n-select
|
|
||||||
v-model:value="query.status"
|
|
||||||
:options="statusOptions"
|
|
||||||
clearable
|
|
||||||
:placeholder="t('common.label.status')"
|
|
||||||
style="width: 130px"
|
|
||||||
@update:value="onSearch"
|
|
||||||
/>
|
|
||||||
<n-input
|
|
||||||
v-model:value="query.keyword"
|
|
||||||
:placeholder="t('pages.traceCode.shortCode')"
|
|
||||||
clearable
|
|
||||||
style="width: 160px"
|
|
||||||
@keyup.enter="onSearch"
|
|
||||||
/>
|
|
||||||
<n-button type="primary" @click="onSearch">
|
|
||||||
<template #icon><n-icon :component="SearchOutline" /></template>
|
|
||||||
{{ t('common.action.search') }}
|
|
||||||
</n-button>
|
|
||||||
<div class="spacer" />
|
|
||||||
<n-button v-if="auth.canWrite" @click="groupModal = true">
|
|
||||||
<template #icon><n-icon :component="FolderOutline" /></template>
|
|
||||||
{{ t('pages.traceCode.manageGroups') }}
|
|
||||||
</n-button>
|
|
||||||
<n-dropdown v-if="auth.canWrite" trigger="click" :options="exportOptions" @select="onExport">
|
|
||||||
<n-button>
|
|
||||||
<template #icon><n-icon :component="DownloadOutline" /></template>
|
|
||||||
{{ t('common.action.export') }}
|
|
||||||
</n-button>
|
|
||||||
</n-dropdown>
|
|
||||||
<n-button v-if="auth.canWrite" type="primary" @click="genModal = true">
|
|
||||||
<template #icon><n-icon :component="AddOutline" /></template>
|
|
||||||
{{ t('pages.traceCode.generate') }}
|
|
||||||
</n-button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 批量操作条 -->
|
|
||||||
<n-card v-if="auth.canWrite && checkedKeys.length" size="small" class="batch-bar" :bordered="false">
|
|
||||||
<n-space align="center">
|
|
||||||
<span>{{ t('pages.traceCode.selected', { n: checkedKeys.length }) }}</span>
|
|
||||||
<n-dropdown trigger="click" :options="groupAssignOptions" @select="batchAssignGroup">
|
|
||||||
<n-button size="small">
|
|
||||||
<template #icon><n-icon :component="FolderOutline" /></template>
|
|
||||||
{{ t('pages.traceCode.batchGroup') }}
|
|
||||||
</n-button>
|
|
||||||
</n-dropdown>
|
|
||||||
<n-button size="small" @click="batchStatus(false)">{{ t('pages.traceCode.batchEnable') }}</n-button>
|
|
||||||
<n-button size="small" type="warning" @click="batchStatus(true)">{{ t('pages.traceCode.batchDisable') }}</n-button>
|
|
||||||
</n-space>
|
|
||||||
</n-card>
|
|
||||||
|
|
||||||
<n-data-table
|
|
||||||
:columns="columns"
|
|
||||||
:data="rows"
|
|
||||||
:loading="loading"
|
|
||||||
:pagination="pagination"
|
|
||||||
remote
|
|
||||||
:row-key="(r) => r.id"
|
|
||||||
v-model:checked-row-keys="checkedKeys"
|
|
||||||
@update:page="onPage"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- 生成 -->
|
|
||||||
<n-modal v-model:show="genModal" preset="card" :title="t('pages.traceCode.generate')" style="width: 440px">
|
|
||||||
<n-form :model="genForm" label-placement="top">
|
|
||||||
<n-form-item :label="t('pages.artwork.selectArtwork')" required>
|
|
||||||
<n-select
|
|
||||||
v-model:value="genForm.artworkId"
|
|
||||||
filterable
|
|
||||||
remote
|
|
||||||
clearable
|
|
||||||
:loading="artworkSearching"
|
|
||||||
:options="artworkOptions"
|
|
||||||
:placeholder="t('pages.artwork.selectArtworkTip')"
|
|
||||||
@search="searchArtworks"
|
|
||||||
/>
|
|
||||||
</n-form-item>
|
|
||||||
<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.group')">
|
|
||||||
<n-select v-model:value="genForm.groupId" :options="groupPlainOptions" clearable :placeholder="t('pages.traceCode.noGroup')" />
|
|
||||||
</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>
|
|
||||||
<n-text v-if="generating" depth="3">{{ t('pages.traceCode.generating') }}</n-text>
|
|
||||||
<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="generate">{{ t('common.action.generate') }}</n-button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</n-modal>
|
|
||||||
|
|
||||||
<!-- 二维码 -->
|
|
||||||
<n-modal v-model:show="qrModal" preset="card" :title="t('pages.traceCode.qrPreview')" style="width: 360px">
|
|
||||||
<div style="text-align: center">
|
|
||||||
<img :src="qrSrc" alt="qrcode" style="width: 280px; height: 280px" />
|
|
||||||
<div style="margin-top: 8px; opacity: 0.6; word-break: break-all">{{ qrUrl }}</div>
|
|
||||||
</div>
|
|
||||||
</n-modal>
|
|
||||||
|
|
||||||
<!-- 分组管理 -->
|
|
||||||
<n-modal v-model:show="groupModal" preset="card" :title="t('pages.traceCode.manageGroups')" style="width: 520px">
|
|
||||||
<div class="page-toolbar">
|
|
||||||
<n-input v-model:value="groupForm.name" :placeholder="t('pages.traceCode.groupName')" style="width: 200px" />
|
|
||||||
<n-button type="primary" :disabled="!groupForm.name" @click="saveGroup">
|
|
||||||
{{ editingGroup ? t('common.action.save') : t('pages.traceCode.createGroup') }}
|
|
||||||
</n-button>
|
|
||||||
<n-button v-if="editingGroup" @click="resetGroupForm">{{ t('common.action.cancel') }}</n-button>
|
|
||||||
</div>
|
|
||||||
<n-list bordered>
|
|
||||||
<n-list-item v-for="g in groups" :key="g.id">
|
|
||||||
<div class="group-row">
|
|
||||||
<span>{{ g.name }}<n-text depth="3">({{ g._count?.traceCodes ?? 0 }})</n-text></span>
|
|
||||||
<span>
|
|
||||||
<n-button text type="primary" size="small" @click="editGroup(g)">{{ t('common.action.edit') }}</n-button>
|
|
||||||
<n-button text type="error" size="small" style="margin-left: 10px" @click="removeGroup(g)">{{ t('common.action.delete') }}</n-button>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</n-list-item>
|
|
||||||
</n-list>
|
|
||||||
</n-modal>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, h, onMounted, reactive, ref } from 'vue';
|
import TraceCodePanel from '@/components/TraceCodePanel.vue';
|
||||||
import { useRoute } from 'vue-router';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
|
||||||
import { NButton, NIcon, NTag, NText, type DataTableColumns } from 'naive-ui';
|
|
||||||
import { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline, FolderOutline, OpenOutline } from '@vicons/ionicons5';
|
|
||||||
import { TraceCodeStatus } from '@artveris/shared';
|
|
||||||
import { traceCodeApi, jobApi, artworkApi } from '@/api';
|
|
||||||
import { useAuthStore } from '@/stores/auth';
|
|
||||||
import { message, dialog } from '@/utils/feedback';
|
|
||||||
import { fmt, statusType } from '@/utils/format';
|
|
||||||
import { downloadFile } from '@/utils/download';
|
|
||||||
|
|
||||||
const { t } = useI18n();
|
|
||||||
const route = useRoute();
|
|
||||||
const auth = useAuthStore();
|
|
||||||
|
|
||||||
const rows = ref<any[]>([]);
|
|
||||||
const loading = ref(false);
|
|
||||||
const checkedKeys = ref<Array<string | number>>([]);
|
|
||||||
const query = reactive<{ artworkId: number | null; groupId: number | null; batchId: number | null; status: string | null; keyword: string; page: number; pageSize: number }>({
|
|
||||||
artworkId: null,
|
|
||||||
groupId: null,
|
|
||||||
batchId: null,
|
|
||||||
status: null,
|
|
||||||
keyword: '',
|
|
||||||
page: 1,
|
|
||||||
pageSize: 10,
|
|
||||||
});
|
|
||||||
const pagination = reactive({ page: 1, pageSize: 10, itemCount: 0 });
|
|
||||||
const statusOptions = Object.values(TraceCodeStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
|
|
||||||
|
|
||||||
const batches = ref<any[]>([]);
|
|
||||||
const batchOptions = ref<{ label: string; value: number }[]>([]);
|
|
||||||
const groups = ref<any[]>([]);
|
|
||||||
const groupFilterOptions = computed(() => groups.value.map((g) => ({ label: g.name, value: g.id })));
|
|
||||||
const groupPlainOptions = computed(() => groups.value.map((g) => ({ label: g.name, value: g.id })));
|
|
||||||
const groupAssignOptions = computed(() => [
|
|
||||||
{ label: t('pages.traceCode.noGroup'), key: '__none__' },
|
|
||||||
...groups.value.map((g) => ({ label: g.name, key: String(g.id) })),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const genModal = ref(false);
|
|
||||||
const generating = ref(false);
|
|
||||||
const genForm = reactive<{ artworkId: number | null; quantity: number; batchNo: string; groupId: number | null }>({ artworkId: null, quantity: 100, batchNo: '', groupId: null });
|
|
||||||
|
|
||||||
const artworkSearching = ref(false);
|
|
||||||
const artworkOptions = ref<{ label: string; value: number }[]>([]);
|
|
||||||
let artworkTimer: ReturnType<typeof setTimeout> | null = null;
|
|
||||||
function searchArtworks(keyword: string) {
|
|
||||||
if (artworkTimer) clearTimeout(artworkTimer);
|
|
||||||
artworkTimer = setTimeout(async () => {
|
|
||||||
artworkSearching.value = true;
|
|
||||||
try {
|
|
||||||
const res: any = await artworkApi.list({ keyword: keyword || undefined, pageSize: 20 });
|
|
||||||
artworkOptions.value = res.list.map((a: any) => ({
|
|
||||||
label: `${a.archiveNo || '-'} · ${a.title}`,
|
|
||||||
value: a.id,
|
|
||||||
}));
|
|
||||||
} finally {
|
|
||||||
artworkSearching.value = false;
|
|
||||||
}
|
|
||||||
}, 300);
|
|
||||||
}
|
|
||||||
|
|
||||||
const qrModal = ref(false);
|
|
||||||
const qrSrc = ref('');
|
|
||||||
const qrUrl = ref('');
|
|
||||||
|
|
||||||
const groupModal = ref(false);
|
|
||||||
const groupForm = reactive<{ name: string }>({ name: '' });
|
|
||||||
const editingGroup = ref<number | null>(null);
|
|
||||||
|
|
||||||
const columns = computed<DataTableColumns<any>>(() => [
|
|
||||||
{ type: 'selection' },
|
|
||||||
{ title: () => t('pages.traceCode.shortCode'), key: 'shortCode', width: 120 },
|
|
||||||
{
|
|
||||||
title: () => t('pages.traceCode.url'),
|
|
||||||
key: 'url',
|
|
||||||
ellipsis: { tooltip: true },
|
|
||||||
render: (r) =>
|
|
||||||
h(
|
|
||||||
'a',
|
|
||||||
{ href: r.url, target: '_blank', rel: 'noopener', style: 'color: var(--brand); text-decoration: none' },
|
|
||||||
[r.url, h(NIcon, { component: OpenOutline, style: 'vertical-align:-2px;margin-left:4px' })],
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{ title: () => t('pages.traceCode.group'), key: 'group', width: 100, render: (r) => r.group?.name || h(NText, { depth: 3 }, { default: () => t('pages.traceCode.noGroup') }) },
|
|
||||||
{ title: () => t('pages.artwork.archiveNo'), key: 'archiveNo', width: 130, render: (r) => r.artwork?.archiveNo || '-' },
|
|
||||||
{ title: () => t('pages.artwork.title'), key: 'artwork', width: 130, render: (r) => r.artwork?.title || '-' },
|
|
||||||
{
|
|
||||||
title: () => t('common.label.status'),
|
|
||||||
key: 'status',
|
|
||||||
width: 96,
|
|
||||||
render: (r) => h(NTag, { size: 'small', type: statusType(r.status) }, { default: () => t(`common.status.${r.status}`) }),
|
|
||||||
},
|
|
||||||
{ title: () => t('pages.traceCode.queryCount'), key: 'queryCount', width: 80 },
|
|
||||||
{
|
|
||||||
title: () => t('common.label.operation'),
|
|
||||||
key: 'ops',
|
|
||||||
width: 70,
|
|
||||||
render: (r) =>
|
|
||||||
h(NButton, { quaternary: true, circle: true, size: 'small', onClick: () => showQr(r) }, { icon: () => h(NIcon, null, { default: () => h(QrCodeOutline) }) }),
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
async function loadBatches() {
|
|
||||||
const res: any = await traceCodeApi.batches({ pageSize: 100 });
|
|
||||||
batches.value = res.list;
|
|
||||||
batchOptions.value = res.list.map((b: any) => ({ label: `${b.batchNo} (${b.generatedCount}/${b.quantity})`, value: b.id }));
|
|
||||||
}
|
|
||||||
async function loadGroups() {
|
|
||||||
groups.value = await traceCodeApi.groups();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function load() {
|
|
||||||
loading.value = true;
|
|
||||||
checkedKeys.value = [];
|
|
||||||
try {
|
|
||||||
const res: any = await traceCodeApi.list({
|
|
||||||
artworkId: query.artworkId || undefined,
|
|
||||||
groupId: query.groupId || undefined,
|
|
||||||
batchId: query.batchId || undefined,
|
|
||||||
status: query.status || undefined,
|
|
||||||
keyword: query.keyword || undefined,
|
|
||||||
page: query.page,
|
|
||||||
pageSize: query.pageSize,
|
|
||||||
});
|
|
||||||
rows.value = res.list;
|
|
||||||
pagination.itemCount = res.total;
|
|
||||||
pagination.page = res.page;
|
|
||||||
} finally {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function onSearch() {
|
|
||||||
query.page = 1;
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
function onPage(p: number) {
|
|
||||||
query.page = p;
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function generate() {
|
|
||||||
if (!genForm.artworkId) {
|
|
||||||
message.error(t('pages.artwork.selectArtworkTip'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
generating.value = true;
|
|
||||||
try {
|
|
||||||
const res: any = await traceCodeApi.generate({
|
|
||||||
artworkId: genForm.artworkId,
|
|
||||||
quantity: genForm.quantity,
|
|
||||||
batchNo: genForm.batchNo || undefined,
|
|
||||||
groupId: genForm.groupId || 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;
|
|
||||||
await loadBatches();
|
|
||||||
await load();
|
|
||||||
} finally {
|
|
||||||
generating.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function showQr(r: any) {
|
|
||||||
qrSrc.value = traceCodeApi.qrUrl(r.id);
|
|
||||||
qrUrl.value = r.url;
|
|
||||||
qrModal.value = true;
|
|
||||||
}
|
|
||||||
const exportOptions = computed(() => {
|
|
||||||
const cur = t('pages.traceCode.exportCurrent');
|
|
||||||
const opts: Array<{ label: string; key: string; type?: string }> = [
|
|
||||||
{ label: `Excel · ${cur}`, key: 'filter:xlsx' },
|
|
||||||
{ label: `CSV · ${cur}`, key: 'filter:csv' },
|
|
||||||
];
|
|
||||||
if (checkedKeys.value.length) {
|
|
||||||
const sel = t('pages.traceCode.selected', { n: checkedKeys.value.length });
|
|
||||||
opts.push({ label: `Excel · ${sel}`, key: 'selected:xlsx' });
|
|
||||||
opts.push({ label: `CSV · ${sel}`, key: 'selected:csv' });
|
|
||||||
}
|
|
||||||
return opts;
|
|
||||||
});
|
|
||||||
|
|
||||||
async function onExport(key: string) {
|
|
||||||
const [scope, format] = key.split(':');
|
|
||||||
const params: Record<string, unknown> = { format };
|
|
||||||
if (scope === 'selected') {
|
|
||||||
params.ids = checkedKeys.value.map(String).join(',');
|
|
||||||
} else {
|
|
||||||
if (query.artworkId) params.artworkId = query.artworkId;
|
|
||||||
if (query.groupId) params.groupId = query.groupId;
|
|
||||||
if (query.batchId) params.batchId = query.batchId;
|
|
||||||
if (query.status) params.status = query.status;
|
|
||||||
if (query.keyword) params.keyword = query.keyword;
|
|
||||||
}
|
|
||||||
await downloadFile('/trace-codes/export', `trace-codes.${format}`, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 批量操作 */
|
|
||||||
async function batchAssignGroup(key: string) {
|
|
||||||
const groupId = key === '__none__' ? null : Number(key);
|
|
||||||
await traceCodeApi.batchGroup(checkedKeys.value.map(String), groupId);
|
|
||||||
message.success(t('common.msg.operationSuccess'));
|
|
||||||
await load();
|
|
||||||
}
|
|
||||||
async function batchStatus(disabled: boolean) {
|
|
||||||
await traceCodeApi.batchStatus(checkedKeys.value.map(String), disabled);
|
|
||||||
message.success(t('common.msg.operationSuccess'));
|
|
||||||
await load();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 分组管理 */
|
|
||||||
function resetGroupForm() {
|
|
||||||
editingGroup.value = null;
|
|
||||||
groupForm.name = '';
|
|
||||||
}
|
|
||||||
function editGroup(g: any) {
|
|
||||||
editingGroup.value = g.id;
|
|
||||||
groupForm.name = g.name;
|
|
||||||
}
|
|
||||||
async function saveGroup() {
|
|
||||||
if (editingGroup.value) {
|
|
||||||
await traceCodeApi.updateGroup(editingGroup.value, { name: groupForm.name });
|
|
||||||
} else {
|
|
||||||
await traceCodeApi.createGroup({ name: groupForm.name });
|
|
||||||
}
|
|
||||||
message.success(t('common.msg.saved'));
|
|
||||||
resetGroupForm();
|
|
||||||
await loadGroups();
|
|
||||||
}
|
|
||||||
function removeGroup(g: any) {
|
|
||||||
dialog.warning({
|
|
||||||
title: t('common.action.delete'),
|
|
||||||
content: t('common.msg.confirmDelete'),
|
|
||||||
positiveText: t('common.action.confirm'),
|
|
||||||
negativeText: t('common.action.cancel'),
|
|
||||||
onPositiveClick: async () => {
|
|
||||||
await traceCodeApi.removeGroup(g.id);
|
|
||||||
message.success(t('common.msg.deleted'));
|
|
||||||
await loadGroups();
|
|
||||||
await load();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
// 支持从作品详情跳转:?artworkId=xx 直接筛选该款的码
|
|
||||||
const aid = Number(route.query.artworkId);
|
|
||||||
if (aid) query.artworkId = aid;
|
|
||||||
await Promise.all([loadBatches(), loadGroups()]);
|
|
||||||
await load();
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.mr8 {
|
|
||||||
margin-right: 8px;
|
|
||||||
}
|
|
||||||
.batch-bar {
|
|
||||||
margin-bottom: 12px;
|
|
||||||
}
|
|
||||||
.group-row {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { buildPage } from '../common/utils/pagination.util';
|
|||||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||||
|
|
||||||
class QueryLogQueryDto extends PaginationDto {
|
class QueryLogQueryDto extends PaginationDto {
|
||||||
@ApiPropertyOptional({ description: '关键词(短码 / 追溯码 / SKU / 档案编号)' })
|
@ApiPropertyOptional({ description: '关键词(短码 / 追溯码 / 档案编号)' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
keyword?: string;
|
keyword?: string;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export class QueryTraceCodeDto extends PaginationDto {
|
|||||||
@IsInt()
|
@IsInt()
|
||||||
groupId?: number;
|
groupId?: number;
|
||||||
|
|
||||||
@ApiPropertyOptional({ description: '关键词(短码/追溯码/SKU/档案号)' })
|
@ApiPropertyOptional({ description: '关键词(短码/追溯码/档案号/作品名称)' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
keyword?: string;
|
keyword?: string;
|
||||||
@@ -117,6 +117,12 @@ export class BatchStatusDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class QueryBatchDto extends PaginationDto {
|
export class QueryBatchDto extends PaginationDto {
|
||||||
|
@ApiPropertyOptional({ description: '作品/款式 ID' })
|
||||||
|
@IsOptional()
|
||||||
|
@Type(() => Number)
|
||||||
|
@IsInt()
|
||||||
|
artworkId?: number;
|
||||||
|
|
||||||
@ApiPropertyOptional({ description: '关键词(批次编号)' })
|
@ApiPropertyOptional({ description: '关键词(批次编号)' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export class TraceCodeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async generateBatch(dto: GenerateBatchDto, userId: number) {
|
async generateBatch(dto: GenerateBatchDto, userId: number) {
|
||||||
// 必须指定作品(款):生码即归属该款(一款多码)
|
// 必须指定作品档案/款式;每条 TraceCode 对应一套实物,仍是一物一码。
|
||||||
const artwork = await this.prisma.artwork.findFirst({
|
const artwork = await this.prisma.artwork.findFirst({
|
||||||
where: { id: dto.artworkId, deletedAt: null },
|
where: { id: dto.artworkId, deletedAt: null },
|
||||||
});
|
});
|
||||||
@@ -138,6 +138,7 @@ export class TraceCodeService {
|
|||||||
|
|
||||||
async listBatches(query: QueryBatchDto) {
|
async listBatches(query: QueryBatchDto) {
|
||||||
const where: Prisma.BatchWhereInput = {};
|
const where: Prisma.BatchWhereInput = {};
|
||||||
|
if (query.artworkId) where.artworkId = query.artworkId;
|
||||||
if (query.keyword) where.batchNo = { contains: query.keyword };
|
if (query.keyword) where.batchNo = { contains: query.keyword };
|
||||||
const [list, total] = await this.prisma.$transaction([
|
const [list, total] = await this.prisma.$transaction([
|
||||||
this.prisma.batch.findMany({
|
this.prisma.batch.findMany({
|
||||||
|
|||||||
+18
-18
@@ -12,11 +12,11 @@
|
|||||||
|
|
||||||
## 2. 产品目标
|
## 2. 产品目标
|
||||||
|
|
||||||
系统以“一物一码、首次激活、多次查询”为核心逻辑,打通艺术品从建档、绑定防伪码、出库、上链到消费者扫码查询的完整闭环,让每件作品都拥有可追溯、可验证的数字身份。
|
系统以“一物一码、首次激活、多次查询”为核心逻辑。这里的“物”指每套实际生产或交付的实物;同一款式/艺术品档案可按批次生产多套实物,每套实物拥有独立追溯码、独立激活记录与独立查询次数。后台以“艺术品档案”为主入口,打通建档、批次生码、出库、上链到消费者扫码查询的完整闭环。
|
||||||
|
|
||||||
核心目标:
|
核心目标:
|
||||||
|
|
||||||
- 为每件艺术品生成唯一的数字身份与防伪追溯码。
|
- 为每套实物生成唯一的数字身份与防伪追溯码,同一款式档案下可管理多个批次与多套实物码。
|
||||||
- 向消费者清晰呈现作品信息、溯源链路、权威认证与区块链存证。
|
- 向消费者清晰呈现作品信息、溯源链路、权威认证与区块链存证。
|
||||||
- 为平台和机构提供建档、模板配置、批量生码、出库与上链管理、数据看板等一站式后台能力。
|
- 为平台和机构提供建档、模板配置、批量生码、出库与上链管理、数据看板等一站式后台能力。
|
||||||
- 完整记录每一次查询,辅助识别异常访问与防伪码被复制的风险。
|
- 完整记录每一次查询,辅助识别异常访问与防伪码被复制的风险。
|
||||||
@@ -36,14 +36,14 @@
|
|||||||
|
|
||||||
### 4.1 后台建档与出库流程
|
### 4.1 后台建档与出库流程
|
||||||
|
|
||||||
1. 平台或机构创建艺术品作品信息。
|
1. 平台或机构创建艺术品档案/款式信息。
|
||||||
2. 选择或配置信息模板。
|
2. 选择或配置信息模板。
|
||||||
3. 填写基础信息,上传作品图片、证书、制作过程等资料。
|
3. 填写基础信息,上传作品图片、证书、制作过程等资料。
|
||||||
4. 为单件或整批作品绑定唯一防伪码。
|
4. 在艺术品档案下按批次生成唯一防伪码,每套实物对应一个独立码。
|
||||||
5. 生成溯源链接、二维码或 NFC 数据。
|
5. 生成溯源链接、二维码或 NFC 数据。
|
||||||
6. 导出生码数据,用于印刷、打标或写入 NFC。
|
6. 导出生码数据,用于印刷、打标或写入 NFC。
|
||||||
7. 出库前拍摄出库实况图。
|
7. 出库前拍摄出库实况图。
|
||||||
8. 录入或批量导入出库信息、档案编号与 SKU。
|
8. 按短码/追溯码录入或批量导入出库信息、批次信息与上链结果。
|
||||||
9. 登记或触发上链,生成区块链存证。
|
9. 登记或触发上链,生成区块链存证。
|
||||||
10. 消费者通过二维码、NFC 或链接打开溯源页面。
|
10. 消费者通过二维码、NFC 或链接打开溯源页面。
|
||||||
|
|
||||||
@@ -219,11 +219,11 @@
|
|||||||
- 字段排序在用户端展示中生效。
|
- 字段排序在用户端展示中生效。
|
||||||
- 停用模板不影响已建档作品的历史展示。
|
- 停用模板不影响已建档作品的历史展示。
|
||||||
|
|
||||||
### 6.2 艺术品建档管理
|
### 6.2 艺术品档案管理
|
||||||
|
|
||||||
#### 功能说明
|
#### 功能说明
|
||||||
|
|
||||||
创建与维护艺术品档案,包括基础信息、图片、溯源节点与认证文件。
|
创建与维护艺术品档案/款式信息,包括基础信息、图片、溯源节点、认证文件、批次与实物追溯码。
|
||||||
|
|
||||||
#### 需求细项
|
#### 需求细项
|
||||||
|
|
||||||
@@ -232,12 +232,12 @@
|
|||||||
- 上传溯源节点的图片与视频。
|
- 上传溯源节点的图片与视频。
|
||||||
- 录入动态基础字段,维护溯源时间轴节点。
|
- 录入动态基础字段,维护溯源时间轴节点。
|
||||||
- 上传认证文件。
|
- 上传认证文件。
|
||||||
- 绑定或查看唯一追溯码。
|
- 在档案详情中生成、查看、分组、导出和启停该档案下的实物追溯码。
|
||||||
|
|
||||||
#### 验收标准
|
#### 验收标准
|
||||||
|
|
||||||
- 保存后用户端可查看对应作品信息。
|
- 保存后用户端可查看对应作品信息。
|
||||||
- 已绑定追溯码的作品可通过溯源链接访问。
|
- 已生成追溯码的实物可通过溯源链接访问对应档案详情。
|
||||||
- 已上传的视频可在用户端节点中查看。
|
- 已上传的视频可在用户端节点中查看。
|
||||||
- 作品停用后,用户端不再显示为正常有效状态。
|
- 作品停用后,用户端不再显示为正常有效状态。
|
||||||
|
|
||||||
@@ -245,20 +245,20 @@
|
|||||||
|
|
||||||
#### 功能说明
|
#### 功能说明
|
||||||
|
|
||||||
按批次生成唯一溯源码,供工厂打标、印刷二维码或写入 NFC。
|
在指定艺术品档案下按批次生成唯一溯源码,供工厂打标、印刷二维码或写入 NFC。
|
||||||
|
|
||||||
#### 编码与链接规则
|
#### 编码与链接规则
|
||||||
|
|
||||||
- 采用“短网址 + 随机编码”形式:`https://t.{业务域名}/{随机编码}`,示例 `https://t.example.com/a8K3pQ9x`。
|
- 采用“短网址 + 随机编码”形式:`https://t.{业务域名}/{随机编码}`,示例 `https://t.example.com/a8K3pQ9x`。
|
||||||
- 二维码内容为完整短网址。
|
- 二维码内容为完整短网址。
|
||||||
- 随机编码仅作为公开访问标识,不直接使用档案编号、SKU、批次号或内部追溯码。
|
- 随机编码仅作为公开访问标识,不直接使用档案编号、批次号或内部追溯码。
|
||||||
- 系统内部维护“随机编码 → 追溯码 → 作品”的对应关系。
|
- 系统内部维护“随机编码 → 追溯码 → 艺术品档案/实物码”的对应关系。
|
||||||
- 编码具备足够随机性,防止被批量猜测。
|
- 编码具备足够随机性,防止被批量猜测。
|
||||||
- 后续可通过调整链接映射更换落地页,不影响已印刷的二维码。
|
- 后续可通过调整链接映射更换落地页,不影响已印刷的二维码。
|
||||||
|
|
||||||
#### 需求细项
|
#### 需求细项
|
||||||
|
|
||||||
- 按批次生成指定数量的唯一追溯码。
|
- 在指定艺术品档案下按批次生成指定数量的唯一追溯码。
|
||||||
- 每个追溯码关联唯一的随机编码与短网址。
|
- 每个追溯码关联唯一的随机编码与短网址。
|
||||||
- 生成二维码图片或二维码数据。
|
- 生成二维码图片或二维码数据。
|
||||||
- 导出 CSV / Excel,字段包含批次编号、追溯码、随机编码、短网址、二维码数据与生成时间。
|
- 导出 CSV / Excel,字段包含批次编号、追溯码、随机编码、短网址、二维码数据与生成时间。
|
||||||
@@ -267,18 +267,18 @@
|
|||||||
|
|
||||||
- 同批次、跨批次的追溯码均不重复。
|
- 同批次、跨批次的追溯码均不重复。
|
||||||
- 导出文件可被常见表格软件打开。
|
- 导出文件可被常见表格软件打开。
|
||||||
- 导出的链接可访问对应页面;未绑定作品或不满足激活条件时,显示未激活提示页。
|
- 导出的链接可访问对应页面;未满足激活条件时,显示未激活提示页。
|
||||||
|
|
||||||
### 6.4 出库与上链管理
|
### 6.4 出库与上链管理
|
||||||
|
|
||||||
#### 功能说明
|
#### 功能说明
|
||||||
|
|
||||||
按批次批量导入作品的 SKU、档案编号、出库图片与上链信息。
|
按追溯码或短码批量导入实物码的出库图片与上链信息。
|
||||||
|
|
||||||
#### 需求细项
|
#### 需求细项
|
||||||
|
|
||||||
- 支持单条录入与批量导入。
|
- 支持单条录入与批量导入。
|
||||||
- 导入字段:SKU、档案编号、批次编号、出库时间、出库实况图、上链哈希值、上链时间、区块高度。
|
- 导入字段:短码/追溯码、批次编号、出库时间、出库实况图、上链哈希值、上链时间、区块高度。
|
||||||
- 支持上传出库实况图。
|
- 支持上传出库实况图。
|
||||||
- 支持记录或触发上链结果。
|
- 支持记录或触发上链结果。
|
||||||
- 可查看导入的成功、失败及失败原因。
|
- 可查看导入的成功、失败及失败原因。
|
||||||
@@ -308,7 +308,7 @@
|
|||||||
| 字段 | 说明 |
|
| 字段 | 说明 |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| 追溯码 | 被查询作品的唯一编号 |
|
| 追溯码 | 被查询作品的唯一编号 |
|
||||||
| SKU / 档案编号 | 关联的作品信息 |
|
| 档案编号 / 批次编号 | 关联的档案与批次信息 |
|
||||||
| 查询时间 | 本次访问时间 |
|
| 查询时间 | 本次访问时间 |
|
||||||
| 查询次数 | 当前累计次数 |
|
| 查询次数 | 当前累计次数 |
|
||||||
| 首次激活时间 | 第一次有效访问并激活的时间 |
|
| 首次激活时间 | 第一次有效访问并激活的时间 |
|
||||||
@@ -326,7 +326,7 @@
|
|||||||
|
|
||||||
#### 验收标准
|
#### 验收标准
|
||||||
|
|
||||||
- 可按追溯码、SKU、批次、时间范围查询日志。
|
- 可按追溯码、档案编号、批次、时间范围查询日志。
|
||||||
- 后台查询次数与用户端展示一致。
|
- 后台查询次数与用户端展示一致。
|
||||||
- 异常查询可筛选与查看。
|
- 异常查询可筛选与查看。
|
||||||
- 用户端不展示 IP、设备等敏感字段。
|
- 用户端不展示 IP、设备等敏感字段。
|
||||||
|
|||||||
+26
-15
@@ -114,7 +114,7 @@ ysp/
|
|||||||
| `auth` | 后台登录、JWT 签发与校验 |
|
| `auth` | 后台登录、JWT 签发与校验 |
|
||||||
| `rbac` | 用户、角色、权限校验(第一版固定角色) |
|
| `rbac` | 用户、角色、权限校验(第一版固定角色) |
|
||||||
| `template` | 溯源模板与动态字段管理 |
|
| `template` | 溯源模板与动态字段管理 |
|
||||||
| `artwork` | 艺术品建档、图片、动态字段、状态管理 |
|
| `artwork` | 艺术品档案/款式、图片、动态字段、状态管理 |
|
||||||
| `trace-node` | 溯源时间轴节点维护 |
|
| `trace-node` | 溯源时间轴节点维护 |
|
||||||
| `certificate` | 认证文件管理(原件 + 水印图) |
|
| `certificate` | 认证文件管理(原件 + 水印图) |
|
||||||
| `trace-code` | 批量生码、短码与二维码生成、导出 |
|
| `trace-code` | 批量生码、短码与二维码生成、导出 |
|
||||||
@@ -182,7 +182,7 @@ flowchart LR
|
|||||||
|
|
||||||
### 5.2 数据模型关系(ER 图)
|
### 5.2 数据模型关系(ER 图)
|
||||||
|
|
||||||
> 模型核心假设:`artwork` 表示一件可独立溯源的艺术品档案,与 `trace_code` 一对一“一物一码”;同一作品款的多件实物各为一条 `artwork` + 一个 `trace_code`,共享描述通过模板与录入复用。出库与上链信息按件记录。该模型简单且贴合“一物一码”,若未来需区分“款/SKU 与实物”可再做二级扩展。
|
> 模型核心假设:`artwork` 表示一款/一类艺术品档案,承载可复用的基础信息、图片、溯源节点与认证文件;`batch` 表示该档案下的一次生产/生码批次;`trace_code` 表示每套实物的唯一追溯码。系统仍满足“一物一码”,但“一物”落在 `trace_code` 对应的实物层,而不是 `artwork` 档案层。出库、激活、查询次数与上链信息均按 `trace_code` 独立记录。
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
erDiagram
|
erDiagram
|
||||||
@@ -191,7 +191,8 @@ erDiagram
|
|||||||
TEMPLATE ||--o{ ARTWORK : "套用"
|
TEMPLATE ||--o{ ARTWORK : "套用"
|
||||||
ARTWORK ||--o{ TRACE_NODE : "拥有"
|
ARTWORK ||--o{ TRACE_NODE : "拥有"
|
||||||
ARTWORK ||--o{ CERTIFICATE : "拥有"
|
ARTWORK ||--o{ CERTIFICATE : "拥有"
|
||||||
ARTWORK ||--|| TRACE_CODE : "绑定"
|
ARTWORK ||--o{ BATCH : "拥有批次"
|
||||||
|
ARTWORK ||--o{ TRACE_CODE : "生成实物码"
|
||||||
BATCH ||--o{ TRACE_CODE : "生成"
|
BATCH ||--o{ TRACE_CODE : "生成"
|
||||||
TRACE_CODE ||--o{ BLOCKCHAIN_PROOF : "存证"
|
TRACE_CODE ||--o{ BLOCKCHAIN_PROOF : "存证"
|
||||||
TRACE_CODE ||--o{ QUERY_LOG : "产生"
|
TRACE_CODE ||--o{ QUERY_LOG : "产生"
|
||||||
@@ -225,6 +226,7 @@ erDiagram
|
|||||||
int template_id FK
|
int template_id FK
|
||||||
string title
|
string title
|
||||||
string artist
|
string artist
|
||||||
|
string archive_no UK
|
||||||
json dynamic_fields
|
json dynamic_fields
|
||||||
json images
|
json images
|
||||||
enum status
|
enum status
|
||||||
@@ -256,6 +258,7 @@ erDiagram
|
|||||||
BATCH {
|
BATCH {
|
||||||
int id PK
|
int id PK
|
||||||
string batch_no UK
|
string batch_no UK
|
||||||
|
int artwork_id FK
|
||||||
int quantity
|
int quantity
|
||||||
int generated_count
|
int generated_count
|
||||||
enum status
|
enum status
|
||||||
@@ -267,8 +270,7 @@ erDiagram
|
|||||||
string short_code UK
|
string short_code UK
|
||||||
int artwork_id FK
|
int artwork_id FK
|
||||||
int batch_id FK
|
int batch_id FK
|
||||||
string sku
|
int group_id FK
|
||||||
string archive_no
|
|
||||||
datetime out_time
|
datetime out_time
|
||||||
string out_image
|
string out_image
|
||||||
enum status
|
enum status
|
||||||
@@ -294,10 +296,13 @@ erDiagram
|
|||||||
bigint id PK
|
bigint id PK
|
||||||
bigint trace_code_id FK
|
bigint trace_code_id FK
|
||||||
int artwork_id
|
int artwork_id
|
||||||
|
string short_code
|
||||||
|
string code
|
||||||
|
string archive_no
|
||||||
|
string batch_no
|
||||||
datetime queried_at
|
datetime queried_at
|
||||||
enum query_result
|
enum query_result
|
||||||
string ip
|
string ip
|
||||||
string region
|
|
||||||
string user_agent
|
string user_agent
|
||||||
string device_type
|
string device_type
|
||||||
}
|
}
|
||||||
@@ -309,7 +314,7 @@ erDiagram
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `sys_user` | 后台用户与角色 | 小 |
|
| `sys_user` | 后台用户与角色 | 小 |
|
||||||
| `template` / `template_field` | 溯源模板与动态字段定义 | 小 |
|
| `template` / `template_field` | 溯源模板与动态字段定义 | 小 |
|
||||||
| `artwork` | 艺术品档案(作品级共享信息) | 中 |
|
| `artwork` | 艺术品档案/款式(共享信息与档案编号) | 中 |
|
||||||
| `trace_node` | 溯源时间轴节点 | 中 |
|
| `trace_node` | 溯源时间轴节点 | 中 |
|
||||||
| `certificate` | 认证文件(原件 + 水印图) | 中 |
|
| `certificate` | 认证文件(原件 + 水印图) | 中 |
|
||||||
| `batch` | 生码批次 | 小 |
|
| `batch` | 生码批次 | 小 |
|
||||||
@@ -323,7 +328,7 @@ erDiagram
|
|||||||
```text
|
```text
|
||||||
RoleType = SUPER_ADMIN | OPERATOR | AUDITOR | VIEWER
|
RoleType = SUPER_ADMIN | OPERATOR | AUDITOR | VIEWER
|
||||||
ArtworkStatus = DRAFT | ACTIVE | DISABLED
|
ArtworkStatus = DRAFT | ACTIVE | DISABLED
|
||||||
TraceCodeStatus = UNBOUND | INACTIVE | ACTIVE | DISABLED | ABNORMAL
|
TraceCodeStatus = INACTIVE | ACTIVE | DISABLED | ABNORMAL
|
||||||
NodeType = CREATE | PRODUCE | STORAGE | OUTBOUND | OTHER
|
NodeType = CREATE | PRODUCE | STORAGE | OUTBOUND | OTHER
|
||||||
FieldType = TEXT | NUMBER | DATE | IMAGE | FILE | LINK | TEXTAREA
|
FieldType = TEXT | NUMBER | DATE | IMAGE | FILE | LINK | TEXTAREA
|
||||||
CertType = PHOTO | CERT | APPRAISAL
|
CertType = PHOTO | CERT | APPRAISAL
|
||||||
@@ -340,21 +345,27 @@ model TraceCode {
|
|||||||
id BigInt @id @default(autoincrement())
|
id BigInt @id @default(autoincrement())
|
||||||
code String @unique
|
code String @unique
|
||||||
shortCode String @unique @map("short_code")
|
shortCode String @unique @map("short_code")
|
||||||
artworkId Int? @map("artwork_id")
|
artworkId Int @map("artwork_id")
|
||||||
batchId Int? @map("batch_id")
|
batchId Int @map("batch_id")
|
||||||
sku String?
|
groupId Int? @map("group_id")
|
||||||
archiveNo String? @map("archive_no")
|
outTime DateTime? @map("out_time")
|
||||||
status TraceCodeStatus @default(UNBOUND)
|
outImage String? @map("out_image")
|
||||||
|
status TraceCodeStatus @default(INACTIVE)
|
||||||
queryCount Int @default(0) @map("query_count")
|
queryCount Int @default(0) @map("query_count")
|
||||||
firstActivatedAt DateTime? @map("first_activated_at")
|
firstActivatedAt DateTime? @map("first_activated_at")
|
||||||
|
lastQueriedAt DateTime? @map("last_queried_at")
|
||||||
url String?
|
url String?
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
|
|
||||||
artwork Artwork? @relation(fields: [artworkId], references: [id])
|
artwork Artwork @relation(fields: [artworkId], references: [id])
|
||||||
|
batch Batch @relation(fields: [batchId], references: [id])
|
||||||
|
group TraceCodeGroup? @relation(fields: [groupId], references: [id])
|
||||||
proofs BlockchainProof[]
|
proofs BlockchainProof[]
|
||||||
queryLogs QueryLog[]
|
queryLogs QueryLog[]
|
||||||
|
|
||||||
@@index([artworkId])
|
@@index([artworkId])
|
||||||
|
@@index([batchId])
|
||||||
|
@@index([groupId])
|
||||||
@@index([status])
|
@@index([status])
|
||||||
@@map("trace_code")
|
@@map("trace_code")
|
||||||
}
|
}
|
||||||
@@ -509,7 +520,7 @@ sequenceDiagram
|
|||||||
## 8. 关键技术实现要点
|
## 8. 关键技术实现要点
|
||||||
|
|
||||||
- **短链生成与防枚举**:短码用 `nanoid` 生成 8–10 位 Base62 随机串,唯一约束去重;`short_code → trace_code → artwork` 映射写入 Redis 加速解析;短码不含业务信息,配合频率限制防枚举。
|
- **短链生成与防枚举**:短码用 `nanoid` 生成 8–10 位 Base62 随机串,唯一约束去重;`short_code → trace_code → artwork` 映射写入 Redis 加速解析;短码不含业务信息,配合频率限制防枚举。
|
||||||
- **防伪激活与计数并发安全**:激活与计数在数据库事务中完成,状态由 `UNBOUND/INACTIVE` 流转到 `ACTIVE`;高频计数用 Redis 原子自增并定期回写,避免行锁热点。
|
- **防伪激活与计数并发安全**:激活与计数在数据库事务中完成,状态由 `INACTIVE` 流转到 `ACTIVE`;高频计数用 Redis 原子自增并定期回写,避免行锁热点。
|
||||||
- **动态字段**:模板定义字段(`template_field`),作品数据存 `artwork.dynamic_fields`(JSON),用户端按模板顺序渲染、空值不展示。
|
- **动态字段**:模板定义字段(`template_field`),作品数据存 `artwork.dynamic_fields`(JSON),用户端按模板顺序渲染、空值不展示。
|
||||||
- **文件存储抽象**:定义 `StorageService` 接口(`put/get/getUrl/remove`),第一版实现本地磁盘 + Nginx;后续新增 OSS/COS/MinIO 适配,业务零改动。
|
- **文件存储抽象**:定义 `StorageService` 接口(`put/get/getUrl/remove`),第一版实现本地磁盘 + Nginx;后续新增 OSS/COS/MinIO 适配,业务零改动。
|
||||||
- **证书水印**:上传原件存后台,Worker 用 `sharp` 叠加水印(平台/机构名或“仅供溯源核验使用”)生成展示版;用户端仅取水印版,原件受控访问。
|
- **证书水印**:上传原件存后台,Worker 用 `sharp` 叠加水印(平台/机构名或“仅供溯源核验使用”)生成展示版;用户端仅取水印版,原件受控访问。
|
||||||
|
|||||||
Reference in New Issue
Block a user