fix: 修复出库追溯码默认加载
This commit is contained in:
@@ -91,6 +91,7 @@
|
||||
- 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` 是单件实物的一物一码载体。
|
||||
- 后台交互拆分(2026-07-03):艺术品档案列表操作列拆为两个图标入口:编辑详情(进入 `/artworks/:id`,只维护基础信息、图片、溯源节点、认证文件)和数据管理(进入 `/artworks/:id/trace-codes`,专门管理该档案下的批次与追溯码)。`ArtworkEdit.vue` 不再内嵌追溯码表,新增 `ArtworkTraceCodes.vue` 复用 `TraceCodePanel` 并展示档案编号、追溯码数、已激活数、查询总数摘要;侧边栏仍只高亮“艺术品档案”。
|
||||
- 出库单条录入修复(2026-07-03):`Outbound.vue` 的远程追溯码下拉原先只在用户输入时触发搜索,页面初次打开 options 为空,导致默认显示“无数据”;现改为 mounted 后主动加载最近 20 条追溯码,输入时继续远程检索,并用请求序号避免旧搜索覆盖新结果。选择追溯码会回填出库时间、备注、出库实况图、最近 ONCHAIN 存证哈希/时间/区块高度;清空选择会清空表单,清空出库时间/图片/备注后保存可真正写回 null。`TraceCodeService.list` 额外返回 `outImageUrl` 与 `latestProof`,供后台出库页回显使用。
|
||||
|
||||
## 当前代码基准与注意事项
|
||||
|
||||
|
||||
@@ -93,10 +93,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue';
|
||||
import { onBeforeUnmount, onMounted, reactive, 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 { useAuthStore } from '@/stores/auth';
|
||||
import MediaUpload from '@/components/MediaUpload.vue';
|
||||
@@ -110,7 +111,7 @@ const auth = useAuthStore();
|
||||
/* 单条录入 */
|
||||
const saving = ref(false);
|
||||
const searching = ref(false);
|
||||
const codeOptions = ref<{ label: string; value: string }[]>([]);
|
||||
const codeOptions = ref<{ label: string; value: string; raw: any }[]>([]);
|
||||
const outImages = ref<any[]>([]);
|
||||
const form = reactive<any>({
|
||||
traceCodeId: null,
|
||||
@@ -122,39 +123,88 @@ const form = reactive<any>({
|
||||
});
|
||||
|
||||
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(async () => {
|
||||
searching.value = true;
|
||||
try {
|
||||
const res: any = await traceCodeApi.list({ keyword: keyword || undefined, pageSize: 20 });
|
||||
codeOptions.value = res.list.map((c: any) => ({
|
||||
label: `${c.shortCode}${c.artwork ? ' · ' + (c.artwork.archiveNo || c.artwork.title) : ''}`,
|
||||
value: String(c.id),
|
||||
raw: c,
|
||||
}));
|
||||
} finally {
|
||||
searching.value = false;
|
||||
}
|
||||
}, 300);
|
||||
searchTimer = setTimeout(() => loadCodeOptions(keyword), 300);
|
||||
}
|
||||
function onPickCode(_id: string, opt: any) {
|
||||
|
||||
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 || '';
|
||||
outImages.value = c.outImage ? [{ key: c.outImage, url: c.outImage, name: c.outImage }] : [];
|
||||
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 ? new Date(form.outTime).toISOString() : undefined,
|
||||
outImageKey: outImages.value[0]?.key || undefined,
|
||||
outTime: form.outTime ? dayjs(form.outTime).toISOString() : null,
|
||||
outImageKey: outImages.value[0]?.key ?? null,
|
||||
txHash: form.txHash || undefined,
|
||||
onchainAt: form.onchainAt ? new Date(form.onchainAt).toISOString() : undefined,
|
||||
onchainAt: form.onchainAt ? dayjs(form.onchainAt).toISOString() : undefined,
|
||||
blockHeight: form.blockHeight ?? undefined,
|
||||
remark: form.remark || undefined,
|
||||
remark: form.remark || null,
|
||||
});
|
||||
message.success(t('common.msg.saved'));
|
||||
} finally {
|
||||
@@ -193,4 +243,12 @@ async function doImport({ file, onFinish, onError }: UploadCustomRequestOptions)
|
||||
importing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadCodeOptions();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (searchTimer) clearTimeout(searchTimer);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -6,12 +6,12 @@ export class OutboundDto {
|
||||
@ApiPropertyOptional({ description: '出库时间' })
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
outTime?: string;
|
||||
outTime?: string | null;
|
||||
|
||||
@ApiPropertyOptional({ description: '出库实况图存储 key' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
outImageKey?: string;
|
||||
outImageKey?: string | null;
|
||||
|
||||
@ApiPropertyOptional({ description: '上链哈希值(填写则记录上链结果)' })
|
||||
@IsOptional()
|
||||
@@ -35,5 +35,5 @@ export class OutboundDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(255)
|
||||
remark?: string;
|
||||
remark?: string | null;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Queue } from 'bullmq';
|
||||
import { Response } from 'express';
|
||||
import { createHash } from 'crypto';
|
||||
import * as ExcelJS from 'exceljs';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import {
|
||||
ErrorCode,
|
||||
JobType,
|
||||
@@ -35,13 +36,13 @@ export class OutboundService {
|
||||
async updateSingle(traceCodeId: bigint, dto: OutboundDto) {
|
||||
const code = await this.prisma.traceCode.findUnique({ where: { id: traceCodeId } });
|
||||
if (!code) throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '追溯码不存在', 404);
|
||||
const data: Prisma.TraceCodeUpdateInput = {};
|
||||
if ('outTime' in dto) data.outTime = dto.outTime ? new Date(dto.outTime) : null;
|
||||
if ('outImageKey' in dto) data.outImage = dto.outImageKey || null;
|
||||
if ('remark' in dto) data.remark = dto.remark || null;
|
||||
const updated = await this.prisma.traceCode.update({
|
||||
where: { id: traceCodeId },
|
||||
data: {
|
||||
outTime: dto.outTime ? new Date(dto.outTime) : undefined,
|
||||
outImage: dto.outImageKey,
|
||||
remark: dto.remark,
|
||||
},
|
||||
data,
|
||||
});
|
||||
// 录入了上链哈希则记录一条已上链存证(手工登记,不触发 Mock 链)
|
||||
if (dto.txHash) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import * as QRCode from 'qrcode';
|
||||
import dayjs from 'dayjs';
|
||||
import { ArtworkStatus, ErrorCode, JobType, QUEUE_NAMES, TraceCodeStatus } from '@artveris/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { StorageService } from '../storage/storage.service';
|
||||
import { BusinessException } from '../common/exceptions/business.exception';
|
||||
import { buildPage } from '../common/utils/pagination.util';
|
||||
import { JobsService } from '../jobs/jobs.service';
|
||||
@@ -28,6 +29,7 @@ export class TraceCodeService {
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly jobs: JobsService,
|
||||
private readonly config: ConfigService,
|
||||
private readonly storage: StorageService,
|
||||
@InjectQueue(QUEUE_NAMES.GEN_CODE) private readonly genQueue: Queue,
|
||||
) {}
|
||||
|
||||
@@ -173,6 +175,11 @@ export class TraceCodeService {
|
||||
artwork: { select: { id: true, title: true, archiveNo: true } },
|
||||
batch: { select: { id: true, batchNo: true } },
|
||||
group: { select: { id: true, name: true } },
|
||||
proofs: {
|
||||
where: { status: 'ONCHAIN' },
|
||||
orderBy: [{ onchainAt: 'desc' }, { id: 'desc' }],
|
||||
take: 1,
|
||||
},
|
||||
},
|
||||
orderBy: { id: 'desc' },
|
||||
skip: query.skip,
|
||||
@@ -180,7 +187,19 @@ export class TraceCodeService {
|
||||
}),
|
||||
this.prisma.traceCode.count({ where }),
|
||||
]);
|
||||
return buildPage(list, total, query.page, query.pageSize);
|
||||
return buildPage(
|
||||
list.map((code) => {
|
||||
const { proofs, ...rest } = code;
|
||||
return {
|
||||
...rest,
|
||||
outImageUrl: code.outImage ? this.storage.getUrl(code.outImage) : null,
|
||||
latestProof: proofs[0] ?? null,
|
||||
};
|
||||
}),
|
||||
total,
|
||||
query.page,
|
||||
query.pageSize,
|
||||
);
|
||||
}
|
||||
|
||||
async getQrPng(id: bigint): Promise<Buffer> {
|
||||
|
||||
Reference in New Issue
Block a user