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 -2
View File
@@ -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",
+1 -2
View File
@@ -251,8 +251,7 @@
"dynamicFields": "动态字段",
"nodes": "溯源时间轴",
"certificates": "认证文件",
"saveBeforeNodes": "保存基础信息后可维护溯源时间轴",
"saveBeforeCertificates": "保存基础信息后可上传认证文件",
"saveDraft": "保存草稿",
"traceCode": "追溯码",
"status": "状态",
"create": "新建作品",
+137 -40
View File
@@ -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>
+30 -3
View File
@@ -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();