Files
platforms/frontend/platform_admin/scripts/check-resource-search.mjs
2026-08-11 22:23:02 +08:00

41 lines
2.0 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.0.0
*/
import { readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const listPage = readFileSync(
resolve(root, 'src/views/shared/CrudListPage.vue'),
'utf8',
);
const searchState = readFileSync(
resolve(root, 'src/views/shared/use-resource-list-search.ts'),
'utf8',
);
const resources = readFileSync(resolve(root, 'src/api/resources.ts'), 'utf8');
const expectations = [
[listPage, 'v-if="searchEnabled"', '不支持搜索时隐藏表单'],
[listPage, ':placeholder="searchPlaceholder"', '动态显示可搜索字段'],
[listPage, 'const keyword = requestKeyword();', '只发送受支持的关键字'],
[searchState, 'definition.value.searchFields', '读取后端搜索契约'],
[searchState, 'resourceListDisplayFields', '搜索字段与实际列表列求交集'],
[searchState, 'if (searchEnabled.value || !route.query.keyword) return;', '清理不支持页面的陈旧关键字'],
[searchState, '`可搜索:${searchableFields.value', '明确列出可搜索中文字段'],
[resources, 'searchFields: resourceSearchFields(name)', '资源定义消费后端搜索契约'],
[resources, "resourceSearchEnumOptions('staff_account', 'role_code')", '工作人员中文角色与搜索契约同源'],
[resources, "resourceSearchEnumOptions('gasorder_basic', 'creator_type')", '订单创建方中文枚举与搜索契约同源'],
];
for (const [content, fragment, description] of expectations) {
if (!content.includes(fragment)) throw new Error(`资源搜索检查失败:${description}`);
}
if (listPage.includes('关键字段模糊搜索')) {
throw new Error('仍存在未说明具体字段的旧搜索提示');
}
console.log('资源搜索检查通过动态提示、隐藏逻辑、URL 清理和中文枚举均已覆盖');