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
+1
View File
@@ -133,6 +133,7 @@
- 国际化覆盖修复(2026-07-05):后台清理设置页、备份恢复、出库导入、退出确认、表头筛选等用户可见硬编码中文,统一迁入 `apps/admin/src/locales/zh-CN.json` / `en-US.json`;`renderTableFilterTitle` 使用当前 i18n 的“全部/筛选”。全局 `message/dialog/loadingBar` 的 `createDiscreteApi` 现在跟随当前语言、日期语言和主题,避免页面切英文但离散弹窗仍中文。请求拦截器新增错误码翻译优先级:后台接口返回 `code` 时优先使用 `common.errorCode.*`,英文界面下若后端未知 message 含中文则回退英文通用错误,避免中文业务异常直接出现在英文 UI。上传组件失败提示改为语言包文案。客户端首页语言切换按钮从 `SUPPORTED_LOCALES` 读取标签,客户端语言包中的语言名统一为“简体中文 / English”;隐私说明同步移除已废弃的“地区”记录口径。
- 浏览器标题同步(2026-07-05):后台登录页 `document.title` 使用系统设置中的平台名称;后台主布局标题规则为“当前菜单 - 平台名称”,并通过 `artveris-settings-updated` 事件在保存系统设置后同步更新。客户端首页标题使用公开设置中的平台名称;客户端溯源详情页在查询到有效档案后把浏览器标题设置为当前 `artwork.archiveNo`,异常/加载失败时回退平台名称。
- 备份覆盖率加固(2026-07-05):备份数据库清单现在会在创建备份前对照 `Prisma.ModelName` 做覆盖校验,除 `BackupRecord`(备份包自身元数据,恢复旧路径会产生坏记录)外,所有业务模型必须在备份清单中,否则直接报错阻止生成不完整备份。`systemSetting` 备份不再只导出数据库已有行,而是导出 `SettingsService.getAll()` 的有效设置全集,确保平台名称、系统图标、备案信息、日志保留、备份策略、轮播间隔等默认但未保存过的设置也能随备份迁移。文件备份仍覆盖本地 `storage` 全目录,但会显式排除 `backupRoot`,避免 `BACKUP_DIR` 被配置到 storage 下时把旧备份包递归打进新备份;恢复清理 storage 时也保留 backupRoot。
- 默认建档体验(2026-07-05):对照甲方原版 PRD §3.1.2/§3.2,新建作品档案时后端会自动创建 4 个溯源时间轴节点骨架:创作/选胚、制作过程、仓储/托管、出库/流转;默认节点只含标题/类型/排序,不预填图片、时间、地点、说明等真实内容,运营可编辑、补充或删除。默认动态字段口径调整为只包含模板字段:工艺、创作年代/出品时间、规格尺寸、材质/媒介、认证机构、数据权属;作品名称、艺术家、档案编号、批次编号分别由固定字段、自动档案号和批次/追溯码管理承载,不再重复进动态字段。新建模板弹窗会按当前语言生成这些默认字段;seed 幂等补齐既有“陶瓷溯源模板”的缺失默认字段。
## 当前代码基准与注意事项
+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)