添加根据合同/卷宗的入口进行分类评查点列表,同时区分卷宗添加的分组属于卷宗,合同添加的分组属于合同

This commit is contained in:
2025-10-29 21:01:01 +08:00
parent e56d199c3c
commit 064f05ffa5
3 changed files with 50 additions and 19 deletions
+8 -1
View File
@@ -24,6 +24,7 @@ export interface ApiRuleGroup {
code?: string;
description?: string;
is_enabled: boolean;
m_type?: number; // 文档类型:0=合同,1=其他
created_at?: string;
updated_at?: string;
}
@@ -35,6 +36,7 @@ export interface RuleGroupCreateUpdateDto {
pid: string | null; // 父分组ID,如果是一级分组则为null或'0'
description?: string;
is_enabled: boolean;
reviewType?: string; // 审核类型:'contract'=合同,其他为卷宗
}
// 用于替换代码中的 any 类型
@@ -446,13 +448,18 @@ export async function createRuleGroup(groupData: RuleGroupCreateUpdateDto, token
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
is_enabled: groupData.is_enabled,
m_type: mType
};
// console.log('创建评查点分组请求数据:', JSON.stringify(apiGroup, null, 2));
+15 -12
View File
@@ -213,12 +213,12 @@ export async function getRulesList(params: RulesQueryParams): Promise<{data: Rul
if (reviewType) {
try {
// 先获取所有评查点组数据,用于找到对应的pid
const groupsAllResponse = await postgrestGet<{code: number; msg: string; data: Array<{id: number; pid: number}>}>('evaluation_point_groups', {
select: 'id,pid',
const groupsAllResponse = await postgrestGet<{code: number; msg: string; data: Array<{id: number; pid: number; m_type: number}>}>('evaluation_point_groups', {
select: 'id,pid,m_type',
token
});
let groups: Array<{id: number; pid: number}> = [];
let groups: Array<{id: number; pid: number; m_type: number}> = [];
if (!groupsAllResponse.error) {
if (groupsAllResponse.data && 'code' in groupsAllResponse.data && groupsAllResponse.data.data) {
@@ -232,12 +232,14 @@ export async function getRulesList(params: RulesQueryParams): Promise<{data: Rul
let pidList: number[] = [];
if (reviewType === 'contract') {
// 合同类型,找到所有pid=3的评查点组
const contractGroups = groups.filter(g => g.pid === 3).map(g => g.id);
// 合同类型,找到所有pid=3的评查点组 2025/10/29: 修改为通过m_type = 0 去查找评查点组
// const contractGroups = groups.filter(g => g.pid === 3).map(g => g.id);
const contractGroups = groups.filter(g => g.m_type === 0).map(g => g.id);
pidList = contractGroups;
} else if (reviewType === 'record') {
// 卷宗类型,找到所有pid=1或pid=2的评查点组
const recordGroups = groups.filter(g => g.pid === 1 || g.pid === 2).map(g => g.id);
// 卷宗类型,找到所有pid=1或pid=2的评查点组 2025/10/29: 修改为通过m_type = 1 去查找评查点组
// const recordGroups = groups.filter(g => g.pid === 1 || g.pid === 2).map(g => g.id);
const recordGroups = groups.filter(g => g.m_type === 1).map(g => g.id);
pidList = recordGroups;
}
@@ -860,7 +862,8 @@ export async function getRuleTypes(reviewType?: string, token?: string): Promise
code,
name,
description,
is_enabled
is_enabled,
m_type
`,
// 查询父ID为0的类型(顶级类型)
filter: {
@@ -871,11 +874,11 @@ export async function getRuleTypes(reviewType?: string, token?: string): Promise
// 根据 reviewType 添加过滤条件
if (reviewType === 'contract') {
// 如果是合同类型,只加载id=3的评查点类型
postgrestParams.filter!['id'] = 'eq.3';
// 如果是合同类型,只加载id=3的评查点类型 2025/10/29: 修改为通过m_type = 0 去查找评查点组
postgrestParams.filter!['m_type'] = 'eq.0';
} else if (reviewType === 'record') {
// 如果是卷宗类型,只加载id=1和id=2的评查点类型
postgrestParams.filter!['id'] = 'in.(1,2)';
// 如果是卷宗类型,只加载id=1和id=2的评查点类型 2025/10/29: 修改为通过m_type = 1 去查找评查点组
postgrestParams.filter!['m_type'] = 'eq.1';
}
// 发送请求获取评查点类型列表
+27 -6
View File
@@ -162,6 +162,7 @@ export async function action({ request }: ActionFunctionArgs) {
const status = formData.get("status") as string || "active";
const groupType = formData.get("groupType") as string;
const parentId = groupType === "secondary" ? formData.get("parentId") as string : null;
const reviewType = formData.get("reviewType") as string || undefined;
// 表单验证
// action是处于服务端的表单提交方法,这里再次验证表单数据也是出于安全考虑,防止客户端验证被绕过从而提交非法数据
@@ -194,7 +195,8 @@ export async function action({ request }: ActionFunctionArgs) {
code: code.trim(),
description: description?.trim() || "",
is_enabled: status === "active",
pid: parentId === null ? "0" : parentId
pid: parentId === null ? "0" : parentId,
reviewType: reviewType // 传递 reviewType
};
try {
@@ -244,12 +246,15 @@ export default function RuleGroupNew() {
const userRole = rootData?.userRole || 'common';
// 判断表单是否为只读模式
// 判断表单是否为只读模式
const isReadOnly = userRole === 'common';
// 解构数据
const { group, parentGroups, isEdit, error } = data;
// 从 sessionStorage 获取 reviewType
const [reviewType, setReviewType] = useState<string | null>(null);
// 表单状态管理 - 使用受控组件
const [formValues, setFormValues] = useState<{
groupType: "primary" | "secondary";
@@ -309,7 +314,20 @@ export default function RuleGroupNew() {
});
}
}, [group]);
// 在组件挂载时从 sessionStorage 获取 reviewType
useEffect(() => {
try {
if (typeof window !== 'undefined') {
const storedReviewType = sessionStorage.getItem('reviewType');
// console.log("从 sessionStorage 获取 reviewType:", storedReviewType);
setReviewType(storedReviewType);
}
} catch (error) {
console.error('获取 sessionStorage 中的 reviewType 失败:', error);
}
}, []);
// 验证表单字段
const validateField = (field: string, value: string) => {
switch (field) {
@@ -471,7 +489,10 @@ export default function RuleGroupNew() {
<Form method="post" id="group-form" ref={formRef} onSubmit={handleBeforeSubmit}>
{/* 如果是编辑模式,添加ID */}
{group?.id && <input type="hidden" name="id" value={group.id} />}
{/* 传递 reviewType */}
{reviewType && <input type="hidden" name="reviewType" value={reviewType} />}
{/* 基本信息区域 */}
<Card className="form-section">
<div className="form-section-header">