feat: 无修改时禁止提交审核
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user