feat: 优化默认建档模板和时间轴

This commit is contained in:
Nixevol
2026-07-05 01:21:34 +08:00
parent 7a51814307
commit b51f26213b
6 changed files with 74 additions and 11 deletions
+9 -1
View File
@@ -205,7 +205,15 @@
"edit": "Edit Template",
"namePlaceholder": "Enter template name",
"fieldKeyTip": "Unique key, e.g. craft",
"sortHint": "Field order = display order on consumer page; use arrows to reorder"
"sortHint": "Field order = display order on consumer page; use arrows to reorder",
"defaultFields": {
"craft": "Craft",
"year": "Creation Era / Release Time",
"size": "Dimensions",
"material": "Material / Medium",
"certificationOrg": "Certification Body",
"dataOwner": "Data Ownership"
}
},
"audit": {
"status": "Audit Status",
+9 -1
View File
@@ -205,7 +205,15 @@
"edit": "编辑模板",
"namePlaceholder": "请输入模板名称",
"fieldKeyTip": "英文唯一标识,如 craft",
"sortHint": "字段顺序即客户端展示顺序,可用上下箭头调整"
"sortHint": "字段顺序即客户端展示顺序,可用上下箭头调整",
"defaultFields": {
"craft": "工艺",
"year": "创作年代 / 出品时间",
"size": "规格尺寸",
"material": "材质 / 媒介",
"certificationOrg": "认证机构",
"dataOwner": "数据权属"
}
},
"audit": {
"status": "审核状态",
+14 -3
View File
@@ -60,7 +60,7 @@
<div v-for="(f, i) in form.fields" :key="i" class="field-row">
<span class="field-order">{{ i + 1 }}</span>
<n-input v-model:value="f.fieldKey" :placeholder="t('pages.template.fieldKeyTip')" style="width: 120px" />
<n-input v-model:value="f.label" :placeholder="t('pages.template.fieldLabel')" style="width: 110px" />
<n-input v-model:value="f.label" :placeholder="t('pages.template.fieldLabel')" style="width: 180px" />
<n-select v-model:value="f.type" :options="fieldTypeOptions" style="width: 110px" />
<n-checkbox v-model:checked="f.required">{{ t('pages.template.required') }}</n-checkbox>
<span class="field-ops">
@@ -133,6 +133,17 @@ const formRef = ref<FormInst | null>(null);
const form = reactive<{ name: string; remark: string; status: string; fields: any[] }>({ name: '', remark: '', status: 'ENABLED', fields: [] });
const rules: FormRules = { name: { required: true, message: () => t('pages.template.namePlaceholder'), trigger: 'blur' } };
function createDefaultTemplateFields() {
return [
{ fieldKey: 'craft', label: t('pages.template.defaultFields.craft'), type: FieldType.TEXT, required: true },
{ fieldKey: 'year', label: t('pages.template.defaultFields.year'), type: FieldType.TEXT, required: false },
{ fieldKey: 'size', label: t('pages.template.defaultFields.size'), type: FieldType.TEXT, required: false },
{ fieldKey: 'material', label: t('pages.template.defaultFields.material'), type: FieldType.TEXT, required: false },
{ fieldKey: 'certificationOrg', label: t('pages.template.defaultFields.certificationOrg'), type: FieldType.TEXT, required: false },
{ fieldKey: 'dataOwner', label: t('pages.template.defaultFields.dataOwner'), type: FieldType.TEXT, required: false },
];
}
const columns: DataTableColumns<any> = [
{
title: 'ID',
@@ -246,7 +257,7 @@ function openCreate() {
form.name = '';
form.remark = '';
form.status = 'ENABLED';
form.fields = [{ fieldKey: '', label: '', type: FieldType.TEXT, required: false }];
form.fields = createDefaultTemplateFields();
showModal.value = true;
}
function openEdit(r: any) {
@@ -309,7 +320,7 @@ onMounted(load);
align-items: center;
gap: 8px;
margin-bottom: 8px;
min-width: 560px;
min-width: 660px;
}
.field-editor {
width: 100%;
+33 -6
View File
@@ -13,6 +13,14 @@ const ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
const shortId = customAlphabet(ALPHABET, 10);
const codeId = customAlphabet(ALPHABET, 18);
const watermarkText = process.env.WATERMARK_TEXT || '仅供溯源核验使用';
const DEFAULT_TEMPLATE_FIELDS = [
{ fieldKey: 'craft', label: '工艺', type: 'TEXT', required: true, sortOrder: 0 },
{ fieldKey: 'year', label: '创作年代 / 出品时间', type: 'TEXT', required: false, sortOrder: 1 },
{ fieldKey: 'size', label: '规格尺寸', type: 'TEXT', required: false, sortOrder: 2 },
{ fieldKey: 'material', label: '材质 / 媒介', type: 'TEXT', required: false, sortOrder: 3 },
{ fieldKey: 'certificationOrg', label: '认证机构', type: 'TEXT', required: false, sortOrder: 4 },
{ fieldKey: 'dataOwner', label: '数据权属', type: 'TEXT', required: false, sortOrder: 5 },
] as const;
function writeStorage(key: string, buf: Buffer): string {
const full = join(storageDir, key);
@@ -70,9 +78,33 @@ async function ensureSettings(): Promise<void> {
}
}
async function ensureTemplateDefaultFields(templateId: number): Promise<void> {
const existing = await prisma.templateField.findMany({ where: { templateId } });
const byKey = new Map(existing.map((field) => [field.fieldKey, field]));
for (const field of DEFAULT_TEMPLATE_FIELDS) {
const current = byKey.get(field.fieldKey);
if (current) {
await prisma.templateField.update({
where: { id: current.id },
data: {
label: field.label,
type: field.type,
required: field.required,
sortOrder: field.sortOrder,
},
});
} else {
await prisma.templateField.create({
data: { ...field, templateId },
});
}
}
}
async function ensureSampleData(): Promise<void> {
const existing = await prisma.template.findFirst({ where: { name: '陶瓷溯源模板' } });
if (existing) {
await ensureTemplateDefaultFields(existing.id);
console.log('示例数据已存在,跳过。');
return;
}
@@ -84,12 +116,7 @@ async function ensureSampleData(): Promise<void> {
name: '陶瓷溯源模板',
remark: '适用于陶瓷类艺术品',
fields: {
create: [
{ fieldKey: 'craft', label: '工艺', type: 'TEXT', required: true, sortOrder: 0 },
{ fieldKey: 'material', label: '材质', type: 'TEXT', sortOrder: 1 },
{ fieldKey: 'size', label: '规格尺寸', type: 'TEXT', sortOrder: 2 },
{ fieldKey: 'year', label: '创作年代', type: 'TEXT', sortOrder: 3 },
],
create: DEFAULT_TEMPLATE_FIELDS.map((field) => ({ ...field })),
},
},
});
+8
View File
@@ -14,6 +14,13 @@ interface MediaItem {
type?: string;
}
const DEFAULT_TRACE_NODES: Prisma.TraceNodeCreateWithoutArtworkInput[] = [
{ nodeType: 'CREATE', title: '创作 / 选胚', sortOrder: 0 },
{ nodeType: 'PRODUCE', title: '制作过程', sortOrder: 1 },
{ nodeType: 'STORAGE', title: '仓储 / 托管', sortOrder: 2 },
{ nodeType: 'OUTBOUND', title: '出库 / 流转', sortOrder: 3 },
];
@Injectable()
export class ArtworkService {
constructor(
@@ -46,6 +53,7 @@ export class ArtworkService {
dynamicFields: (dto.dynamicFields ?? {}) as Prisma.InputJsonValue,
images: (dto.images ?? []) as unknown as Prisma.InputJsonValue,
createdBy: userId,
traceNodes: { create: DEFAULT_TRACE_NODES },
},
});
// 创建后回填档案编号(需要自增 id)