feat: align frontend document and rule management flows
This commit is contained in:
@@ -2,6 +2,13 @@ import { postgrestGet, postgrestPut, type PostgrestParams } from '../postgrest-c
|
||||
import { apiRequest } from '../axios-client';
|
||||
import { formatDate } from '../../utils';
|
||||
|
||||
function buildMissingRuleGroupApiError(): { error: string; status: number } {
|
||||
return {
|
||||
error: '评查点分组接口未部署:后端 `GET /api/v3/evaluation-point-groups` 当前返回 404。',
|
||||
status: 404
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 评查点分组接口
|
||||
*/
|
||||
@@ -252,6 +259,9 @@ export async function getEvaluationPointGroups(
|
||||
|
||||
|
||||
if (response.error) {
|
||||
if (response.status === 404) {
|
||||
return buildMissingRuleGroupApiError();
|
||||
}
|
||||
console.error('❌ getEvaluationPointGroups 错误:', response.error);
|
||||
return { error: response.error, status: response.status };
|
||||
}
|
||||
@@ -274,8 +284,12 @@ export async function getEvaluationPointGroups(
|
||||
} catch (error) {
|
||||
console.error('❌ 获取一级分组列表出错:', error);
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '获取一级分组列表失败',
|
||||
status: 500
|
||||
...(error instanceof Error && error.message.includes('404')
|
||||
? buildMissingRuleGroupApiError()
|
||||
: {
|
||||
error: error instanceof Error ? error.message : '获取一级分组列表失败',
|
||||
status: 500
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -305,6 +319,9 @@ export async function getAllEvaluationPointGroups(
|
||||
});
|
||||
|
||||
if (response.error) {
|
||||
if (response.status === 404) {
|
||||
return buildMissingRuleGroupApiError();
|
||||
}
|
||||
return { error: response.error, status: response.status };
|
||||
}
|
||||
|
||||
@@ -337,6 +354,49 @@ export async function getAllEvaluationPointGroups(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按文档类型范围获取可用评查点分组(树形结构)
|
||||
*/
|
||||
export async function getEvaluationPointGroupsByDocumentTypes(
|
||||
documentTypeIds: number[],
|
||||
token?: string
|
||||
): Promise<{data: RuleGroup[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
if (!documentTypeIds || documentTypeIds.length === 0) {
|
||||
return { data: [] };
|
||||
}
|
||||
|
||||
const queryParams = new URLSearchParams();
|
||||
queryParams.append('document_type_ids', documentTypeIds.join(','));
|
||||
queryParams.append('include_disabled', 'false');
|
||||
queryParams.append('with_rule_count', 'false');
|
||||
|
||||
const response = await apiRequest<EvaluationPointGroupResponse[]>(
|
||||
`/api/v3/evaluation-point-groups/by-document-types?${queryParams.toString()}`,
|
||||
{
|
||||
method: 'GET',
|
||||
...(token ? { headers: { 'Authorization': `Bearer ${token}` } } : {})
|
||||
}
|
||||
);
|
||||
|
||||
if (response.error) {
|
||||
return { error: response.error, status: response.status };
|
||||
}
|
||||
|
||||
if (response.data && Array.isArray(response.data)) {
|
||||
return { data: response.data.map(convertApiGroupToRuleGroup) };
|
||||
}
|
||||
|
||||
return { error: '获取文档类型可用分组失败:返回数据格式不正确', status: 500 };
|
||||
} catch (error) {
|
||||
console.error('❌ 获取文档类型可用分组出错:', error);
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '获取文档类型可用分组失败',
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. 获取单个分组详情(FastAPI v3)
|
||||
* @param id 分组ID
|
||||
|
||||
Reference in New Issue
Block a user