feat: 无修改时禁止提交审核

This commit is contained in:
Nixevol
2026-07-05 03:35:20 +08:00
parent a195adba1b
commit 29e608e782
5 changed files with 154 additions and 5 deletions
+1
View File
@@ -258,6 +258,7 @@
"saveDraft": "Save Draft",
"submitReview": "Submit for Audit",
"submittedReview": "Submitted for audit. Changes take effect only after approval.",
"noChangeTip": "No artwork content changes to submit.",
"changeInfo": "Change Notes",
"changeTitle": "Change Title",
"changeTitlePlaceholder": "e.g. Add certificate, adjust artwork images",
+1
View File
@@ -258,6 +258,7 @@
"saveDraft": "保存草稿",
"submitReview": "提交审核",
"submittedReview": "已提交审核,审核通过后修改才会生效",
"noChangeTip": "作品内容未发生变化,无需提交审核",
"changeInfo": "修改说明",
"changeTitle": "修改标题",
"changeTitlePlaceholder": "例如:补充认证文件、调整作品图片",
+80 -1
View File
@@ -11,7 +11,13 @@
<n-button v-if="isNew" :loading="saving" :disabled="!auth.canWrite" @click="saveArtwork(true)">
{{ t('pages.artwork.saveDraft') }}
</n-button>
<n-button type="primary" :loading="saving" :disabled="!auth.canWrite" @click="isNew ? saveArtwork(false) : openSubmitReview()">
<n-button
type="primary"
:loading="saving"
:disabled="!auth.canWrite || (!isNew && !hasArtworkChanges)"
:title="!isNew && !hasArtworkChanges ? t('pages.artwork.noChangeTip') : ''"
@click="isNew ? saveArtwork(false) : openSubmitReview()"
>
{{ isNew ? t('common.action.save') : t('pages.artwork.submitReview') }}
</n-button>
</div>
@@ -370,7 +376,9 @@ const certs = ref<any[]>([]);
const revisions = ref<any[]>([]);
const revisionLoading = ref(false);
const previewRevision = ref<any>(null);
const originalSnapshot = ref<string>('');
let localIdSeed = 0;
const hasArtworkChanges = computed(() => isNew.value || originalSnapshot.value !== JSON.stringify(buildComparableSnapshot()));
function nextLocalId(prefix: string) {
localIdSeed += 1;
@@ -414,6 +422,10 @@ async function openSubmitReview() {
} catch {
return;
}
if (!hasArtworkChanges.value) {
message.warning(t('pages.artwork.noChangeTip'));
return;
}
if (!submitReviewForm.title) submitReviewForm.title = t('pages.artwork.defaultChangeTitle');
submitReviewModal.value = true;
}
@@ -431,6 +443,7 @@ async function loadArtwork() {
} else {
previewRevision.value = null;
}
originalSnapshot.value = JSON.stringify(buildComparableSnapshot());
}
async function loadRevisions() {
@@ -498,6 +511,7 @@ function normalizeCert(c: any) {
...c,
originKey: c.originKey ?? c.originFileUrl,
watermarkKey: c.watermarkKey ?? c.watermarkFileUrl,
issuedAt: c.issuedAt,
originUrl: c.originUrl,
watermarkUrl: c.watermarkUrl,
};
@@ -523,6 +537,7 @@ function buildCertPayload() {
return certs.value.map((cert) => ({
name: cert.name,
issuer: cert.issuer,
issuedAt: cert.issuedAt || undefined,
type: cert.type,
originKey: cert.originKey,
watermarkKey: cert.watermarkKey,
@@ -537,6 +552,11 @@ async function saveArtwork(asDraft: boolean) {
}
saving.value = true;
try {
if (!isNew.value && !hasArtworkChanges.value) {
message.warning(t('pages.artwork.noChangeTip'));
submitReviewModal.value = false;
return;
}
const payload = {
templateId: form.templateId,
title: form.title,
@@ -571,6 +591,65 @@ async function saveArtwork(asDraft: boolean) {
}
}
function buildComparableSnapshot() {
return {
artwork: {
templateId: Number(form.templateId),
title: form.title || '',
artist: form.artist || '',
status: form.status,
dynamicFields: normalizeJson(form.dynamicFields || {}),
images: normalizeMedia(form.images),
},
traceNodes: nodes.value.map((node, index) => ({
nodeType: node.nodeType,
title: node.title || '',
occurredAt: normalizeDateOnly(node.occurredAt),
location: node.location || '',
description: node.description || '',
mediaFiles: normalizeMedia(node.media || node.mediaFiles),
sortOrder: index,
})),
certificates: certs.value.map((cert) => ({
name: cert.name || '',
issuer: cert.issuer || '',
issuedAt: normalizeDateOnly(cert.issuedAt),
type: cert.type,
originKey: cert.originKey,
watermarkKey: cert.watermarkKey || '',
})),
};
}
function normalizeMedia(items?: any[]) {
return (items || []).map((item) => ({
key: item.key || item.url || '',
name: item.name || '',
type: item.type || '',
}));
}
function normalizeJson(value: unknown): unknown {
if (Array.isArray(value)) return value.map((item) => normalizeJson(item));
if (value && typeof value === 'object') {
return Object.keys(value as Record<string, unknown>)
.sort()
.reduce<Record<string, unknown>>((acc, key) => {
const item = (value as Record<string, unknown>)[key];
if (item !== undefined) acc[key] = normalizeJson(item);
return acc;
}, {});
}
return value ?? null;
}
function normalizeDateOnly(value?: string | Date | null) {
if (!value) return null;
const date = new Date(value);
if (!Number.isNaN(date.getTime())) return date.toISOString().slice(0, 10);
return String(value).slice(0, 10);
}
/* 节点 */
const nodeModal = ref(false);
const nodeSaving = ref(false);
+71 -4
View File
@@ -278,6 +278,9 @@ export class ArtworkService {
const artwork = await this.ensureExists(id);
const shouldApplyDirectly = artwork.status !== ArtworkStatus.ACTIVE || artwork.auditStatus !== AuditStatus.APPROVED;
if (!this.hasSnapshotChanged(current, afterSnapshot)) {
throw new BusinessException(ErrorCode.VALIDATION_FAILED, '作品内容未发生变化,无需提交审核', 400);
}
const revisionTitle = dto.revisionTitle || '作品内容修改';
const revisionReason = dto.revisionReason || null;
@@ -454,7 +457,7 @@ export class ArtworkService {
return nodes.map((node, index) => ({
nodeType: node.nodeType,
title: node.title,
occurredAt: node.occurredAt ?? null,
occurredAt: this.normalizeDateOnly(node.occurredAt),
location: node.location ?? null,
description: node.description ?? null,
mediaFiles: (node.mediaFiles ?? []) as MediaItem[],
@@ -466,7 +469,7 @@ export class ArtworkService {
return certs.map((cert) => ({
name: cert.name,
issuer: cert.issuer ?? null,
issuedAt: cert.issuedAt ?? null,
issuedAt: this.normalizeDateOnly(cert.issuedAt),
type: cert.type,
originKey: cert.originKey,
watermarkKey: cert.watermarkKey ?? null,
@@ -512,7 +515,7 @@ export class ArtworkService {
.map((node) => ({
nodeType: node.nodeType,
title: node.title,
occurredAt: node.occurredAt ? node.occurredAt.toISOString() : null,
occurredAt: this.normalizeDateOnly(node.occurredAt),
location: node.location,
description: node.description,
mediaFiles: (Array.isArray(node.mediaFiles) ? node.mediaFiles : []) as unknown as MediaItem[],
@@ -521,7 +524,7 @@ export class ArtworkService {
certificates: record.certificates.map((cert) => ({
name: cert.name,
issuer: cert.issuer,
issuedAt: cert.issuedAt ? cert.issuedAt.toISOString() : null,
issuedAt: this.normalizeDateOnly(cert.issuedAt),
type: cert.type,
originKey: cert.originFileUrl,
watermarkKey: cert.watermarkFileUrl,
@@ -529,6 +532,70 @@ export class ArtworkService {
};
}
private hasSnapshotChanged(before: ArtworkSnapshot, after: ArtworkSnapshot): boolean {
return JSON.stringify(this.normalizeSnapshotForCompare(before)) !== JSON.stringify(this.normalizeSnapshotForCompare(after));
}
private normalizeSnapshotForCompare(snapshot: ArtworkSnapshot) {
return {
artwork: {
templateId: Number(snapshot.artwork.templateId),
title: snapshot.artwork.title ?? '',
artist: snapshot.artwork.artist ?? '',
status: snapshot.artwork.status,
dynamicFields: this.normalizeJson(snapshot.artwork.dynamicFields ?? {}),
images: this.normalizeMedia(snapshot.artwork.images),
},
traceNodes: snapshot.traceNodes.map((node, index) => ({
nodeType: node.nodeType,
title: node.title ?? '',
occurredAt: this.normalizeDateOnly(node.occurredAt),
location: node.location ?? '',
description: node.description ?? '',
mediaFiles: this.normalizeMedia(node.mediaFiles),
sortOrder: index,
})),
certificates: snapshot.certificates.map((cert) => ({
name: cert.name ?? '',
issuer: cert.issuer ?? '',
issuedAt: this.normalizeDateOnly(cert.issuedAt),
type: cert.type,
originKey: cert.originKey,
watermarkKey: cert.watermarkKey ?? '',
})),
};
}
private normalizeMedia(items?: MediaItem[]) {
return (items ?? []).map((item) => ({
key: item.key,
name: item.name ?? '',
type: item.type ?? '',
}));
}
private normalizeJson(value: unknown): unknown {
if (Array.isArray(value)) return value.map((item) => this.normalizeJson(item));
if (value && typeof value === 'object') {
return Object.keys(value as Record<string, unknown>)
.sort()
.reduce<Record<string, unknown>>((acc, key) => {
const item = (value as Record<string, unknown>)[key];
if (item !== undefined) acc[key] = this.normalizeJson(item);
return acc;
}, {});
}
return value ?? null;
}
private normalizeDateOnly(value?: string | Date | null): string | null {
if (!value) return null;
if (value instanceof Date) return value.toISOString().slice(0, 10);
const date = new Date(value);
if (!Number.isNaN(date.getTime())) return date.toISOString().slice(0, 10);
return value.slice(0, 10);
}
private snapshotWithUrls(input: unknown) {
const snapshot = input as ArtworkSnapshot | Record<string, never>;
if (!('artwork' in snapshot)) return snapshot;