feat: 1. 完善文档列表的显示效果,数据对接后端接口返回。

2. 对评查点分组和文档类型的编辑删除新增操作进行限制。
This commit is contained in:
2025-11-20 15:26:11 +08:00
parent 2edde8a8ab
commit 6dc9b4e468
11 changed files with 549 additions and 575 deletions
+27 -30
View File
@@ -24,7 +24,6 @@ export interface ApiRuleGroup {
code?: string;
description?: string;
is_enabled: boolean;
m_type?: number; // 文档类型:0=合同,1=其他
created_at?: string;
updated_at?: string;
}
@@ -36,7 +35,6 @@ export interface RuleGroupCreateUpdateDto {
pid: string | null; // 父分组ID,如果是一级分组则为null或'0'
description?: string;
is_enabled: boolean;
reviewType?: string; // 审核类型:'contract'=合同,其他为卷宗
}
// 用于替换代码中的 any 类型
@@ -289,8 +287,8 @@ export async function getAllRuleGroups(token?: string): Promise<{data: RuleGroup
}));
}
// 3. 构建树形结构
const parentGroups = allGroups.filter(group => group.pid === '0');
// 3. 构建树形结构pid为NULL表示顶级分组)
const parentGroups = allGroups.filter(group => !group.pid || group.pid === '0' || group.pid === null);
// 4. 为每个父分组添加子分组
for (const parent of parentGroups) {
@@ -396,8 +394,8 @@ export async function getRuleGroup(id: string, token?: string): Promise<{data: R
return { error: '未找到指定分组', status: 404 };
}
// 如果是父分组,获取评查点数量
if (group.pid === '0') {
// 如果是父分组(顶级分组,pid为NULL或'0',获取评查点数量
if (!group.pid || group.pid === '0' || group.pid === null) {
const ruleCountParams: PostgrestParams = {
select: 'id',
filter: {
@@ -436,30 +434,29 @@ export async function createRuleGroup(groupData: RuleGroupCreateUpdateDto, token
return { error: '分组名称和编码不能为空', status: 400 };
}
// 确保 pid 是合法值
let pidValue: number;
// 🆕 确保 pid 是合法值NULL表示顶级分组)
let pidValue: number | null;
try {
pidValue = groupData.pid ? Number(groupData.pid) : 0;
if (isNaN(pidValue)) {
return { error: '父分组ID必须是有效的数字', status: 400 };
if (!groupData.pid || groupData.pid === '0') {
pidValue = null; // 顶级分组
} else {
pidValue = Number(groupData.pid);
if (isNaN(pidValue)) {
return { error: '父分组ID必须是有效的数字', status: 400 };
}
}
} catch (error) {
console.error('父分组ID转换失败:', error);
return { error: '父分组ID格式错误', status: 400 };
}
// 根据 reviewType 确定 m_type 的值
// contract -> 0, 其他 -> 1
const mType = groupData.reviewType === 'contract' ? 0 : 1;
// 构建API请求数据 - 确保字段类型符合数据库要求
const apiGroup: ApiRuleGroup = {
pid: pidValue,
name: groupData.name.trim(),
code: groupData.code.trim(),
description: groupData.description || '',
is_enabled: groupData.is_enabled,
m_type: mType
is_enabled: groupData.is_enabled
};
// console.log('创建评查点分组请求数据:', JSON.stringify(apiGroup, null, 2));
@@ -489,7 +486,7 @@ export async function createRuleGroup(groupData: RuleGroupCreateUpdateDto, token
// 构建返回对象
const createdGroup: RuleGroup = {
id: apiResponse.id?.toString() || '',
pid: apiResponse.pid?.toString() || '0', // 兼容没有 pid 的情况
pid: apiResponse.pid?.toString() || '', // 🆕 NULL 转换为空字符串(表示顶级分组)
name: apiResponse.name || '',
code: apiResponse.code?.toString() || '', // 处理可能的数字类型
description: apiResponse.description,
@@ -521,24 +518,24 @@ export async function updateRuleGroup(id: string, data: RuleGroupCreateUpdateDto
return { error: '分组名称和编码不能为空', status: 400 };
}
// 根据 reviewType 确定 m_type 的值
// contract -> 0, 其他 -> 1
const mType = data.reviewType === 'contract' ? 0 : 1;
// 构建符合数据库结构的对象
const apiGroup: Partial<ApiRuleGroup> = {
name: data.name.trim(),
code: data.code.trim(),
description: data.description || '',
is_enabled: data.is_enabled,
m_type: mType // 使用 m_type 而不是 reviewType
is_enabled: data.is_enabled
};
// 如果需要更新父分组,添加 pid
// 🆕 如果需要更新父分组,添加 pidNULL表示顶级分组)
if (data.pid !== undefined) {
const pidValue = data.pid ? Number(data.pid) : 0;
if (isNaN(pidValue)) {
return { error: '父分组ID必须是有效的数字', status: 400 };
let pidValue: number | null;
if (!data.pid || data.pid === '0') {
pidValue = null; // 顶级分组
} else {
pidValue = Number(data.pid);
if (isNaN(pidValue)) {
return { error: '父分组ID必须是有效的数字', status: 400 };
}
}
apiGroup.pid = pidValue;
}
@@ -590,8 +587,8 @@ export async function deleteRuleGroup(id: string, token?: string): Promise<{succ
return { success: false, error: '未找到指定分组' };
}
// 2. 如果是一级分组,需要先删除所有子分组
if (group.pid === '0') {
// 2. 如果是一级分组(顶级分组,pid为NULL或'0',需要先删除所有子分组
if (!group.pid || group.pid === '0' || group.pid === null) {
// 获取所有子分组
const childGroupsResponse = await getChildGroups(id, token);
if (childGroupsResponse.error) {