feat: 优化建档草稿和审核详情入口
This commit is contained in:
@@ -251,8 +251,7 @@
|
||||
"dynamicFields": "Fields",
|
||||
"nodes": "Timeline",
|
||||
"certificates": "Certificates",
|
||||
"saveBeforeNodes": "Save basic info before editing the timeline",
|
||||
"saveBeforeCertificates": "Save basic info before uploading certificates",
|
||||
"saveDraft": "Save Draft",
|
||||
"traceCode": "Trace Code",
|
||||
"status": "Status",
|
||||
"create": "New Artwork",
|
||||
|
||||
@@ -251,8 +251,7 @@
|
||||
"dynamicFields": "动态字段",
|
||||
"nodes": "溯源时间轴",
|
||||
"certificates": "认证文件",
|
||||
"saveBeforeNodes": "保存基础信息后可维护溯源时间轴",
|
||||
"saveBeforeCertificates": "保存基础信息后可上传认证文件",
|
||||
"saveDraft": "保存草稿",
|
||||
"traceCode": "追溯码",
|
||||
"status": "状态",
|
||||
"create": "新建作品",
|
||||
|
||||
@@ -6,6 +6,15 @@
|
||||
{{ t('common.action.back') }}
|
||||
</n-button>
|
||||
<div class="page-title">{{ isNew ? t('pages.artwork.create') : t('pages.artwork.detail') }}</div>
|
||||
<div class="spacer" />
|
||||
<div class="edit-actions">
|
||||
<n-button :loading="saving" :disabled="!auth.canWrite" @click="saveArtwork(true)">
|
||||
{{ t('pages.artwork.saveDraft') }}
|
||||
</n-button>
|
||||
<n-button type="primary" :loading="saving" :disabled="!auth.canWrite" @click="saveArtwork(false)">
|
||||
{{ t('common.action.save') }}
|
||||
</n-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<n-grid :cols="1" :y-gap="16">
|
||||
@@ -107,29 +116,21 @@
|
||||
<n-divider style="margin: 4px 0 16px">{{ t('pages.artwork.images') }}</n-divider>
|
||||
<media-sorter v-model="form.images" :max="12" />
|
||||
</n-form>
|
||||
<div style="text-align: right; margin-top: 16px">
|
||||
<n-button type="primary" :loading="saving" :disabled="!auth.canWrite" @click="saveBasic">
|
||||
{{ t('common.action.save') }}
|
||||
</n-button>
|
||||
</div>
|
||||
</n-card>
|
||||
</n-grid-item>
|
||||
|
||||
<!-- 溯源时间轴 -->
|
||||
<n-grid-item>
|
||||
<n-card :title="t('pages.artwork.nodes')" :bordered="false">
|
||||
<template v-if="!isNew" #header-extra>
|
||||
<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>
|
||||
</template>
|
||||
<n-empty v-if="isNew" class="locked-section" :description="t('pages.artwork.saveBeforeNodes')">
|
||||
<template #icon><n-icon :component="LockClosedOutline" /></template>
|
||||
</n-empty>
|
||||
<n-empty v-else-if="!nodes.length" :description="t('common.msg.noData')" />
|
||||
<n-empty v-if="!nodes.length" :description="t('common.msg.noData')" />
|
||||
<n-timeline v-else>
|
||||
<n-timeline-item v-for="n in nodes" :key="n.id" type="info" :title="n.title">
|
||||
<n-timeline-item v-for="n in nodes" :key="n.id ?? n.localId" type="info" :title="n.title">
|
||||
<template #header>
|
||||
<div class="node-head">
|
||||
<span>{{ t(`common.nodeType.${n.nodeType}`) }} · {{ n.title }}</span>
|
||||
@@ -142,7 +143,7 @@
|
||||
<div class="node-meta">{{ [fmtDate(n.occurredAt), n.location].filter(Boolean).join(' · ') }}</div>
|
||||
<div>{{ n.description }}</div>
|
||||
<div class="node-media">
|
||||
<template v-for="m in n.media" :key="m.url">
|
||||
<template v-for="m in n.media" :key="m.url || m.key">
|
||||
<video
|
||||
v-if="isVideoMedia(m)"
|
||||
:src="m.url"
|
||||
@@ -161,21 +162,18 @@
|
||||
<!-- 认证文件 -->
|
||||
<n-grid-item>
|
||||
<n-card :title="t('pages.artwork.certificates')" :bordered="false">
|
||||
<template v-if="!isNew" #header-extra>
|
||||
<template #header-extra>
|
||||
<n-button v-if="auth.canWrite" size="small" type="primary" @click="openCert()">
|
||||
<template #icon><n-icon :component="AddOutline" /></template>
|
||||
{{ t('pages.artwork.addCert') }}
|
||||
</n-button>
|
||||
</template>
|
||||
<n-empty v-if="isNew" class="locked-section" :description="t('pages.artwork.saveBeforeCertificates')">
|
||||
<template #icon><n-icon :component="LockClosedOutline" /></template>
|
||||
</n-empty>
|
||||
<n-empty v-else-if="!certs.length" :description="t('common.msg.noData')" />
|
||||
<n-empty v-if="!certs.length" :description="t('common.msg.noData')" />
|
||||
<n-grid v-else :cols="4" :x-gap="12" :y-gap="12" item-responsive responsive="screen">
|
||||
<n-grid-item v-for="c in certs" :key="c.id" span="2 m:1">
|
||||
<n-grid-item v-for="c in certs" :key="c.id ?? c.localId" span="2 m:1">
|
||||
<n-card size="small" :title="c.name">
|
||||
<template #cover>
|
||||
<n-image v-if="c.watermarkUrl" :src="c.watermarkUrl" object-fit="cover" style="height:140px;width:100%" />
|
||||
<n-image v-if="c.watermarkUrl || c.originUrl" :src="c.watermarkUrl || c.originUrl" object-fit="cover" style="height:140px;width:100%" />
|
||||
<div v-else class="cert-pending">{{ t('pages.artwork.watermarkPending') }}</div>
|
||||
</template>
|
||||
<div class="cert-meta">{{ c.issuer || '-' }}</div>
|
||||
@@ -251,11 +249,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, h, onMounted, reactive, ref } from 'vue';
|
||||
import { computed, onMounted, reactive, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { NTag, type FormInst, type FormRules } from 'naive-ui';
|
||||
import { ArrowBackOutline, AddOutline, LockClosedOutline } from '@vicons/ionicons5';
|
||||
import type { FormInst, FormRules } from 'naive-ui';
|
||||
import { ArrowBackOutline, AddOutline } from '@vicons/ionicons5';
|
||||
import { ArtworkStatus, CertType, NodeType } from '@artveris/shared';
|
||||
import { artworkApi, templateApi } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
@@ -291,6 +289,21 @@ const currentFields = computed(() => templates.value.find((x) => x.id === form.t
|
||||
const artwork = ref<any>(null);
|
||||
const nodes = ref<any[]>([]);
|
||||
const certs = ref<any[]>([]);
|
||||
let localIdSeed = 0;
|
||||
|
||||
function nextLocalId(prefix: string) {
|
||||
localIdSeed += 1;
|
||||
return `${prefix}-${Date.now()}-${localIdSeed}`;
|
||||
}
|
||||
|
||||
function defaultTraceNodes() {
|
||||
return [
|
||||
{ localId: nextLocalId('node'), nodeType: NodeType.CREATE, title: '创作 / 选胚', sortOrder: 0, media: [] },
|
||||
{ localId: nextLocalId('node'), nodeType: NodeType.PRODUCE, title: '制作过程', sortOrder: 1, media: [] },
|
||||
{ localId: nextLocalId('node'), nodeType: NodeType.STORAGE, title: '仓储 / 托管', sortOrder: 2, media: [] },
|
||||
{ localId: nextLocalId('node'), nodeType: NodeType.OUTBOUND, title: '出库 / 流转', sortOrder: 3, media: [] },
|
||||
];
|
||||
}
|
||||
|
||||
function onTemplateChange() {
|
||||
form.dynamicFields = {};
|
||||
@@ -320,11 +333,58 @@ async function loadArtwork() {
|
||||
...m,
|
||||
type: m.type || (isVideoMedia(m) ? 'video' : 'image'),
|
||||
}));
|
||||
nodes.value = a.traceNodes || [];
|
||||
certs.value = a.certificates || [];
|
||||
nodes.value = (a.traceNodes || []).map(normalizeNode);
|
||||
certs.value = (a.certificates || []).map(normalizeCert);
|
||||
}
|
||||
|
||||
async function saveBasic() {
|
||||
function normalizeNode(n: any) {
|
||||
const media = n.media ?? n.mediaFiles ?? [];
|
||||
return {
|
||||
...n,
|
||||
media: media.map((m: any) => ({
|
||||
key: m.key || m.url,
|
||||
url: m.url,
|
||||
name: m.name,
|
||||
type: m.type || (isVideoMedia(m) ? 'video' : 'image'),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeCert(c: any) {
|
||||
return {
|
||||
...c,
|
||||
originKey: c.originKey ?? c.originFileUrl,
|
||||
originUrl: c.originUrl,
|
||||
watermarkUrl: c.watermarkUrl,
|
||||
};
|
||||
}
|
||||
|
||||
function buildNodePayload() {
|
||||
return nodes.value.map((node, index) => ({
|
||||
nodeType: node.nodeType,
|
||||
title: node.title,
|
||||
occurredAt: node.occurredAt || undefined,
|
||||
location: node.location,
|
||||
description: node.description,
|
||||
sortOrder: index,
|
||||
mediaFiles: (node.media || []).map((m: any) => ({
|
||||
key: m.key,
|
||||
name: m.name,
|
||||
type: m.type || (isVideoMedia(m) ? 'video' : 'image'),
|
||||
})),
|
||||
}));
|
||||
}
|
||||
|
||||
function buildCertPayload() {
|
||||
return certs.value.map((cert) => ({
|
||||
name: cert.name,
|
||||
issuer: cert.issuer,
|
||||
type: cert.type,
|
||||
originKey: cert.originKey,
|
||||
}));
|
||||
}
|
||||
|
||||
async function saveArtwork(asDraft: boolean) {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
} catch {
|
||||
@@ -336,7 +396,7 @@ async function saveBasic() {
|
||||
templateId: form.templateId,
|
||||
title: form.title,
|
||||
artist: form.artist,
|
||||
status: form.status,
|
||||
status: asDraft ? ArtworkStatus.DRAFT : isNew.value ? ArtworkStatus.ACTIVE : form.status,
|
||||
dynamicFields: form.dynamicFields,
|
||||
images: form.images.map((m: any) => ({
|
||||
key: m.key,
|
||||
@@ -345,9 +405,14 @@ async function saveBasic() {
|
||||
})),
|
||||
};
|
||||
if (isNew.value) {
|
||||
const created: any = await artworkApi.create(payload);
|
||||
const created: any = await artworkApi.create({
|
||||
...payload,
|
||||
traceNodes: buildNodePayload(),
|
||||
certificates: buildCertPayload(),
|
||||
});
|
||||
message.success(t('common.msg.created'));
|
||||
router.replace(`/artworks/${created.id}`);
|
||||
await router.replace(`/artworks/${created.id}`);
|
||||
await loadArtwork();
|
||||
} else {
|
||||
await artworkApi.update(artworkId.value, payload);
|
||||
message.success(t('common.msg.saved'));
|
||||
@@ -362,12 +427,14 @@ async function saveBasic() {
|
||||
const nodeModal = ref(false);
|
||||
const nodeSaving = ref(false);
|
||||
const editingNode = ref<number | null>(null);
|
||||
const editingNodeLocalId = ref<string | null>(null);
|
||||
const nodeForm = reactive<any>({ nodeType: NodeType.CREATE, title: '', occurredAt: null, location: '', description: '', media: [] });
|
||||
function isVideoMedia(m: any) {
|
||||
return m.type === 'video' || /\.(mp4|webm|mov|m4v)$/i.test(m.url || m.key || '');
|
||||
}
|
||||
function openNode(n?: any) {
|
||||
editingNode.value = n?.id ?? null;
|
||||
editingNodeLocalId.value = n?.localId ?? null;
|
||||
Object.assign(nodeForm, {
|
||||
nodeType: n?.nodeType ?? NodeType.CREATE,
|
||||
title: n?.title ?? '',
|
||||
@@ -402,16 +469,32 @@ async function saveNode() {
|
||||
type: m.type || (isVideoMedia(m) ? 'video' : 'image'),
|
||||
})),
|
||||
};
|
||||
if (editingNode.value) await artworkApi.updateNode(editingNode.value, payload);
|
||||
if (isNew.value) {
|
||||
const draftNode = normalizeNode({
|
||||
...payload,
|
||||
id: editingNode.value,
|
||||
localId: editingNodeLocalId.value || nextLocalId('node'),
|
||||
media: nodeForm.media,
|
||||
});
|
||||
const index = nodes.value.findIndex((item) => item.localId === draftNode.localId);
|
||||
if (index >= 0) nodes.value.splice(index, 1, draftNode);
|
||||
else nodes.value.push(draftNode);
|
||||
nodes.value = nodes.value.map((node, index) => ({ ...node, sortOrder: index }));
|
||||
} else if (editingNode.value) await artworkApi.updateNode(editingNode.value, payload);
|
||||
else await artworkApi.createNode(artworkId.value, payload);
|
||||
message.success(t('common.msg.saved'));
|
||||
nodeModal.value = false;
|
||||
nodes.value = await artworkApi.listNodes(artworkId.value);
|
||||
if (!isNew.value) nodes.value = (await artworkApi.listNodes(artworkId.value)).map(normalizeNode);
|
||||
} finally {
|
||||
nodeSaving.value = false;
|
||||
}
|
||||
}
|
||||
function removeNode(n: any) {
|
||||
if (isNew.value) {
|
||||
nodes.value = nodes.value.filter((item) => item.localId !== n.localId);
|
||||
nodes.value = nodes.value.map((node, index) => ({ ...node, sortOrder: index }));
|
||||
return;
|
||||
}
|
||||
dialog.warning({
|
||||
title: t('common.action.delete'),
|
||||
content: t('common.msg.confirmDelete'),
|
||||
@@ -419,7 +502,7 @@ function removeNode(n: any) {
|
||||
negativeText: t('common.action.cancel'),
|
||||
onPositiveClick: async () => {
|
||||
await artworkApi.removeNode(n.id);
|
||||
nodes.value = await artworkApi.listNodes(artworkId.value);
|
||||
nodes.value = (await artworkApi.listNodes(artworkId.value)).map(normalizeNode);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -439,20 +522,35 @@ async function saveCert() {
|
||||
}
|
||||
certSaving.value = true;
|
||||
try {
|
||||
await artworkApi.createCert(artworkId.value, {
|
||||
const payload = {
|
||||
name: certForm.name,
|
||||
issuer: certForm.issuer,
|
||||
type: certForm.type,
|
||||
originKey: certForm.files[0].key,
|
||||
});
|
||||
};
|
||||
if (isNew.value) {
|
||||
certs.value.push(
|
||||
normalizeCert({
|
||||
...payload,
|
||||
localId: nextLocalId('cert'),
|
||||
originUrl: certForm.files[0].url,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
await artworkApi.createCert(artworkId.value, payload);
|
||||
}
|
||||
message.success(t('common.msg.created'));
|
||||
certModal.value = false;
|
||||
certs.value = await artworkApi.listCerts(artworkId.value);
|
||||
if (!isNew.value) certs.value = (await artworkApi.listCerts(artworkId.value)).map(normalizeCert);
|
||||
} finally {
|
||||
certSaving.value = false;
|
||||
}
|
||||
}
|
||||
function removeCert(c: any) {
|
||||
if (isNew.value) {
|
||||
certs.value = certs.value.filter((item) => item.localId !== c.localId);
|
||||
return;
|
||||
}
|
||||
dialog.warning({
|
||||
title: t('common.action.delete'),
|
||||
content: t('common.msg.confirmDelete'),
|
||||
@@ -460,7 +558,7 @@ function removeCert(c: any) {
|
||||
negativeText: t('common.action.cancel'),
|
||||
onPositiveClick: async () => {
|
||||
await artworkApi.removeCert(c.id);
|
||||
certs.value = await artworkApi.listCerts(artworkId.value);
|
||||
certs.value = (await artworkApi.listCerts(artworkId.value)).map(normalizeCert);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -468,6 +566,7 @@ function removeCert(c: any) {
|
||||
onMounted(async () => {
|
||||
await loadTemplates();
|
||||
if (!isNew.value) await loadArtwork();
|
||||
else nodes.value = defaultTraceNodes();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -511,10 +610,8 @@ onMounted(async () => {
|
||||
color: #9ca3af;
|
||||
background: #f4f7fc;
|
||||
}
|
||||
.locked-section {
|
||||
padding: 28px 0;
|
||||
border: 1px dashed var(--border-color);
|
||||
border-radius: 8px;
|
||||
background: var(--table-header-bg);
|
||||
.edit-actions {
|
||||
display: inline-flex;
|
||||
gap: 8px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
class="table-fill"
|
||||
flex-height
|
||||
remote
|
||||
:scroll-x="1180"
|
||||
:scroll-x="1350"
|
||||
:row-key="(r) => r.id"
|
||||
@update:sorter="onSorterChange"
|
||||
/>
|
||||
@@ -99,7 +99,31 @@ const columns: DataTableColumns<any> = [
|
||||
})
|
||||
: h(NAvatar, { size: 40, style: 'border-radius:8px' }, { default: () => '—' }),
|
||||
},
|
||||
{ title: () => t('pages.artwork.title'), key: 'title', minWidth: 240, ellipsis: { tooltip: true } },
|
||||
{
|
||||
title: () => t('pages.artwork.archiveNo'),
|
||||
key: 'archiveNo',
|
||||
width: 170,
|
||||
align: 'center',
|
||||
ellipsis: { tooltip: true },
|
||||
render: (r) =>
|
||||
h(
|
||||
NButton,
|
||||
{ text: true, type: 'primary', title: t('common.action.detail'), onClick: () => goDetail(r) },
|
||||
{ default: () => r.archiveNo || '-' },
|
||||
),
|
||||
},
|
||||
{
|
||||
title: () => t('pages.artwork.title'),
|
||||
key: 'title',
|
||||
minWidth: 240,
|
||||
ellipsis: { tooltip: true },
|
||||
render: (r) =>
|
||||
h(
|
||||
NButton,
|
||||
{ text: true, type: 'primary', title: t('common.action.detail'), onClick: () => goDetail(r) },
|
||||
{ default: () => r.title },
|
||||
),
|
||||
},
|
||||
{ title: () => t('pages.artwork.artist'), key: 'artist', minWidth: 140, ellipsis: { tooltip: true }, render: (r) => r.artist || '-' },
|
||||
{
|
||||
title: () => renderTableFilterTitle(t('pages.audit.status'), query.auditStatus, auditStatusOptions, (value) => setAuditFilter(value)),
|
||||
@@ -118,7 +142,7 @@ const columns: DataTableColumns<any> = [
|
||||
align: 'center',
|
||||
render: (r) =>
|
||||
h('div', { class: 'row-actions' }, [
|
||||
h(NButton, { quaternary: true, circle: true, size: 'small', title: t('common.action.detail'), onClick: () => router.push(`/artworks/${r.id}`) }, { icon: () => h(NIcon, null, { default: () => h(EyeOutline) }) }),
|
||||
h(NButton, { quaternary: true, circle: true, size: 'small', title: t('common.action.detail'), onClick: () => goDetail(r) }, { icon: () => h(NIcon, null, { default: () => h(EyeOutline) }) }),
|
||||
h(NButton, { quaternary: true, circle: true, size: 'small', type: 'success', title: t('pages.audit.approve'), disabled: r.auditStatus === 'APPROVED', onClick: () => approve(r) }, { icon: () => h(NIcon, null, { default: () => h(CheckmarkCircleOutline) }) }),
|
||||
h(NButton, { quaternary: true, circle: true, size: 'small', type: 'error', title: t('pages.audit.reject'), disabled: r.auditStatus === 'REJECTED', onClick: () => openReject(r) }, { icon: () => h(NIcon, null, { default: () => h(CloseCircleOutline) }) }),
|
||||
]),
|
||||
@@ -151,6 +175,9 @@ function previewArtworkImages(images: any[]) {
|
||||
0,
|
||||
);
|
||||
}
|
||||
function goDetail(r: any) {
|
||||
router.push(`/artworks/${r.id}`);
|
||||
}
|
||||
function setAuditFilter(value: string | number | null) {
|
||||
query.auditStatus = value ? String(value) : null;
|
||||
onSearch();
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { BullModule } from '@nestjs/bullmq';
|
||||
import { QUEUE_NAMES } from '@artveris/shared';
|
||||
import { ArtworkService } from './artwork.service';
|
||||
import { ArtworkController } from './artwork.controller';
|
||||
|
||||
@Module({
|
||||
imports: [BullModule.registerQueue({ name: QUEUE_NAMES.WATERMARK })],
|
||||
controllers: [ArtworkController],
|
||||
providers: [ArtworkService],
|
||||
exports: [ArtworkService],
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectQueue } from '@nestjs/bullmq';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { AuditStatus, ErrorCode } from '@artveris/shared';
|
||||
import { Queue } from 'bullmq';
|
||||
import { AuditStatus, ErrorCode, QUEUE_NAMES } from '@artveris/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { StorageService } from '../storage/storage.service';
|
||||
import { BusinessException } from '../common/exceptions/business.exception';
|
||||
@@ -26,6 +28,7 @@ export class ArtworkService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly storage: StorageService,
|
||||
@InjectQueue(QUEUE_NAMES.WATERMARK) private readonly watermarkQueue: Queue,
|
||||
) {}
|
||||
|
||||
private mapMedia(items: unknown): Array<MediaItem & { url: string }> {
|
||||
@@ -45,22 +48,54 @@ export class ArtworkService {
|
||||
where: { id: dto.templateId, deletedAt: null },
|
||||
});
|
||||
if (!tpl) throw new BusinessException(ErrorCode.TEMPLATE_NOT_FOUND, '模板不存在', 404);
|
||||
const artwork = await this.prisma.artwork.create({
|
||||
data: {
|
||||
templateId: dto.templateId,
|
||||
title: dto.title,
|
||||
artist: dto.artist,
|
||||
dynamicFields: (dto.dynamicFields ?? {}) as Prisma.InputJsonValue,
|
||||
images: (dto.images ?? []) as unknown as Prisma.InputJsonValue,
|
||||
createdBy: userId,
|
||||
traceNodes: { create: DEFAULT_TRACE_NODES },
|
||||
},
|
||||
});
|
||||
// 创建后回填档案编号(需要自增 id)
|
||||
await this.prisma.artwork.update({
|
||||
where: { id: artwork.id },
|
||||
data: { archiveNo: this.buildArchiveNo(artwork.id) },
|
||||
|
||||
const traceNodes =
|
||||
dto.traceNodes === undefined
|
||||
? DEFAULT_TRACE_NODES
|
||||
: dto.traceNodes.map((node, index) => ({
|
||||
nodeType: node.nodeType,
|
||||
title: node.title,
|
||||
occurredAt: node.occurredAt ? new Date(node.occurredAt) : null,
|
||||
location: node.location,
|
||||
description: node.description,
|
||||
mediaFiles: (node.mediaFiles ?? []) as unknown as Prisma.InputJsonValue,
|
||||
sortOrder: node.sortOrder ?? index,
|
||||
}));
|
||||
const certificates = (dto.certificates ?? []).map((cert) => ({
|
||||
name: cert.name,
|
||||
issuer: cert.issuer,
|
||||
issuedAt: cert.issuedAt ? new Date(cert.issuedAt) : null,
|
||||
type: cert.type,
|
||||
originFileUrl: cert.originKey,
|
||||
}));
|
||||
|
||||
const artwork = await this.prisma.$transaction(async (tx) => {
|
||||
const created = await tx.artwork.create({
|
||||
data: {
|
||||
templateId: dto.templateId,
|
||||
title: dto.title,
|
||||
artist: dto.artist,
|
||||
status: dto.status,
|
||||
dynamicFields: (dto.dynamicFields ?? {}) as Prisma.InputJsonValue,
|
||||
images: (dto.images ?? []) as unknown as Prisma.InputJsonValue,
|
||||
createdBy: userId,
|
||||
traceNodes: traceNodes.length ? { create: traceNodes } : undefined,
|
||||
certificates: certificates.length ? { create: certificates } : undefined,
|
||||
},
|
||||
include: { certificates: true },
|
||||
});
|
||||
await tx.artwork.update({
|
||||
where: { id: created.id },
|
||||
data: { archiveNo: this.buildArchiveNo(created.id) },
|
||||
});
|
||||
return created;
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
artwork.certificates.map((cert) =>
|
||||
this.watermarkQueue.add('generate', { certificateId: cert.id, originKey: cert.originFileUrl }),
|
||||
),
|
||||
);
|
||||
return this.get(artwork.id);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import {
|
||||
IsArray,
|
||||
IsDateString,
|
||||
IsEnum,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
@@ -12,7 +13,7 @@ import {
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
import { IsBoolean } from 'class-validator';
|
||||
import { ArtworkStatus, AuditStatus } from '@artveris/shared';
|
||||
import { ArtworkStatus, AuditStatus, CertType, NodeType } from '@artveris/shared';
|
||||
import { PaginationDto } from '../../common/dto/pagination.dto';
|
||||
|
||||
export class MediaItemDto {
|
||||
@@ -61,6 +62,94 @@ export class CreateArtworkDto {
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => MediaItemDto)
|
||||
images?: MediaItemDto[];
|
||||
|
||||
@ApiPropertyOptional({ description: '状态', enum: ArtworkStatus })
|
||||
@IsOptional()
|
||||
@IsEnum(ArtworkStatus)
|
||||
status?: ArtworkStatus;
|
||||
|
||||
@ApiPropertyOptional({ description: '创建时一并保存的溯源时间轴草稿', type: () => [CreateArtworkTraceNodeDto] })
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => CreateArtworkTraceNodeDto)
|
||||
traceNodes?: CreateArtworkTraceNodeDto[];
|
||||
|
||||
@ApiPropertyOptional({ description: '创建时一并保存的认证文件草稿', type: () => [CreateArtworkCertificateDto] })
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => CreateArtworkCertificateDto)
|
||||
certificates?: CreateArtworkCertificateDto[];
|
||||
}
|
||||
|
||||
export class CreateArtworkTraceNodeDto {
|
||||
@ApiProperty({ description: '节点类型', enum: NodeType })
|
||||
@IsEnum(NodeType)
|
||||
nodeType!: NodeType;
|
||||
|
||||
@ApiProperty({ description: '节点标题' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MaxLength(80)
|
||||
title!: string;
|
||||
|
||||
@ApiPropertyOptional({ description: '发生时间' })
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
occurredAt?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: '地点' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(120)
|
||||
location?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: '说明' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(2000)
|
||||
description?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: '图片/视频', type: [MediaItemDto] })
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => MediaItemDto)
|
||||
mediaFiles?: MediaItemDto[];
|
||||
|
||||
@ApiPropertyOptional({ description: '排序' })
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
sortOrder?: number;
|
||||
}
|
||||
|
||||
export class CreateArtworkCertificateDto {
|
||||
@ApiProperty({ description: '证书名称' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MaxLength(120)
|
||||
name!: string;
|
||||
|
||||
@ApiPropertyOptional({ description: '颁发机构' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(120)
|
||||
issuer?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: '颁发时间' })
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
issuedAt?: string;
|
||||
|
||||
@ApiProperty({ description: '类型', enum: CertType })
|
||||
@IsEnum(CertType)
|
||||
type!: CertType;
|
||||
|
||||
@ApiProperty({ description: '原始文件存储 key(上传接口返回)' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
originKey!: string;
|
||||
}
|
||||
|
||||
export class UpdateArtworkDto {
|
||||
|
||||
Reference in New Issue
Block a user