feat: 实现后台管理前端全部页面与登录布局

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nixevol
2026-06-28 16:52:41 +08:00
co-authored by Cursor
parent fa61840cfb
commit 5fa84f346b
40 changed files with 4481 additions and 1 deletions
+511
View File
@@ -0,0 +1,511 @@
<template>
<div class="page">
<div class="page-toolbar">
<n-button quaternary @click="router.back()">
<template #icon><n-icon :component="ArrowBackOutline" /></template>
{{ t('common.action.back') }}
</n-button>
<div class="page-title">{{ isNew ? t('pages.artwork.create') : t('pages.artwork.detail') }}</div>
</div>
<n-grid :cols="1" :y-gap="16">
<!-- 基础信息 -->
<n-grid-item>
<n-card :title="t('pages.artwork.basicInfo')" :bordered="false">
<n-form ref="formRef" :model="form" :rules="rules" label-placement="top">
<n-grid :cols="2" :x-gap="16" item-responsive responsive="screen">
<n-form-item-gi span="2 m:1" path="templateId" :label="t('pages.artwork.template')">
<n-select
v-model:value="form.templateId"
:options="templateOptions"
:disabled="!isNew"
@update:value="onTemplateChange"
/>
</n-form-item-gi>
<n-form-item-gi span="2 m:1" path="title" :label="t('pages.artwork.title')">
<n-input v-model:value="form.title" />
</n-form-item-gi>
<n-form-item-gi span="2 m:1" :label="t('pages.artwork.artist')">
<n-input v-model:value="form.artist" />
</n-form-item-gi>
<n-form-item-gi v-if="!isNew" span="2 m:1" :label="t('common.label.status')">
<n-select v-model:value="form.status" :options="statusOptions" />
</n-form-item-gi>
</n-grid>
<n-divider style="margin: 4px 0 16px">{{ t('pages.artwork.dynamicFields') }}</n-divider>
<n-grid :cols="2" :x-gap="16" item-responsive responsive="screen">
<n-form-item-gi v-for="f in currentFields" :key="f.fieldKey" span="2 m:1" :label="f.label">
<n-date-picker
v-if="f.type === 'DATE'"
v-model:formatted-value="form.dynamicFields[f.fieldKey]"
value-format="yyyy-MM-dd"
type="date"
style="width: 100%"
/>
<n-input
v-else-if="f.type === 'TEXTAREA'"
v-model:value="form.dynamicFields[f.fieldKey]"
type="textarea"
:rows="2"
/>
<n-input v-else v-model:value="form.dynamicFields[f.fieldKey]" />
</n-form-item-gi>
</n-grid>
<n-divider style="margin: 4px 0 16px">{{ t('pages.artwork.images') }}</n-divider>
<media-upload v-model="form.images" type="image" :max="8" />
</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>
<template v-if="!isNew">
<!-- 溯源时间轴 -->
<n-grid-item>
<n-card :title="t('pages.artwork.nodes')" :bordered="false">
<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="!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">
<template #header>
<div class="node-head">
<span>{{ t(`common.nodeType.${n.nodeType}`) }} · {{ n.title }}</span>
<span v-if="auth.canWrite" class="node-ops">
<n-button text size="tiny" @click="openNode(n)">{{ t('common.action.edit') }}</n-button>
<n-button text size="tiny" type="error" @click="removeNode(n)">{{ t('common.action.delete') }}</n-button>
</span>
</div>
</template>
<div class="node-meta">{{ [fmtDate(n.occurredAt), n.location].filter(Boolean).join(' · ') }}</div>
<div>{{ n.description }}</div>
<div class="node-media">
<n-image v-for="m in n.media" :key="m.url" :src="m.url" width="64" height="64" object-fit="cover" style="border-radius:6px" />
</div>
</n-timeline-item>
</n-timeline>
</n-card>
</n-grid-item>
<!-- 认证文件 -->
<n-grid-item>
<n-card :title="t('pages.artwork.certificates')" :bordered="false">
<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="!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-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%" />
<div v-else class="cert-pending">{{ t('pages.artwork.watermarkPending') }}</div>
</template>
<div class="cert-meta">{{ c.issuer || '-' }}</div>
<template #footer>
<n-button v-if="auth.canWrite" text size="tiny" type="error" @click="removeCert(c)">
{{ t('common.action.delete') }}
</n-button>
</template>
</n-card>
</n-grid-item>
</n-grid>
</n-card>
</n-grid-item>
<!-- 追溯码与区块链 -->
<n-grid-item>
<n-card :title="t('pages.artwork.traceCode') + ' / ' + t('pages.blockchain.title')" :bordered="false">
<div v-if="artwork?.traceCode">
<n-descriptions :column="3" label-placement="left" bordered size="small">
<n-descriptions-item :label="t('pages.traceCode.shortCode')">{{ artwork.traceCode.shortCode }}</n-descriptions-item>
<n-descriptions-item :label="t('common.label.status')">
<n-tag size="small" :type="statusType(artwork.traceCode.status)">{{ t(`common.status.${artwork.traceCode.status}`) }}</n-tag>
</n-descriptions-item>
<n-descriptions-item :label="t('pages.traceCode.queryCount')">{{ artwork.traceCode.queryCount }}</n-descriptions-item>
</n-descriptions>
<div style="margin-top:12px; display:flex; gap:8px; flex-wrap:wrap">
<n-button v-if="auth.canWrite" size="small" @click="unbind">{{ t('common.action.unbind') }}</n-button>
<n-button v-if="auth.canWrite" size="small" type="primary" :loading="onchainLoading" @click="onchain">
<template #icon><n-icon :component="LinkOutline" /></template>
{{ t('common.action.onchain') }}
</n-button>
</div>
<n-data-table
v-if="artwork.traceCode.proofs?.length"
style="margin-top:12px"
size="small"
:columns="proofColumns"
:data="artwork.traceCode.proofs"
:row-key="(r) => r.id"
/>
</div>
<div v-else>
<n-empty :description="t('pages.artwork.noTrace')" />
<div v-if="auth.canWrite" style="margin-top:12px; display:flex; gap:8px; align-items:center">
<n-select
v-model:value="bindCodeId"
:options="unboundOptions"
filterable
:placeholder="t('pages.traceCode.shortCode')"
style="width: 240px"
@focus="loadUnbound"
/>
<n-button type="primary" :disabled="!bindCodeId" @click="bind">{{ t('pages.artwork.bindCode') }}</n-button>
</div>
</div>
</n-card>
</n-grid-item>
</template>
</n-grid>
<!-- 节点弹窗 -->
<n-modal v-model:show="nodeModal" preset="card" :title="t('pages.artwork.addNode')" style="width:560px;max-width:94vw">
<n-form :model="nodeForm" label-placement="top">
<n-grid :cols="2" :x-gap="12">
<n-form-item-gi :label="t('common.label.type')">
<n-select v-model:value="nodeForm.nodeType" :options="nodeTypeOptions" />
</n-form-item-gi>
<n-form-item-gi :label="t('pages.artwork.nodeTitle')">
<n-input v-model:value="nodeForm.title" />
</n-form-item-gi>
<n-form-item-gi :label="t('pages.artwork.nodeTime')">
<n-date-picker v-model:formatted-value="nodeForm.occurredAt" value-format="yyyy-MM-dd" type="date" style="width:100%" />
</n-form-item-gi>
<n-form-item-gi :label="t('pages.artwork.nodeLocation')">
<n-input v-model:value="nodeForm.location" />
</n-form-item-gi>
</n-grid>
<n-form-item :label="t('pages.artwork.nodeDesc')">
<n-input v-model:value="nodeForm.description" type="textarea" :rows="2" />
</n-form-item>
<n-form-item :label="t('pages.artwork.images')">
<media-upload v-model="nodeForm.mediaFiles" type="image" :max="6" />
</n-form-item>
</n-form>
<template #footer>
<div style="text-align:right">
<n-button class="mr8" @click="nodeModal = false">{{ t('common.action.cancel') }}</n-button>
<n-button type="primary" :loading="nodeSaving" @click="saveNode">{{ t('common.action.save') }}</n-button>
</div>
</template>
</n-modal>
<!-- 证书弹窗 -->
<n-modal v-model:show="certModal" preset="card" :title="t('pages.artwork.addCert')" style="width:480px;max-width:94vw">
<n-form :model="certForm" label-placement="top">
<n-form-item :label="t('pages.artwork.certName')">
<n-input v-model:value="certForm.name" />
</n-form-item>
<n-form-item :label="t('pages.artwork.certIssuer')">
<n-input v-model:value="certForm.issuer" />
</n-form-item>
<n-form-item :label="t('pages.artwork.certType')">
<n-select v-model:value="certForm.type" :options="certTypeOptions" />
</n-form-item>
<n-form-item :label="t('pages.artwork.originFile')">
<media-upload v-model="certForm.files" type="image" :max="1" />
</n-form-item>
</n-form>
<template #footer>
<div style="text-align:right">
<n-button class="mr8" @click="certModal = false">{{ t('common.action.cancel') }}</n-button>
<n-button type="primary" :loading="certSaving" @click="saveCert">{{ t('common.action.save') }}</n-button>
</div>
</template>
</n-modal>
</div>
</template>
<script setup lang="ts">
import { computed, h, onMounted, reactive, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { NTag, type DataTableColumns, type FormInst, type FormRules } from 'naive-ui';
import { ArrowBackOutline, AddOutline, LinkOutline } from '@vicons/ionicons5';
import { ArtworkStatus, CertType, NodeType } from '@artveris/shared';
import { artworkApi, templateApi, traceCodeApi } from '@/api';
import { useAuthStore } from '@/stores/auth';
import MediaUpload from '@/components/MediaUpload.vue';
import { message, dialog } from '@/utils/feedback';
import { fmt, fmtDate, statusType } from '@/utils/format';
const { t } = useI18n();
const route = useRoute();
const router = useRouter();
const auth = useAuthStore();
const isNew = computed(() => route.params.id === 'new');
const artworkId = computed(() => Number(route.params.id));
const formRef = ref<FormInst | null>(null);
const form = reactive<any>({ templateId: null, title: '', artist: '', status: ArtworkStatus.DRAFT, dynamicFields: {}, images: [] });
const rules: FormRules = {
templateId: { required: true, type: 'number', message: () => t('pages.artwork.template'), trigger: 'change' },
title: { required: true, message: () => t('pages.artwork.title'), trigger: 'blur' },
};
const saving = ref(false);
const templates = ref<any[]>([]);
const templateOptions = computed(() => templates.value.map((x) => ({ label: x.name, value: x.id })));
const statusOptions = Object.values(ArtworkStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
const nodeTypeOptions = Object.values(NodeType).map((v) => ({ label: t(`common.nodeType.${v}`), value: v }));
const certTypeOptions = Object.values(CertType).map((v) => ({ label: v, value: v }));
const currentFields = computed(() => templates.value.find((x) => x.id === form.templateId)?.fields ?? []);
const artwork = ref<any>(null);
const nodes = ref<any[]>([]);
const certs = ref<any[]>([]);
const proofColumns: DataTableColumns<any> = [
{ title: () => t('pages.blockchain.txHash'), key: 'txHash', ellipsis: { tooltip: true }, render: (r) => r.txHash || '-' },
{ title: () => t('pages.blockchain.blockHeight'), key: 'blockHeight', width: 120, render: (r) => r.blockHeight || '-' },
{
title: () => t('common.label.status'),
key: 'status',
width: 100,
render: (r) => h(NTag, { size: 'small', type: statusType(r.status) }, { default: () => t(`common.status.${r.status}`) }),
},
{ title: () => t('pages.blockchain.onchainAt'), key: 'onchainAt', width: 160, render: (r) => fmt(r.onchainAt) },
];
function onTemplateChange() {
form.dynamicFields = {};
}
async function loadTemplates() {
templates.value = await templateApi.options();
}
async function loadArtwork() {
const a: any = await artworkApi.get(artworkId.value);
artwork.value = a;
form.templateId = a.templateId;
form.title = a.title;
form.artist = a.artist;
form.status = a.status;
form.dynamicFields = a.dynamicFields || {};
form.images = a.images || [];
nodes.value = a.traceNodes || [];
certs.value = a.certificates || [];
}
async function saveBasic() {
try {
await formRef.value?.validate();
} catch {
return;
}
saving.value = true;
try {
const payload = {
templateId: form.templateId,
title: form.title,
artist: form.artist,
status: form.status,
dynamicFields: form.dynamicFields,
images: form.images.map((m: any) => ({ key: m.key, name: m.name })),
};
if (isNew.value) {
const created: any = await artworkApi.create(payload);
message.success(t('common.msg.created'));
router.replace(`/artworks/${created.id}`);
} else {
await artworkApi.update(artworkId.value, payload);
message.success(t('common.msg.saved'));
await loadArtwork();
}
} finally {
saving.value = false;
}
}
/* 节点 */
const nodeModal = ref(false);
const nodeSaving = ref(false);
const editingNode = ref<number | null>(null);
const nodeForm = reactive<any>({ nodeType: NodeType.CREATE, title: '', occurredAt: null, location: '', description: '', mediaFiles: [] });
function openNode(n?: any) {
editingNode.value = n?.id ?? null;
Object.assign(nodeForm, {
nodeType: n?.nodeType ?? NodeType.CREATE,
title: n?.title ?? '',
occurredAt: n?.occurredAt ? fmtDate(n.occurredAt) : null,
location: n?.location ?? '',
description: n?.description ?? '',
mediaFiles: n?.media ? n.media.map((m: any) => ({ key: m.key || m.url, url: m.url, name: m.name })) : [],
});
nodeModal.value = true;
}
async function saveNode() {
if (!nodeForm.title) {
message.error(t('pages.artwork.nodeTitle'));
return;
}
nodeSaving.value = true;
try {
const payload = {
nodeType: nodeForm.nodeType,
title: nodeForm.title,
occurredAt: nodeForm.occurredAt || undefined,
location: nodeForm.location,
description: nodeForm.description,
mediaFiles: nodeForm.mediaFiles.map((m: any) => ({ key: m.key, name: m.name, type: 'image' })),
};
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);
} finally {
nodeSaving.value = false;
}
}
function removeNode(n: any) {
dialog.warning({
title: t('common.action.delete'),
content: t('common.msg.confirmDelete'),
positiveText: t('common.action.confirm'),
negativeText: t('common.action.cancel'),
onPositiveClick: async () => {
await artworkApi.removeNode(n.id);
nodes.value = await artworkApi.listNodes(artworkId.value);
},
});
}
/* 证书 */
const certModal = ref(false);
const certSaving = ref(false);
const certForm = reactive<any>({ name: '', issuer: '', type: CertType.CERT, files: [] });
function openCert() {
Object.assign(certForm, { name: '', issuer: '', type: CertType.CERT, files: [] });
certModal.value = true;
}
async function saveCert() {
if (!certForm.name || !certForm.files.length) {
message.error(t('pages.artwork.certName'));
return;
}
certSaving.value = true;
try {
await artworkApi.createCert(artworkId.value, {
name: certForm.name,
issuer: certForm.issuer,
type: certForm.type,
originKey: certForm.files[0].key,
});
message.success(t('common.msg.created'));
certModal.value = false;
certs.value = await artworkApi.listCerts(artworkId.value);
} finally {
certSaving.value = false;
}
}
function removeCert(c: any) {
dialog.warning({
title: t('common.action.delete'),
content: t('common.msg.confirmDelete'),
positiveText: t('common.action.confirm'),
negativeText: t('common.action.cancel'),
onPositiveClick: async () => {
await artworkApi.removeCert(c.id);
certs.value = await artworkApi.listCerts(artworkId.value);
},
});
}
/* 追溯码 / 区块链 */
const bindCodeId = ref<string | null>(null);
const unbound = ref<any[]>([]);
const unboundOptions = computed(() => unbound.value.map((c) => ({ label: c.shortCode, value: c.id })));
const onchainLoading = ref(false);
async function loadUnbound() {
const res: any = await traceCodeApi.list({ status: 'UNBOUND', pageSize: 50 });
unbound.value = res.list;
}
async function bind() {
if (!bindCodeId.value) return;
await traceCodeApi.bind(bindCodeId.value, artworkId.value);
message.success(t('common.msg.saved'));
bindCodeId.value = null;
await loadArtwork();
}
async function unbind() {
if (!artwork.value?.traceCode) return;
await traceCodeApi.unbind(String(artwork.value.traceCode.id));
message.success(t('common.msg.saved'));
await loadArtwork();
}
async function onchain() {
if (!artwork.value?.traceCode) return;
onchainLoading.value = true;
try {
await traceCodeApi.onchain(String(artwork.value.traceCode.id));
message.success(t('pages.blockchain.triggered'));
setTimeout(loadArtwork, 1500);
} finally {
onchainLoading.value = false;
}
}
onMounted(async () => {
await loadTemplates();
if (!isNew.value) await loadArtwork();
});
</script>
<style scoped>
.page-title {
font-size: 16px;
font-weight: 600;
}
.mr8 {
margin-right: 8px;
}
.node-head {
display: flex;
justify-content: space-between;
gap: 8px;
}
.node-ops {
display: inline-flex;
gap: 8px;
}
.node-meta {
color: #8a8a8a;
font-size: 12px;
margin: 2px 0;
}
.node-media {
display: flex;
gap: 8px;
margin-top: 6px;
flex-wrap: wrap;
}
.cert-meta {
font-size: 12px;
color: #6b7280;
}
.cert-pending {
height: 140px;
display: flex;
align-items: center;
justify-content: center;
color: #9ca3af;
background: #f4f7fc;
}
</style>