完善气站资源列表搜索契约

This commit is contained in:
czl231
2026-08-19 22:07:00 +08:00
parent 72da8e9e47
commit 2f5b934037
10 changed files with 168 additions and 16 deletions

View File

@@ -5,6 +5,14 @@ import { fileURLToPath } from 'node:url';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const source = readFileSync(resolve(root, 'src/api/resources.ts'), 'utf8');
const routes = readFileSync(resolve(root, 'src/router/routes/modules/platform.ts'), 'utf8');
const searchSource = readFileSync(
resolve(root, 'src/views/shared/use-resource-list-search.ts'),
'utf8',
);
const listPageSource = readFileSync(
resolve(root, 'src/views/shared/CrudListPage.vue'),
'utf8',
);
const contract = JSON.parse(
readFileSync(resolve(root, 'src/contracts/gas-resources.json'), 'utf8'),
);
@@ -35,6 +43,18 @@ for (const item of contract.resources) {
throw new Error(`缺少后端资源路由:${item.name}`);
}
const staffSearchFields = backend.get('staff_account')?.searchFields ?? [];
if (staffSearchFields.map((field) => field.key).join(',') !== 'username,role_code')
throw new Error('工作人员搜索契约必须明确为:用户名、角色');
if ((backend.get('user_address')?.searchFields ?? []).length > 0)
throw new Error('不支持模糊搜索的用户地址资源不得公开搜索字段');
if (!searchSource.includes('searchableFields.value.length > 0'))
throw new Error('列表搜索必须由资源搜索契约决定是否显示');
if (searchSource.includes('关键字段模糊搜索'))
throw new Error('列表搜索不得使用含义不明确的兜底提示');
if (!listPageSource.includes('<a-form v-if="searchEnabled"'))
throw new Error('不支持搜索的资源必须隐藏完整搜索区域');
const forbidden = [
'/platform/platform_', '/gas/gas_', '/delivery/delivery_', '/staff/',
'/user/', '/ec/ec_', '/finance/fin_', '/wallet/wallet',