feat: 支持控制出库时间轴显示

This commit is contained in:
Nixevol
2026-07-16 16:57:18 +08:00
parent 4afd89ef12
commit 818884d632
12 changed files with 180 additions and 25 deletions
+1
View File
@@ -327,6 +327,7 @@
"basicInfo": "Basic Info",
"dynamicFields": "Fields",
"nodes": "Timeline",
"showOutboundTimeline": "Show outbound record on client",
"certificates": "Certificates",
"saveDraft": "Save Draft",
"saveChanges": "Save Changes",
+1
View File
@@ -327,6 +327,7 @@
"basicInfo": "基础信息",
"dynamicFields": "动态字段",
"nodes": "溯源时间轴",
"showOutboundTimeline": "客户端显示本件出库记录",
"certificates": "认证文件",
"saveDraft": "保存草稿",
"saveChanges": "保存修改",
+22 -5
View File
@@ -153,10 +153,15 @@
<n-grid-item>
<n-card :title="t('pages.artwork.nodes')" :bordered="false">
<template #header-extra>
<n-button v-if="auth.canWrite" size="small" type="primary" @click="openNode()">
<template #icon><n-icon :component="AddOutline" /></template>
{{ t('pages.artwork.addNode') }}
</n-button>
<n-space align="center">
<n-checkbox v-model:checked="form.showOutboundTimeline" :disabled="!auth.canWrite">
{{ t('pages.artwork.showOutboundTimeline') }}
</n-checkbox>
<n-button v-if="auth.canWrite" size="small" type="primary" @click="openNode()">
<template #icon><n-icon :component="AddOutline" /></template>
{{ t('pages.artwork.addNode') }}
</n-button>
</n-space>
</template>
<n-empty v-if="!nodes.length" :description="t('common.msg.noData')" />
<n-timeline v-else>
@@ -352,7 +357,15 @@ const isNew = computed(() => route.params.id === 'new');
const artworkId = computed(() => Number(route.params.id));
const formRef = ref<FormInst | null>(null);
const form = reactive<any>({ templateId: null, title: '', artist: '', status: ArtworkStatus.DRAFT, dynamicFields: {}, images: [] });
const form = reactive<any>({
templateId: null,
title: '',
artist: '',
status: ArtworkStatus.DRAFT,
dynamicFields: {},
images: [],
showOutboundTimeline: false,
});
const submitReviewForm = reactive({ title: '', reason: '' });
const submitReviewModal = ref(false);
const rules: FormRules = {
@@ -478,6 +491,7 @@ function applyArtworkToForm(a: any) {
form.title = a.title;
form.artist = a.artist;
form.status = a.status;
form.showOutboundTimeline = a.showOutboundTimeline === true;
form.dynamicFields = a.dynamicFields || {};
form.images = (a.images || []).map((m: any) => ({
...m,
@@ -492,6 +506,7 @@ function applySnapshotToForm(snapshot: any) {
title: snapshot.artwork.title,
artist: snapshot.artwork.artist,
status: snapshot.artwork.status,
showOutboundTimeline: snapshot.artwork.showOutboundTimeline ?? false,
dynamicFields: snapshot.artwork.dynamicFields,
images: snapshot.artwork.images,
});
@@ -577,6 +592,7 @@ async function saveArtwork(asDraft: boolean) {
templateId: form.templateId,
title: form.title,
artist: form.artist,
showOutboundTimeline: form.showOutboundTimeline === true,
status: asDraft ? ArtworkStatus.DRAFT : isNew.value || form.status === ArtworkStatus.DRAFT ? ArtworkStatus.ACTIVE : form.status,
dynamicFields: form.dynamicFields,
images: form.images.map((m: any) => ({
@@ -614,6 +630,7 @@ function buildComparableSnapshot() {
title: form.title || '',
artist: form.artist || '',
status: form.status,
showOutboundTimeline: form.showOutboundTimeline === true,
dynamicFields: normalizeJson(form.dynamicFields || {}),
images: normalizeMedia(form.images),
},
@@ -0,0 +1,2 @@
ALTER TABLE `artwork`
ADD COLUMN `show_outbound_timeline` BOOLEAN NOT NULL DEFAULT false;
+17 -16
View File
@@ -214,22 +214,23 @@ model TemplateField {
}
model Artwork {
id Int @id @default(autoincrement())
templateId Int @map("template_id")
title String
artist String?
archiveNo String? @unique @map("archive_no")
dynamicFields Json? @map("dynamic_fields")
images Json?
status ArtworkStatus @default(DRAFT)
auditStatus AuditStatus @default(PENDING) @map("audit_status")
auditRemark String? @map("audit_remark")
auditedBy Int? @map("audited_by")
auditedAt DateTime? @map("audited_at")
createdBy Int? @map("created_by")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
id Int @id @default(autoincrement())
templateId Int @map("template_id")
title String
artist String?
archiveNo String? @unique @map("archive_no")
dynamicFields Json? @map("dynamic_fields")
images Json?
showOutboundTimeline Boolean @default(false) @map("show_outbound_timeline")
status ArtworkStatus @default(DRAFT)
auditStatus AuditStatus @default(PENDING) @map("audit_status")
auditRemark String? @map("audit_remark")
auditedBy Int? @map("audited_by")
auditedAt DateTime? @map("audited_at")
createdBy Int? @map("created_by")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
template Template @relation(fields: [templateId], references: [id])
creator SysUser? @relation(fields: [createdBy], references: [id])
@@ -21,6 +21,7 @@ function createHarness() {
auditStatus: data.auditStatus,
dynamicFields: data.dynamicFields,
images: data.images,
showOutboundTimeline: data.showOutboundTimeline,
traceNodes: [],
certificates: [],
})),
@@ -107,6 +108,20 @@ describe('ArtworkService.create approval policy', () => {
});
});
it('defaults outbound timeline visibility to false in the record and revision snapshot', async () => {
const { service, tx } = createHarness();
await service.create(
{ templateId: 1, title: 'default timeline visibility', status: ArtworkStatus.ACTIVE } as any,
user(RoleType.SUPER_ADMIN),
);
expect(tx.artwork.create.mock.calls[0][0].data.showOutboundTimeline).toBe(false);
expect(
tx.artworkRevision.create.mock.calls[0][0].data.afterSnapshot.artwork.showOutboundTimeline,
).toBe(false);
});
function updateHarness() {
const current = {
artwork: {
@@ -149,6 +164,38 @@ function updateHarness() {
}
describe('ArtworkService.update approval policy', () => {
it('applies a super-admin outbound timeline visibility change immediately', async () => {
const { service, tx, applySnapshot } = updateHarness();
await service.update(7, { showOutboundTimeline: true } as any, user(RoleType.SUPER_ADMIN));
expect(
tx.artworkRevision.create.mock.calls[0][0].data.afterSnapshot.artwork.showOutboundTimeline,
).toBe(true);
expect(applySnapshot).toHaveBeenCalledWith(
tx,
7,
expect.objectContaining({
artwork: expect.objectContaining({ showOutboundTimeline: true }),
}),
expect.objectContaining({ auditStatus: AuditStatus.APPROVED, auditedBy: 9 }),
);
});
it('keeps an operator outbound timeline visibility change in the pending snapshot', async () => {
const { service, tx, applySnapshot } = updateHarness();
await service.update(7, { showOutboundTimeline: true } as any, user(RoleType.OPERATOR));
expect(
tx.artworkRevision.create.mock.calls[0][0].data.afterSnapshot.artwork.showOutboundTimeline,
).toBe(true);
expect(tx.artworkRevision.create.mock.calls[0][0].data.status).toBe(
ArtworkRevisionStatus.PENDING,
);
expect(applySnapshot).not.toHaveBeenCalled();
});
it('applies a super-admin revision immediately and records who superseded the pending revision', async () => {
const { service, tx, applySnapshot, enqueueWatermarks } = updateHarness();
+7
View File
@@ -55,6 +55,7 @@ interface ArtworkSnapshot {
status: ArtworkStatus;
dynamicFields: Record<string, unknown>;
images: MediaItem[];
showOutboundTimeline: boolean;
};
traceNodes: TraceNodeSnapshot[];
certificates: CertificateSnapshot[];
@@ -187,6 +188,7 @@ export class ArtworkService {
auditedAt: reviewedAt,
dynamicFields: (dto.dynamicFields ?? {}) as Prisma.InputJsonValue,
images: (dto.images ?? []) as unknown as Prisma.InputJsonValue,
showOutboundTimeline: dto.showOutboundTimeline ?? false,
createdBy: userId,
traceNodes: traceNodes.length
? {
@@ -435,6 +437,7 @@ export class ArtworkService {
status: nextStatus,
dynamicFields: dto.dynamicFields ?? current.artwork.dynamicFields,
images: (dtoImages ?? current.artwork.images) as MediaItem[],
showOutboundTimeline: dto.showOutboundTimeline ?? current.artwork.showOutboundTimeline ?? false,
},
traceNodes: dtoNodes ?? current.traceNodes,
certificates: dtoCerts ?? current.certificates,
@@ -645,6 +648,7 @@ export class ArtworkService {
status: string;
dynamicFields: Prisma.JsonValue | null;
images: Prisma.JsonValue | null;
showOutboundTimeline?: boolean;
traceNodes: Array<{
nodeType: string;
title: string;
@@ -671,6 +675,7 @@ export class ArtworkService {
status: record.status as ArtworkStatus,
dynamicFields: (record.dynamicFields as Record<string, unknown>) ?? {},
images: (Array.isArray(record.images) ? record.images : []) as unknown as MediaItem[],
showOutboundTimeline: record.showOutboundTimeline ?? false,
},
traceNodes: record.traceNodes
.sort((a, b) => a.sortOrder - b.sortOrder)
@@ -713,6 +718,7 @@ export class ArtworkService {
status: snapshot.artwork.status,
dynamicFields: this.normalizeJson(snapshot.artwork.dynamicFields ?? {}),
images: this.normalizeMedia(snapshot.artwork.images),
showOutboundTimeline: snapshot.artwork.showOutboundTimeline ?? false,
},
traceNodes: snapshot.traceNodes.map((node, index) => ({
nodeType: node.nodeType,
@@ -812,6 +818,7 @@ export class ArtworkService {
status: snapshot.artwork.status,
dynamicFields: snapshot.artwork.dynamicFields as Prisma.InputJsonObject,
images: snapshot.artwork.images as unknown as Prisma.InputJsonValue,
showOutboundTimeline: snapshot.artwork.showOutboundTimeline ?? false,
...auditData,
},
});
+10
View File
@@ -34,6 +34,11 @@ export class MediaItemDto {
}
export class CreateArtworkDto {
@ApiPropertyOptional({ description: '是否在客户端时间轴显示本件出库记录', default: false })
@IsOptional()
@IsBoolean()
showOutboundTimeline?: boolean;
@ApiProperty({ description: '模板 ID' })
@Type(() => Number)
@IsInt()
@@ -158,6 +163,11 @@ export class CreateArtworkCertificateDto {
}
export class UpdateArtworkDto {
@ApiPropertyOptional({ description: '是否在客户端时间轴显示本件出库记录' })
@IsOptional()
@IsBoolean()
showOutboundTimeline?: boolean;
@ApiPropertyOptional({ description: '作品名称' })
@IsOptional()
@IsString()
@@ -1,7 +1,30 @@
import { ArtworkStatus, AuditStatus, TraceCodeStatus } from '@artveris/shared';
import { PublicTraceService } from './public-trace.service';
function createHarness() {
function createHarness(options: {
artworkStatus?: ArtworkStatus;
showOutboundTimeline?: boolean;
withOutbound?: boolean;
} = {}) {
const outbound = options.withOutbound
? {
outTime: new Date('2026-07-16T08:00:00.000Z'),
remark: 'outbound note',
images: [
{
id: 1n,
fileKey: 'outbound/1.jpg',
fileName: '1.jpg',
mimeType: 'image/jpeg',
size: 1024n,
width: 800,
height: 600,
sortOrder: 0,
},
],
_count: { images: 1 },
}
: null;
const code = {
id: 1n,
shortCode: '482731000001',
@@ -18,14 +41,16 @@ function createHarness() {
auditStatus: AuditStatus.APPROVED,
deletedAt: null,
},
outbound: null,
outbound,
};
const artwork = {
...code.artwork,
status: options.artworkStatus ?? ArtworkStatus.DRAFT,
title: '草稿作品',
artist: null,
images: [],
dynamicFields: null,
showOutboundTimeline: options.showOutboundTimeline ?? false,
template: { fields: [] },
traceNodes: [],
certificates: [],
@@ -76,3 +101,32 @@ describe('PublicTraceService draft visibility', () => {
expect(prisma.outboundImage.findMany).not.toHaveBeenCalled();
});
});
describe('PublicTraceService outbound timeline visibility', () => {
it.each([
{ showOutboundTimeline: false, expectedSystemNodes: 0 },
{ showOutboundTimeline: true, expectedSystemNodes: 1 },
])(
'keeps outbound data while producing $expectedSystemNodes system timeline node(s)',
async ({ showOutboundTimeline, expectedSystemNodes }) => {
const { service } = createHarness({
artworkStatus: ArtworkStatus.ACTIVE,
showOutboundTimeline,
withOutbound: true,
});
const result = await service.preview('482731000001', 'inactive');
expect(result.status).toBe('OK');
expect((result as any).outbound).toEqual(
expect.objectContaining({
outTime: new Date('2026-07-16T08:00:00.000Z'),
remark: 'outbound note',
}),
);
expect(
(result as any).timeline.filter((node: { system: string | null }) => node.system === 'OUTBOUND_RECORD'),
).toHaveLength(expectedSystemNodes);
},
);
});
@@ -58,6 +58,7 @@ export class PublicTraceService {
outTime: Date;
images: Array<{ fileKey: string; fileName: string; mimeType: string; id: bigint; size: bigint; width: number; height: number; sortOrder: number }>;
} | null,
showOutboundTimeline: boolean,
) {
const timeline = nodes.map((n) => ({
nodeType: n.nodeType,
@@ -71,7 +72,7 @@ export class PublicTraceService {
const outMedia = outbound?.images.map((image) => this.mapOutboundImage(image)) ?? [];
if (outbound) {
if (showOutboundTimeline && outbound) {
// 单件出库记录:不下发中文标题/说明,标记 system=OUTBOUND_RECORD 由 C 端按语言本地化
timeline.push({
nodeType: 'OUTBOUND',
@@ -319,9 +320,14 @@ export class PublicTraceService {
artist: artwork.artist,
archiveNo: artwork.archiveNo,
images: this.mapMedia(artwork.images),
showOutboundTimeline: artwork.showOutboundTimeline,
fields: this.buildFields(artwork.template.fields, artwork.dynamicFields),
},
timeline: this.buildTimeline(artwork.traceNodes, code.outbound ?? null),
timeline: this.buildTimeline(
artwork.traceNodes,
code.outbound ?? null,
artwork.showOutboundTimeline === true,
),
outbound: code.outbound
? {
outTime: code.outbound.outTime,
+2
View File
@@ -499,6 +499,8 @@ function resetOutboundImages(value: any) {
const timelineItems = computed<any[]>(() => {
const source = Array.isArray(data.value?.timeline) ? data.value.timeline : [];
const regularNodes = source.filter((node: any) => node?.system !== 'OUTBOUND_RECORD');
if (data.value?.artwork?.showOutboundTimeline !== true) return regularNodes;
const legacyOutbound = source.find((node: any) => node?.system === 'OUTBOUND_RECORD');
const outbound = data.value?.outbound;