Files
platforms/frontend/platform_admin/scripts/check-resource-pages.mjs
czl231 deea31d79e 修复合同详情字段中文显示
通用详情页复用中文字段字典,并为合同气瓶快照补充上下文名称。
合同状态按模型常量显示中文,数据库字段和 API 保持不变。
已通过资源页面检查、类型检查和生产构建。
2026-08-12 19:49:41 +08:00

70 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 功能:静态检查平台总后台全部标准资源是否具备独立记录页配置。
* 版本v1.2.0
*/
import { readFileSync, existsSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const contract = JSON.parse(readFileSync(resolve(root, 'src/contracts/platform-resources.json'), 'utf8'));
const routeSource = [
'platform.ts',
'finance-route.ts',
].map((file) => readFileSync(resolve(root, 'src/router/routes/modules', file), 'utf8')).join('\n');
const routeBuilderSource = readFileSync(resolve(root, 'src/router/routes/modules/resource-route-builder.ts'), 'utf8');
const ruleSource = readFileSync(resolve(root, 'src/api/resource-page-rules.ts'), 'utf8');
const listSource = readFileSync(resolve(root, 'src/views/shared/CrudListPage.vue'), 'utf8');
const detailSource = readFileSync(resolve(root, 'src/views/resource/ResourceDetailContent.vue'), 'utf8');
const displaySource = readFileSync(resolve(root, 'src/api/resource-display.ts'), 'utf8');
const treeResources = new Set(['ec_category', 'platform_menu']);
const listResources = contract.resources.filter((item) => !treeResources.has(item.name));
const createModes = new Set(['writable', 'editable', 'append_only', 'managed']);
const editModes = new Set(['writable', 'editable', 'managed']);
const editableResources = listResources.filter((item) => editModes.has(item.mode));
function fail(message) {
throw new Error(`资源独立页面检查失败:${message}`);
}
const missingRoutes = listResources
.filter((item) => !routeSource.includes(`'/${item.name}'`))
.map((item) => item.name);
if (missingRoutes.length) fail(`路由未覆盖 ${missingRoutes.join('、')}`);
const missingRules = editableResources
.filter((item) => !new RegExp(`\\n\\s*${item.name}:\\s*\\{`).test(ruleSource))
.map((item) => item.name);
if (missingRules.length) fail(`编辑字段规则未覆盖 ${missingRules.join('、')}`);
for (const marker of ["makeRecordRoute('create'", "makeRecordRoute('detail'", "makeRecordRoute('edit'"]) {
if (!routeBuilderSource.includes(marker)) fail(`通用路由生成器缺少 ${marker}`);
}
if (listSource.includes('<a-drawer')) fail('列表组件仍包含 CRUD Drawer');
if (
!listSource.includes(
'[() => props.definition.resource, () => staffType.value]',
)
) {
fail('工作人员角色菜单切换未触发列表重新加载');
}
if (existsSync(resolve(root, 'src/views/account/AccountProfilePage.vue'))) {
fail('旧账户资料组件仍存在,未统一到共享记录页');
}
if (!detailSource.includes('resourceFieldLabel(definition, column, collection.key)')) {
fail('聚合详情表格未按集合上下文解析中文字段名称');
}
for (const marker of [
"'gasorder_contract.products'",
"product_info_identity: '气瓶唯一标识'",
"product_code: '气瓶编码'",
"if (key === 'contract_status') return contractStatusLabel(Number(value))",
]) {
if (!displaySource.includes(marker)) fail(`合同详情中文展示缺少 ${marker}`);
}
const createCount = listResources.filter((item) => createModes.has(item.mode)).length;
console.log(
`资源独立页面检查通过:详情 ${listResources.length} 类,新建 ${createCount} 类,编辑 ${editableResources.length} 类。`,
);