feat: 优化建档草稿和审核详情入口

This commit is contained in:
Nixevol
2026-07-05 01:55:42 +08:00
parent b736b8a105
commit 41133a3db5
8 changed files with 314 additions and 64 deletions
+1
View File
@@ -135,6 +135,7 @@
- 备份覆盖率加固(2026-07-05):备份数据库清单现在会在创建备份前对照 `Prisma.ModelName` 做覆盖校验,除 `BackupRecord`(备份包自身元数据,恢复旧路径会产生坏记录)外,所有业务模型必须在备份清单中,否则直接报错阻止生成不完整备份。`systemSetting` 备份不再只导出数据库已有行,而是导出 `SettingsService.getAll()` 的有效设置全集,确保平台名称、系统图标、备案信息、日志保留、备份策略、轮播间隔等默认但未保存过的设置也能随备份迁移。文件备份仍覆盖本地 `storage` 全目录,但会显式排除 `backupRoot`,避免 `BACKUP_DIR` 被配置到 storage 下时把旧备份包递归打进新备份;恢复清理 storage 时也保留 backupRoot。 - 备份覆盖率加固(2026-07-05):备份数据库清单现在会在创建备份前对照 `Prisma.ModelName` 做覆盖校验,除 `BackupRecord`(备份包自身元数据,恢复旧路径会产生坏记录)外,所有业务模型必须在备份清单中,否则直接报错阻止生成不完整备份。`systemSetting` 备份不再只导出数据库已有行,而是导出 `SettingsService.getAll()` 的有效设置全集,确保平台名称、系统图标、备案信息、日志保留、备份策略、轮播间隔等默认但未保存过的设置也能随备份迁移。文件备份仍覆盖本地 `storage` 全目录,但会显式排除 `backupRoot`,避免 `BACKUP_DIR` 被配置到 storage 下时把旧备份包递归打进新备份;恢复清理 storage 时也保留 backupRoot。
- 默认建档体验(2026-07-05):对照甲方原版 PRD §3.1.2/§3.2,新建作品档案时后端会自动创建 4 个溯源时间轴节点骨架:创作/选胚、制作过程、仓储/托管、出库/流转;默认节点只含标题/类型/排序,不预填图片、时间、地点、说明等真实内容,运营可编辑、补充或删除。默认动态字段口径调整为只包含模板字段:工艺、创作年代/出品时间、规格尺寸、材质/媒介、认证机构、数据权属;作品名称、艺术家、档案编号、批次编号分别由固定字段、自动档案号和批次/追溯码管理承载,不再重复进动态字段。新建模板弹窗会按当前语言生成这些默认字段;seed 幂等补齐既有“陶瓷溯源模板”的缺失默认字段。 - 默认建档体验(2026-07-05):对照甲方原版 PRD §3.1.2/§3.2,新建作品档案时后端会自动创建 4 个溯源时间轴节点骨架:创作/选胚、制作过程、仓储/托管、出库/流转;默认节点只含标题/类型/排序,不预填图片、时间、地点、说明等真实内容,运营可编辑、补充或删除。默认动态字段口径调整为只包含模板字段:工艺、创作年代/出品时间、规格尺寸、材质/媒介、认证机构、数据权属;作品名称、艺术家、档案编号、批次编号分别由固定字段、自动档案号和批次/追溯码管理承载,不再重复进动态字段。新建模板弹窗会按当前语言生成这些默认字段;seed 幂等补齐既有“陶瓷溯源模板”的缺失默认字段。
- 默认系统图标配色(2026-07-05):后台与客户端内置 `/app-icon.svg` 保持原有圆角底、盾牌、艺术器形/印章结构不变,仅将默认配色从偏沉深蓝绿/金色调整为清爽青绿与浅蓝渐变;图标仍无底部横线,自定义图标设置逻辑不变。 - 默认系统图标配色(2026-07-05):后台与客户端内置 `/app-icon.svg` 保持原有圆角底、盾牌、艺术器形/印章结构不变,仅将默认配色从偏沉深蓝绿/金色调整为清爽青绿与浅蓝渐变;图标仍无底部横线,自定义图标设置逻辑不变。
- 建档草稿编辑体验(2026-07-05):新建艺术品档案时,前端立即显示 4 个默认溯源时间轴节点,并允许在创建态编辑时间轴、上传认证文件;这些子资源作为本地草稿随档案一次性提交。`POST /artworks` 兼容新增 `status/traceNodes/certificates`,不传 `traceNodes` 时仍由后端创建默认节点,显式传空数组则表示用户删除全部默认节点。建档页保存按钮移到右上角,新增“保存草稿”(写入 `ArtworkStatus.DRAFT`);普通保存新建档案时写入 `ACTIVE`,已有档案仍按页面状态保存。内容审核列表新增档案编号列,档案编号、作品名称和查看按钮都可进入作品详情,便于审核员查看完整作品内容后再处理审核。
## 当前代码基准与注意事项 ## 当前代码基准与注意事项
+1 -2
View File
@@ -251,8 +251,7 @@
"dynamicFields": "Fields", "dynamicFields": "Fields",
"nodes": "Timeline", "nodes": "Timeline",
"certificates": "Certificates", "certificates": "Certificates",
"saveBeforeNodes": "Save basic info before editing the timeline", "saveDraft": "Save Draft",
"saveBeforeCertificates": "Save basic info before uploading certificates",
"traceCode": "Trace Code", "traceCode": "Trace Code",
"status": "Status", "status": "Status",
"create": "New Artwork", "create": "New Artwork",
+1 -2
View File
@@ -251,8 +251,7 @@
"dynamicFields": "动态字段", "dynamicFields": "动态字段",
"nodes": "溯源时间轴", "nodes": "溯源时间轴",
"certificates": "认证文件", "certificates": "认证文件",
"saveBeforeNodes": "保存基础信息后可维护溯源时间轴", "saveDraft": "保存草稿",
"saveBeforeCertificates": "保存基础信息后可上传认证文件",
"traceCode": "追溯码", "traceCode": "追溯码",
"status": "状态", "status": "状态",
"create": "新建作品", "create": "新建作品",
+137 -40
View File
@@ -6,6 +6,15 @@
{{ t('common.action.back') }} {{ t('common.action.back') }}
</n-button> </n-button>
<div class="page-title">{{ isNew ? t('pages.artwork.create') : t('pages.artwork.detail') }}</div> <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> </div>
<n-grid :cols="1" :y-gap="16"> <n-grid :cols="1" :y-gap="16">
@@ -107,29 +116,21 @@
<n-divider style="margin: 4px 0 16px">{{ t('pages.artwork.images') }}</n-divider> <n-divider style="margin: 4px 0 16px">{{ t('pages.artwork.images') }}</n-divider>
<media-sorter v-model="form.images" :max="12" /> <media-sorter v-model="form.images" :max="12" />
</n-form> </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-card>
</n-grid-item> </n-grid-item>
<!-- 溯源时间轴 --> <!-- 溯源时间轴 -->
<n-grid-item> <n-grid-item>
<n-card :title="t('pages.artwork.nodes')" :bordered="false"> <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()"> <n-button v-if="auth.canWrite" size="small" type="primary" @click="openNode()">
<template #icon><n-icon :component="AddOutline" /></template> <template #icon><n-icon :component="AddOutline" /></template>
{{ t('pages.artwork.addNode') }} {{ t('pages.artwork.addNode') }}
</n-button> </n-button>
</template> </template>
<n-empty v-if="isNew" class="locked-section" :description="t('pages.artwork.saveBeforeNodes')"> <n-empty v-if="!nodes.length" :description="t('common.msg.noData')" />
<template #icon><n-icon :component="LockClosedOutline" /></template>
</n-empty>
<n-empty v-else-if="!nodes.length" :description="t('common.msg.noData')" />
<n-timeline v-else> <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> <template #header>
<div class="node-head"> <div class="node-head">
<span>{{ t(`common.nodeType.${n.nodeType}`) }} · {{ n.title }}</span> <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 class="node-meta">{{ [fmtDate(n.occurredAt), n.location].filter(Boolean).join(' · ') }}</div>
<div>{{ n.description }}</div> <div>{{ n.description }}</div>
<div class="node-media"> <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 <video
v-if="isVideoMedia(m)" v-if="isVideoMedia(m)"
:src="m.url" :src="m.url"
@@ -161,21 +162,18 @@
<!-- 认证文件 --> <!-- 认证文件 -->
<n-grid-item> <n-grid-item>
<n-card :title="t('pages.artwork.certificates')" :bordered="false"> <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()"> <n-button v-if="auth.canWrite" size="small" type="primary" @click="openCert()">
<template #icon><n-icon :component="AddOutline" /></template> <template #icon><n-icon :component="AddOutline" /></template>
{{ t('pages.artwork.addCert') }} {{ t('pages.artwork.addCert') }}
</n-button> </n-button>
</template> </template>
<n-empty v-if="isNew" class="locked-section" :description="t('pages.artwork.saveBeforeCertificates')"> <n-empty v-if="!certs.length" :description="t('common.msg.noData')" />
<template #icon><n-icon :component="LockClosedOutline" /></template>
</n-empty>
<n-empty v-else-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 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"> <n-card size="small" :title="c.name">
<template #cover> <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> <div v-else class="cert-pending">{{ t('pages.artwork.watermarkPending') }}</div>
</template> </template>
<div class="cert-meta">{{ c.issuer || '-' }}</div> <div class="cert-meta">{{ c.issuer || '-' }}</div>
@@ -251,11 +249,11 @@
</template> </template>
<script setup lang="ts"> <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 { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { NTag, type FormInst, type FormRules } from 'naive-ui'; import type { FormInst, FormRules } from 'naive-ui';
import { ArrowBackOutline, AddOutline, LockClosedOutline } 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 } from '@/api'; import { artworkApi, templateApi } from '@/api';
import { useAuthStore } from '@/stores/auth'; 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 artwork = ref<any>(null);
const nodes = ref<any[]>([]); const nodes = ref<any[]>([]);
const certs = 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() { function onTemplateChange() {
form.dynamicFields = {}; form.dynamicFields = {};
@@ -320,11 +333,58 @@ async function loadArtwork() {
...m, ...m,
type: m.type || (isVideoMedia(m) ? 'video' : 'image'), type: m.type || (isVideoMedia(m) ? 'video' : 'image'),
})); }));
nodes.value = a.traceNodes || []; nodes.value = (a.traceNodes || []).map(normalizeNode);
certs.value = a.certificates || []; 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 { try {
await formRef.value?.validate(); await formRef.value?.validate();
} catch { } catch {
@@ -336,7 +396,7 @@ async function saveBasic() {
templateId: form.templateId, templateId: form.templateId,
title: form.title, title: form.title,
artist: form.artist, artist: form.artist,
status: form.status, status: asDraft ? ArtworkStatus.DRAFT : isNew.value ? ArtworkStatus.ACTIVE : form.status,
dynamicFields: form.dynamicFields, dynamicFields: form.dynamicFields,
images: form.images.map((m: any) => ({ images: form.images.map((m: any) => ({
key: m.key, key: m.key,
@@ -345,9 +405,14 @@ async function saveBasic() {
})), })),
}; };
if (isNew.value) { 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')); message.success(t('common.msg.created'));
router.replace(`/artworks/${created.id}`); await router.replace(`/artworks/${created.id}`);
await loadArtwork();
} else { } else {
await artworkApi.update(artworkId.value, payload); await artworkApi.update(artworkId.value, payload);
message.success(t('common.msg.saved')); message.success(t('common.msg.saved'));
@@ -362,12 +427,14 @@ async function saveBasic() {
const nodeModal = ref(false); const nodeModal = ref(false);
const nodeSaving = ref(false); const nodeSaving = ref(false);
const editingNode = ref<number | null>(null); 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: [] }); const nodeForm = reactive<any>({ nodeType: NodeType.CREATE, title: '', occurredAt: null, location: '', description: '', media: [] });
function isVideoMedia(m: any) { function isVideoMedia(m: any) {
return m.type === 'video' || /\.(mp4|webm|mov|m4v)$/i.test(m.url || m.key || ''); return m.type === 'video' || /\.(mp4|webm|mov|m4v)$/i.test(m.url || m.key || '');
} }
function openNode(n?: any) { function openNode(n?: any) {
editingNode.value = n?.id ?? null; editingNode.value = n?.id ?? null;
editingNodeLocalId.value = n?.localId ?? null;
Object.assign(nodeForm, { Object.assign(nodeForm, {
nodeType: n?.nodeType ?? NodeType.CREATE, nodeType: n?.nodeType ?? NodeType.CREATE,
title: n?.title ?? '', title: n?.title ?? '',
@@ -402,16 +469,32 @@ async function saveNode() {
type: m.type || (isVideoMedia(m) ? 'video' : 'image'), 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); else await artworkApi.createNode(artworkId.value, payload);
message.success(t('common.msg.saved')); message.success(t('common.msg.saved'));
nodeModal.value = false; nodeModal.value = false;
nodes.value = await artworkApi.listNodes(artworkId.value); if (!isNew.value) nodes.value = (await artworkApi.listNodes(artworkId.value)).map(normalizeNode);
} finally { } finally {
nodeSaving.value = false; nodeSaving.value = false;
} }
} }
function removeNode(n: any) { 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({ dialog.warning({
title: t('common.action.delete'), title: t('common.action.delete'),
content: t('common.msg.confirmDelete'), content: t('common.msg.confirmDelete'),
@@ -419,7 +502,7 @@ function removeNode(n: any) {
negativeText: t('common.action.cancel'), negativeText: t('common.action.cancel'),
onPositiveClick: async () => { onPositiveClick: async () => {
await artworkApi.removeNode(n.id); 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; certSaving.value = true;
try { try {
await artworkApi.createCert(artworkId.value, { const payload = {
name: certForm.name, name: certForm.name,
issuer: certForm.issuer, issuer: certForm.issuer,
type: certForm.type, type: certForm.type,
originKey: certForm.files[0].key, 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')); message.success(t('common.msg.created'));
certModal.value = false; certModal.value = false;
certs.value = await artworkApi.listCerts(artworkId.value); if (!isNew.value) certs.value = (await artworkApi.listCerts(artworkId.value)).map(normalizeCert);
} finally { } finally {
certSaving.value = false; certSaving.value = false;
} }
} }
function removeCert(c: any) { function removeCert(c: any) {
if (isNew.value) {
certs.value = certs.value.filter((item) => item.localId !== c.localId);
return;
}
dialog.warning({ dialog.warning({
title: t('common.action.delete'), title: t('common.action.delete'),
content: t('common.msg.confirmDelete'), content: t('common.msg.confirmDelete'),
@@ -460,7 +558,7 @@ function removeCert(c: any) {
negativeText: t('common.action.cancel'), negativeText: t('common.action.cancel'),
onPositiveClick: async () => { onPositiveClick: async () => {
await artworkApi.removeCert(c.id); 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 () => { onMounted(async () => {
await loadTemplates(); await loadTemplates();
if (!isNew.value) await loadArtwork(); if (!isNew.value) await loadArtwork();
else nodes.value = defaultTraceNodes();
}); });
</script> </script>
@@ -511,10 +610,8 @@ onMounted(async () => {
color: #9ca3af; color: #9ca3af;
background: #f4f7fc; background: #f4f7fc;
} }
.locked-section { .edit-actions {
padding: 28px 0; display: inline-flex;
border: 1px dashed var(--border-color); gap: 8px;
border-radius: 8px;
background: var(--table-header-bg);
} }
</style> </style>
+30 -3
View File
@@ -22,7 +22,7 @@
class="table-fill" class="table-fill"
flex-height flex-height
remote remote
:scroll-x="1180" :scroll-x="1350"
:row-key="(r) => r.id" :row-key="(r) => r.id"
@update:sorter="onSorterChange" @update:sorter="onSorterChange"
/> />
@@ -99,7 +99,31 @@ const columns: DataTableColumns<any> = [
}) })
: h(NAvatar, { size: 40, style: 'border-radius:8px' }, { default: () => '—' }), : 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: () => 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)), title: () => renderTableFilterTitle(t('pages.audit.status'), query.auditStatus, auditStatusOptions, (value) => setAuditFilter(value)),
@@ -118,7 +142,7 @@ const columns: DataTableColumns<any> = [
align: 'center', align: 'center',
render: (r) => render: (r) =>
h('div', { class: 'row-actions' }, [ 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: '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) }) }), 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, 0,
); );
} }
function goDetail(r: any) {
router.push(`/artworks/${r.id}`);
}
function setAuditFilter(value: string | number | null) { function setAuditFilter(value: string | number | null) {
query.auditStatus = value ? String(value) : null; query.auditStatus = value ? String(value) : null;
onSearch(); onSearch();
+3
View File
@@ -1,8 +1,11 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bullmq';
import { QUEUE_NAMES } from '@artveris/shared';
import { ArtworkService } from './artwork.service'; import { ArtworkService } from './artwork.service';
import { ArtworkController } from './artwork.controller'; import { ArtworkController } from './artwork.controller';
@Module({ @Module({
imports: [BullModule.registerQueue({ name: QUEUE_NAMES.WATERMARK })],
controllers: [ArtworkController], controllers: [ArtworkController],
providers: [ArtworkService], providers: [ArtworkService],
exports: [ArtworkService], exports: [ArtworkService],
+51 -16
View File
@@ -1,6 +1,8 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { InjectQueue } from '@nestjs/bullmq';
import { Prisma } from '@prisma/client'; 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 { PrismaService } from '../prisma/prisma.service';
import { StorageService } from '../storage/storage.service'; import { StorageService } from '../storage/storage.service';
import { BusinessException } from '../common/exceptions/business.exception'; import { BusinessException } from '../common/exceptions/business.exception';
@@ -26,6 +28,7 @@ export class ArtworkService {
constructor( constructor(
private readonly prisma: PrismaService, private readonly prisma: PrismaService,
private readonly storage: StorageService, private readonly storage: StorageService,
@InjectQueue(QUEUE_NAMES.WATERMARK) private readonly watermarkQueue: Queue,
) {} ) {}
private mapMedia(items: unknown): Array<MediaItem & { url: string }> { private mapMedia(items: unknown): Array<MediaItem & { url: string }> {
@@ -45,22 +48,54 @@ export class ArtworkService {
where: { id: dto.templateId, deletedAt: null }, where: { id: dto.templateId, deletedAt: null },
}); });
if (!tpl) throw new BusinessException(ErrorCode.TEMPLATE_NOT_FOUND, '模板不存在', 404); if (!tpl) throw new BusinessException(ErrorCode.TEMPLATE_NOT_FOUND, '模板不存在', 404);
const artwork = await this.prisma.artwork.create({
data: { const traceNodes =
templateId: dto.templateId, dto.traceNodes === undefined
title: dto.title, ? DEFAULT_TRACE_NODES
artist: dto.artist, : dto.traceNodes.map((node, index) => ({
dynamicFields: (dto.dynamicFields ?? {}) as Prisma.InputJsonValue, nodeType: node.nodeType,
images: (dto.images ?? []) as unknown as Prisma.InputJsonValue, title: node.title,
createdBy: userId, occurredAt: node.occurredAt ? new Date(node.occurredAt) : null,
traceNodes: { create: DEFAULT_TRACE_NODES }, location: node.location,
}, description: node.description,
}); mediaFiles: (node.mediaFiles ?? []) as unknown as Prisma.InputJsonValue,
// 创建后回填档案编号(需要自增 id) sortOrder: node.sortOrder ?? index,
await this.prisma.artwork.update({ }));
where: { id: artwork.id }, const certificates = (dto.certificates ?? []).map((cert) => ({
data: { archiveNo: this.buildArchiveNo(artwork.id) }, 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); return this.get(artwork.id);
} }
+90 -1
View File
@@ -2,6 +2,7 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer'; import { Type } from 'class-transformer';
import { import {
IsArray, IsArray,
IsDateString,
IsEnum, IsEnum,
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
@@ -12,7 +13,7 @@ import {
ValidateNested, ValidateNested,
} from 'class-validator'; } from 'class-validator';
import { IsBoolean } 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'; import { PaginationDto } from '../../common/dto/pagination.dto';
export class MediaItemDto { export class MediaItemDto {
@@ -61,6 +62,94 @@ export class CreateArtworkDto {
@ValidateNested({ each: true }) @ValidateNested({ each: true })
@Type(() => MediaItemDto) @Type(() => MediaItemDto)
images?: 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 { export class UpdateArtworkDto {