完善气站资源列表搜索契约
This commit is contained in:
@@ -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',
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -30,19 +30,17 @@ export function useResourceListSearch(
|
||||
);
|
||||
return displayFields.value.filter((field) => searchableKeys.has(field.key));
|
||||
});
|
||||
// 气站 API 仍支持通用关键字查询;缺少细粒度搜索契约时保留原搜索入口。
|
||||
const searchEnabled = computed(() => true);
|
||||
const searchEnabled = computed(() => searchableFields.value.length > 0);
|
||||
const searchPlaceholder = computed(
|
||||
() => searchableFields.value.length
|
||||
? `可搜索:${searchableFields.value
|
||||
.map((field) => field.listLabel ?? field.label)
|
||||
.join('、')}`
|
||||
: '关键字段模糊搜索',
|
||||
() =>
|
||||
`可搜索:${searchableFields.value
|
||||
.map((field) => field.listLabel ?? field.label)
|
||||
.join('、')}`,
|
||||
);
|
||||
|
||||
/** 仅在当前资源支持搜索时返回去除首尾空格的关键字。 */
|
||||
function requestKeyword() {
|
||||
return filters.keyword.trim();
|
||||
return searchEnabled.value ? filters.keyword.trim() : '';
|
||||
}
|
||||
|
||||
/** 将受支持的搜索状态写入 URL,并移除无效或陈旧的 keyword。 */
|
||||
|
||||
Reference in New Issue
Block a user