Files
platforms/frontend/platform_admin/scripts/check-resource-pages.mjs
czl231 a37b147f5f 修复:工作人员列表切换后自动加载数据
监听工作人员类型变化,切换安装、配送和运维菜单时自动重置搜索及页码并重新查询;补充资源、搜索和人员关联回归检查,同时更新中文需求说明与操作日志。
2026-08-11 22:38:20 +08:00

57 lines
2.6 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.1.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 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('旧账户资料组件仍存在,未统一到共享记录页');
}
const createCount = listResources.filter((item) => createModes.has(item.mode)).length;
console.log(
`资源独立页面检查通过:详情 ${listResources.length} 类,新建 ${createCount} 类,编辑 ${editableResources.length} 类。`,
);