基础组件完善
This commit is contained in:
@@ -1,182 +1,57 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
|
||||
import type { EvaluationPoint } from '~/models/evaluation_points';
|
||||
import type { EvaluationPointGroup } from '~/models/evaluation_point_groups';
|
||||
interface BasicInfoProps {
|
||||
onChange?: (data: Record<string, unknown>) => void;
|
||||
initialData?: FormDataType;
|
||||
evaluationPointGroups?: Array<{id: number, pid: number, code: string, name: string, is_enabled: boolean}>;
|
||||
initialData?: EvaluationPoint;
|
||||
evaluationPointGroups?: EvaluationPointGroup[];
|
||||
riskOptions?: Array<{value: string, label: string}>;
|
||||
}
|
||||
|
||||
// 定义表单数据类型
|
||||
interface FormDataType {
|
||||
name: string;
|
||||
code: string;
|
||||
risk: string;
|
||||
is_enabled: boolean;
|
||||
description: string;
|
||||
references_laws: {
|
||||
name: string;
|
||||
articles: string[];
|
||||
content: string;
|
||||
};
|
||||
evaluation_point_groups_id: number | null;
|
||||
evaluation_point_groups_pid: number | null;
|
||||
type: string;
|
||||
id?: number;
|
||||
}
|
||||
|
||||
export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }: BasicInfoProps) {
|
||||
const [formData, setFormData] = useState<FormDataType>({
|
||||
name: '',
|
||||
code: '',
|
||||
risk: 'medium',
|
||||
is_enabled: true,
|
||||
description: '',
|
||||
references_laws: {
|
||||
name: '',
|
||||
articles: [],
|
||||
content: ''
|
||||
},
|
||||
evaluation_point_groups_id: null,
|
||||
evaluation_point_groups_pid: null,
|
||||
type: ''
|
||||
// 评查点基本信息组件
|
||||
export function BasicInfo({ onChange, initialData, evaluationPointGroups = [], riskOptions = [] }: BasicInfoProps) {
|
||||
const [formData, setFormData] = useState<EvaluationPoint>({
|
||||
risk: 'medium', // 风险等级 默认中风险
|
||||
is_enabled: true, // 是否启用 默认启用
|
||||
...(initialData || {}) // 合并初始数据
|
||||
});
|
||||
|
||||
// 找到当前评查点类型对应的code
|
||||
const getCheckpointTypeCode = () => {
|
||||
if (!formData.evaluation_point_groups_pid) return "";
|
||||
|
||||
const typeGroup = evaluationPointGroups.find(
|
||||
group => group.id === formData.evaluation_point_groups_pid && group.pid === 0
|
||||
);
|
||||
|
||||
return typeGroup?.code || "";
|
||||
};
|
||||
|
||||
// 评查点描述与法律依据 展开状态
|
||||
const [isDescExpanded, setIsDescExpanded] = useState(false);
|
||||
const [lawArticlesInput, setLawArticlesInput] = useState('');
|
||||
const [filteredRuleGroups, setFilteredRuleGroups] = useState<Array<{id: number, pid: number, code: string, name: string, is_enabled: boolean}>>([]);
|
||||
|
||||
// 条款号临时输入字符串(不会触发自动分割)
|
||||
const [lawArticlesText, setLawArticlesText] = useState('');
|
||||
|
||||
// 当initialData变化时更新表单数据
|
||||
useEffect(() => {
|
||||
if (initialData) {
|
||||
const newFormData = {
|
||||
name: initialData.name || '',
|
||||
code: initialData.code || '',
|
||||
risk: initialData.risk || 'medium',
|
||||
is_enabled: initialData.is_enabled !== undefined ? initialData.is_enabled : true,
|
||||
description: initialData.description || '',
|
||||
references_laws: initialData.references_laws || {
|
||||
name: '',
|
||||
articles: [],
|
||||
content: ''
|
||||
},
|
||||
evaluation_point_groups_id: initialData.evaluation_point_groups_id || null,
|
||||
evaluation_point_groups_pid: initialData.evaluation_point_groups_pid || null,
|
||||
type: initialData.type || ''
|
||||
};
|
||||
|
||||
setFormData(newFormData);
|
||||
|
||||
// 更新法律条款输入框
|
||||
if (initialData.references_laws && Array.isArray(initialData.references_laws.articles)) {
|
||||
setLawArticlesInput(initialData.references_laws.articles.join(','));
|
||||
}
|
||||
|
||||
// 如果有描述或法律依据,默认展开详细信息
|
||||
if (initialData.description ||
|
||||
(initialData.references_laws &&
|
||||
(initialData.references_laws.name ||
|
||||
initialData.references_laws.content ||
|
||||
(initialData.references_laws.articles && initialData.references_laws.articles.length > 0)))) {
|
||||
setIsDescExpanded(true);
|
||||
}
|
||||
}
|
||||
}, [initialData]);
|
||||
|
||||
// 当评查点类型或评查点组数据变化时,过滤规则组列表
|
||||
useEffect(() => {
|
||||
if (evaluationPointGroups && evaluationPointGroups.length > 0) {
|
||||
console.log("评查点组数据更新,当前类型:", formData.type);
|
||||
console.log("评查点组数据:", evaluationPointGroups);
|
||||
|
||||
if (formData.type) {
|
||||
// 获取所选评查点类型的组ID
|
||||
const typeGroup = evaluationPointGroups.find(group =>
|
||||
group.pid === 0 &&
|
||||
group.code === formData.type
|
||||
);
|
||||
|
||||
console.log("找到的类型组:", typeGroup);
|
||||
|
||||
if (typeGroup) {
|
||||
// 更新评查点类型组ID
|
||||
if (formData.evaluation_point_groups_pid !== typeGroup.id) {
|
||||
const newData = {
|
||||
...formData,
|
||||
evaluation_point_groups_pid: typeGroup.id
|
||||
};
|
||||
setFormData(newData);
|
||||
if (onChange) onChange(newData);
|
||||
}
|
||||
|
||||
// 过滤出属于该类型的规则组(pid等于类型组ID的项)
|
||||
const groups = evaluationPointGroups.filter(group =>
|
||||
group.pid === typeGroup.id &&
|
||||
group.is_enabled
|
||||
);
|
||||
console.log("过滤后的规则组:", groups);
|
||||
setFilteredRuleGroups(groups);
|
||||
|
||||
// 如果当前选择的规则组不在过滤结果中,重置选择
|
||||
if (formData.evaluation_point_groups_id &&
|
||||
!groups.some(group => group.id === formData.evaluation_point_groups_id)) {
|
||||
console.log("当前选择的规则组不在过滤结果中,重置选择");
|
||||
const newData = {
|
||||
...formData,
|
||||
evaluation_point_groups_id: null
|
||||
};
|
||||
setFormData(newData);
|
||||
if (onChange) onChange(newData);
|
||||
}
|
||||
} else {
|
||||
console.log("未找到对应的类型组");
|
||||
setFilteredRuleGroups([]);
|
||||
|
||||
// 重置评查点类型组ID
|
||||
if (formData.evaluation_point_groups_pid !== null) {
|
||||
const newData = {
|
||||
...formData,
|
||||
evaluation_point_groups_pid: null
|
||||
};
|
||||
setFormData(newData);
|
||||
if (onChange) onChange(newData);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log("未选择评查点类型");
|
||||
setFilteredRuleGroups([]);
|
||||
|
||||
// 重置评查点类型组ID
|
||||
if (formData.evaluation_point_groups_pid !== null) {
|
||||
const newData = {
|
||||
...formData,
|
||||
evaluation_point_groups_pid: null
|
||||
};
|
||||
setFormData(newData);
|
||||
if (onChange) onChange(newData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [formData.type, evaluationPointGroups, formData.evaluation_point_groups_id, formData.evaluation_point_groups_pid, onChange]);
|
||||
// 根据选择的评查点类型筛选可用的规则组
|
||||
const filteredRuleGroups = evaluationPointGroups.filter(group =>
|
||||
formData.evaluation_point_groups_pid &&
|
||||
group.pid === formData.evaluation_point_groups_pid &&
|
||||
group.is_enabled
|
||||
);
|
||||
|
||||
// 获取评查点类型选项(pid=0的数据)
|
||||
const getCheckpointTypeOptions = () => {
|
||||
if (!evaluationPointGroups || evaluationPointGroups.length === 0) {
|
||||
console.log("无评查点组数据,使用默认类型选项");
|
||||
return (
|
||||
<>
|
||||
<option value="">请选择评查点类型</option>
|
||||
<option value="essential">基本要素类</option>
|
||||
<option value="content">内容合规类</option>
|
||||
<option value="format">格式规范类</option>
|
||||
<option value="legal">法律风险类</option>
|
||||
<option value="business">业务专项类</option>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const typeGroups = evaluationPointGroups.filter(group => group.pid === 0 && group.is_enabled);
|
||||
console.log("可用的评查点类型:", typeGroups);
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<option value="">请选择评查点类型</option>
|
||||
@@ -189,14 +64,15 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }:
|
||||
);
|
||||
};
|
||||
|
||||
// 评查点描述与法律依据 展开状态
|
||||
const handleToggleDescription = () => {
|
||||
setIsDescExpanded(!isDescExpanded);
|
||||
};
|
||||
|
||||
// 处理表单输入变化
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => {
|
||||
const { id, value } = e.target;
|
||||
const newData = { ...formData };
|
||||
|
||||
// 映射id到表单字段名
|
||||
switch(id) {
|
||||
case 'rule-name':
|
||||
@@ -214,32 +90,32 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }:
|
||||
case 'rule-description':
|
||||
newData.description = value;
|
||||
break;
|
||||
case 'law-name':
|
||||
newData.references_laws.name = value;
|
||||
case 'law-name':
|
||||
newData.references_laws = {
|
||||
...formData.references_laws,
|
||||
name: value
|
||||
};
|
||||
break;
|
||||
case 'law-content':
|
||||
newData.references_laws.content = value;
|
||||
break;
|
||||
case 'law-articles':
|
||||
setLawArticlesInput(value);
|
||||
case 'law-content':
|
||||
newData.references_laws = {
|
||||
...formData.references_laws,
|
||||
content: value
|
||||
};
|
||||
break;
|
||||
case 'evaluation-point-group':
|
||||
newData.evaluation_point_groups_id = value ? parseInt(value) : null;
|
||||
break;
|
||||
case 'checkpoint-type':
|
||||
newData.type = value;
|
||||
// 重置规则组选择
|
||||
newData.evaluation_point_groups_id = null;
|
||||
|
||||
// 设置评查点类型组ID
|
||||
// 处理评查点类型选择
|
||||
if (value) {
|
||||
const typeGroup = evaluationPointGroups.find(group =>
|
||||
group.pid === 0 &&
|
||||
group.code === value
|
||||
);
|
||||
newData.evaluation_point_groups_pid = typeGroup ? typeGroup.id : null;
|
||||
// 找到选中的类型组
|
||||
const selectedType = evaluationPointGroups.find(group => group.code === value && group.pid === 0);
|
||||
if (selectedType) {
|
||||
newData.evaluation_point_groups_pid = selectedType.id;
|
||||
}
|
||||
} else {
|
||||
newData.evaluation_point_groups_pid = null;
|
||||
newData.evaluation_point_groups_id = null; // 清空规则组选择
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -251,18 +127,32 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }:
|
||||
}
|
||||
};
|
||||
|
||||
const handleLawArticlesChange = (value: string) => {
|
||||
setLawArticlesInput(value);
|
||||
const articles = value.split(',')
|
||||
// 处理条款号输入框变化
|
||||
const handleLawArticlesChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
// 设置临时字符串状态,这样不会触发任何处理
|
||||
setLawArticlesText(e.target.value);
|
||||
};
|
||||
|
||||
// 处理条款号输入框失去焦点
|
||||
const handleLawArticlesBlur = () => {
|
||||
if (!lawArticlesText) return;
|
||||
|
||||
// 将输入的文本转换为数组
|
||||
const articles = lawArticlesText
|
||||
.split(',')
|
||||
.map(article => article.trim())
|
||||
.filter(article => article !== '');
|
||||
|
||||
|
||||
// 创建一个新的引用法律对象,保留现有字段
|
||||
const referencesLaws = {
|
||||
...(formData.references_laws || {}),
|
||||
articles: articles.length > 0 ? articles : []
|
||||
};
|
||||
|
||||
// 更新表单数据
|
||||
const newData = {
|
||||
...formData,
|
||||
references_laws: {
|
||||
...formData.references_laws,
|
||||
articles
|
||||
}
|
||||
references_laws: referencesLaws
|
||||
};
|
||||
|
||||
setFormData(newData);
|
||||
@@ -272,6 +162,33 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }:
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化条款号文本字段
|
||||
useEffect(() => {
|
||||
if (formData.references_laws?.articles && formData.references_laws.articles.length > 0) {
|
||||
setLawArticlesText(formData.references_laws.articles.join(','));
|
||||
}
|
||||
}, [formData.references_laws?.articles]);
|
||||
|
||||
// 检查是否需要自动展开描述区域
|
||||
useEffect(() => {
|
||||
// 如果描述或法律依据相关字段有值,则自动展开
|
||||
if (
|
||||
formData.description ||
|
||||
formData.references_laws?.name ||
|
||||
(formData.references_laws?.articles && formData.references_laws.articles.length > 0) ||
|
||||
formData.references_laws?.content
|
||||
) {
|
||||
setIsDescExpanded(true);
|
||||
}
|
||||
}, [formData]);
|
||||
|
||||
useEffect(() => {
|
||||
// 可以在这里通知父组件
|
||||
if (onChange && filteredRuleGroups.length === 1) {
|
||||
onChange({ evaluation_point_groups_id: filteredRuleGroups[0].id });
|
||||
}
|
||||
}, [filteredRuleGroups, onChange]);
|
||||
|
||||
return (
|
||||
<div className="ant-card">
|
||||
<div className="ant-card-header">
|
||||
@@ -317,9 +234,19 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }:
|
||||
value={formData.risk}
|
||||
onChange={handleInputChange}
|
||||
>
|
||||
<option value="high">高风险</option>
|
||||
<option value="medium">中风险</option>
|
||||
<option value="low">低风险</option>
|
||||
{riskOptions.length > 0 ? (
|
||||
riskOptions.map(option => (
|
||||
<option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))
|
||||
) : (
|
||||
<>
|
||||
<option value="high">高风险</option>
|
||||
<option value="medium">中风险</option>
|
||||
<option value="low">低风险</option>
|
||||
</>
|
||||
)}
|
||||
</select>
|
||||
<div className="form-tip">请定义评查点的风险等级</div>
|
||||
</div>
|
||||
@@ -330,7 +257,7 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }:
|
||||
<select
|
||||
id="checkpoint-type"
|
||||
className="form-select"
|
||||
value={formData.type}
|
||||
value={getCheckpointTypeCode()}
|
||||
onChange={handleInputChange}
|
||||
>
|
||||
{getCheckpointTypeOptions()}
|
||||
@@ -343,13 +270,13 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }:
|
||||
</label>
|
||||
<select
|
||||
id="evaluation-point-group"
|
||||
className={`form-select ${!formData.type || filteredRuleGroups.length === 0 ? 'bg-gray-100 cursor-not-allowed' : ''}`}
|
||||
className={`form-select ${!formData.evaluation_point_groups_pid || filteredRuleGroups.length === 0 ? 'bg-gray-100 cursor-not-allowed' : ''}`}
|
||||
value={formData.evaluation_point_groups_id?.toString() || ""}
|
||||
onChange={handleInputChange}
|
||||
disabled={!formData.type || filteredRuleGroups.length === 0}
|
||||
disabled={!formData.evaluation_point_groups_pid || filteredRuleGroups.length === 0}
|
||||
>
|
||||
<option value="">
|
||||
{!formData.type ? "请先选择评查点类型" :
|
||||
{!formData.evaluation_point_groups_pid ? "请先选择评查点类型" :
|
||||
filteredRuleGroups.length === 0 ? "该类型下暂无可用规则组" :
|
||||
"请选择规则组"}
|
||||
</option>
|
||||
@@ -360,7 +287,7 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }:
|
||||
))}
|
||||
</select>
|
||||
<div className="form-tip">
|
||||
{!formData.type ? "请先选择评查点类型" :
|
||||
{!formData.evaluation_point_groups_pid ? "请先选择评查点类型" :
|
||||
filteredRuleGroups.length === 0 ? "该类型下暂无可用规则组" :
|
||||
"选择评查点所属的规则组"}
|
||||
</div>
|
||||
@@ -420,20 +347,23 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }:
|
||||
className="form-input"
|
||||
placeholder="例如:《中华人民共和国民法典》"
|
||||
id="law-name"
|
||||
value={formData.references_laws.name}
|
||||
value={formData.references_laws?.name || ''}
|
||||
onChange={handleInputChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mb-3">
|
||||
<label className="text-sm text-gray-600 mb-1 block" htmlFor="law-articles">条款号 <span className="text-xs text-gray-400">(多个条款请用逗号分隔)</span></label>
|
||||
<label className="text-sm text-gray-600 mb-1 block" htmlFor="law-articles">
|
||||
条款号 <span className="text-xs text-gray-400">(多个条款请用逗号分隔)</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
placeholder="例如:第五百八十五条,第五百八十六条"
|
||||
id="law-articles"
|
||||
value={lawArticlesInput}
|
||||
onChange={(e) => handleLawArticlesChange(e.target.value)}
|
||||
value={lawArticlesText}
|
||||
onChange={handleLawArticlesChange}
|
||||
onBlur={handleLawArticlesBlur}
|
||||
/>
|
||||
<div className="form-tip">多个条款用逗号分隔,将自动转换为数组格式</div>
|
||||
</div>
|
||||
@@ -445,7 +375,7 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }:
|
||||
style={{ minHeight: '60px' }}
|
||||
placeholder="例如:当事人应当按照约定全面履行自己的义务。"
|
||||
id="law-content"
|
||||
value={formData.references_laws.content}
|
||||
value={formData.references_laws?.content || ''}
|
||||
onChange={handleInputChange}
|
||||
></textarea>
|
||||
</div>
|
||||
@@ -459,10 +389,10 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }:
|
||||
<div className="text-sm font-medium mb-2">预览效果</div>
|
||||
<div className="law-reference">
|
||||
<div className="law-reference-title" id="preview-law-name">
|
||||
{formData.references_laws.name || '《中华人民共和国民法典》'}
|
||||
{formData.references_laws?.name || '《中华人民共和国民法典》'}
|
||||
</div>
|
||||
<div className="law-reference-articles" id="preview-law-articles">
|
||||
{formData.references_laws.articles.length > 0 ?
|
||||
{formData.references_laws?.articles && formData.references_laws.articles.length > 0 ?
|
||||
formData.references_laws.articles.map((article, index) => (
|
||||
<span key={index} className="law-article">{article}</span>
|
||||
)) : (
|
||||
@@ -473,7 +403,7 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [] }:
|
||||
)}
|
||||
</div>
|
||||
<div className="law-reference-content" id="preview-law-content">
|
||||
{formData.references_laws.content || '当事人应当按照约定全面履行自己的义务。'}
|
||||
{formData.references_laws?.content || '当事人应当按照约定全面履行自己的义务。'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState, KeyboardEvent, FormEvent, useContext, useEffect, useCallback, useRef } from 'react';
|
||||
import { RuleContext } from '~/contexts/RuleContext';
|
||||
import { processFieldName } from '~/utils';
|
||||
import type { PromptType, VLMFieldType } from '~/models/evaluation_points';
|
||||
|
||||
// 定义通知函数的类型
|
||||
type NotifyFn = (data: Record<string, unknown>) => void;
|
||||
@@ -41,7 +42,7 @@ interface RegexField {
|
||||
|
||||
interface VlmField {
|
||||
name: string;
|
||||
type: string;
|
||||
type: VLMFieldType | string;
|
||||
}
|
||||
|
||||
interface PromptTemplate {
|
||||
@@ -72,9 +73,16 @@ interface ExtractionSettingsProps {
|
||||
fields?: RegexField[];
|
||||
};
|
||||
};
|
||||
promptTypeOptions?: Array<{value: string, label: string}>;
|
||||
vlmFieldTypeOptions?: Array<{value: string, label: string}>;
|
||||
}
|
||||
|
||||
export function ExtractionSettings({ onChange, initialData }: ExtractionSettingsProps) {
|
||||
export function ExtractionSettings({
|
||||
onChange,
|
||||
initialData,
|
||||
promptTypeOptions = [],
|
||||
vlmFieldTypeOptions = []
|
||||
}: ExtractionSettingsProps) {
|
||||
const ruleContext = useContext(RuleContext);
|
||||
const lastUpdateTimeRef = useRef(0); // 添加一个ref来记录上次更新时间
|
||||
const lastEventFieldsRef = useRef<string[]>([]);
|
||||
@@ -884,6 +892,62 @@ export function ExtractionSettings({ onChange, initialData }: ExtractionSettings
|
||||
setSelectedFieldType(e.currentTarget.value);
|
||||
};
|
||||
|
||||
// 在渲染选择模态字段类型的下拉列表时使用vlmFieldTypeOptions
|
||||
const renderVlmFieldTypeSelect = (field: string, index: number) => {
|
||||
return (
|
||||
<select
|
||||
className="form-select"
|
||||
value={selectedFieldType}
|
||||
onChange={handleFieldTypeChange}
|
||||
>
|
||||
{vlmFieldTypeOptions.length > 0 ? (
|
||||
vlmFieldTypeOptions.map(option => (
|
||||
<option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))
|
||||
) : (
|
||||
// 默认选项,如果没有提供字段类型选项
|
||||
<>
|
||||
<option value="default">默认</option>
|
||||
<option value="currency">货币</option>
|
||||
<option value="print">打印</option>
|
||||
<option value="seal">印章</option>
|
||||
<option value="cross-seal">骑缝章</option>
|
||||
<option value="english">英文</option>
|
||||
<option value="number">数字</option>
|
||||
<option value="handwriting">手写</option>
|
||||
</>
|
||||
)}
|
||||
</select>
|
||||
);
|
||||
};
|
||||
|
||||
// 在渲染提示词类型的选择器时使用promptTypeOptions
|
||||
const renderPromptTypeSelect = (type: string, promptType: 'llm' | 'vlm') => {
|
||||
return (
|
||||
<select
|
||||
className="form-select"
|
||||
value={type}
|
||||
onChange={(e) => handlePromptTypeChange(e, promptType)}
|
||||
>
|
||||
{promptTypeOptions.length > 0 ? (
|
||||
promptTypeOptions.map(option => (
|
||||
<option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))
|
||||
) : (
|
||||
// 默认选项,如果没有提供提示词类型选项
|
||||
<>
|
||||
<option value="system">使用系统默认提示词</option>
|
||||
<option value="custom">使用自定义提示词</option>
|
||||
</>
|
||||
)}
|
||||
</select>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="ant-card">
|
||||
<div className="ant-card-header">
|
||||
@@ -970,28 +1034,7 @@ export function ExtractionSettings({ onChange, initialData }: ExtractionSettings
|
||||
提示词设置
|
||||
</label>
|
||||
<div className="flex items-center mb-2" id="llm-prompt-settings">
|
||||
<label className="inline-flex items-center mr-6">
|
||||
<input
|
||||
type="radio"
|
||||
name="llm-prompt-type"
|
||||
value="system"
|
||||
checked={promptType.llm === 'system'}
|
||||
onChange={(e) => handlePromptTypeChange(e, 'llm')}
|
||||
className="form-radio"
|
||||
/>
|
||||
<span className="ml-2">使用系统默认提示词</span>
|
||||
</label>
|
||||
<label className="inline-flex items-center">
|
||||
<input
|
||||
type="radio"
|
||||
name="llm-prompt-type"
|
||||
value="custom"
|
||||
checked={promptType.llm === 'custom'}
|
||||
onChange={(e) => handlePromptTypeChange(e, 'llm')}
|
||||
className="form-radio"
|
||||
/>
|
||||
<span className="ml-2">使用自定义提示词</span>
|
||||
</label>
|
||||
{renderPromptTypeSelect(promptType.llm, 'llm')}
|
||||
</div>
|
||||
|
||||
<div
|
||||
@@ -1084,21 +1127,7 @@ export function ExtractionSettings({ onChange, initialData }: ExtractionSettings
|
||||
onChange={(e) => handleFieldInputChange(e, 'vlm')}
|
||||
onKeyDown={(e) => handleKeyDown(e, 'vlm')}
|
||||
/>
|
||||
<select
|
||||
className="form-select mr-2"
|
||||
id="field-type-vlm"
|
||||
value={selectedFieldType}
|
||||
onChange={handleFieldTypeChange}
|
||||
>
|
||||
<option value="default">默认</option>
|
||||
<option value="seal">印章</option>
|
||||
<option value="cross-seal">骑缝章</option>
|
||||
<option value="handwriting">手写体</option>
|
||||
<option value="print">印刷体</option>
|
||||
<option value="english">英文</option>
|
||||
<option value="number">数字</option>
|
||||
<option value="currency">货币</option>
|
||||
</select>
|
||||
{renderVlmFieldTypeSelect(inputValue.vlm, 0)}
|
||||
<button
|
||||
className="ant-btn ant-btn-default"
|
||||
id="add-field-btn-vlm"
|
||||
@@ -1143,28 +1172,7 @@ export function ExtractionSettings({ onChange, initialData }: ExtractionSettings
|
||||
提示词设置
|
||||
</label>
|
||||
<div className="flex items-center mb-2" id="multimodal-prompt-settings">
|
||||
<label className="inline-flex items-center mr-6">
|
||||
<input
|
||||
type="radio"
|
||||
name="multimodal-prompt-type"
|
||||
value="system"
|
||||
checked={promptType.vlm === 'system'}
|
||||
onChange={(e) => handlePromptTypeChange(e, 'vlm')}
|
||||
className="form-radio"
|
||||
/>
|
||||
<span className="ml-2">使用系统默认提示词</span>
|
||||
</label>
|
||||
<label className="inline-flex items-center">
|
||||
<input
|
||||
type="radio"
|
||||
name="multimodal-prompt-type"
|
||||
value="custom"
|
||||
checked={promptType.vlm === 'custom'}
|
||||
onChange={(e) => handlePromptTypeChange(e, 'vlm')}
|
||||
className="form-radio"
|
||||
/>
|
||||
<span className="ml-2">使用自定义提示词</span>
|
||||
</label>
|
||||
{renderPromptTypeSelect(promptType.vlm, 'vlm')}
|
||||
</div>
|
||||
<div
|
||||
className="bg-gray-50 p-2 rounded text-xs text-gray-600 mb-2"
|
||||
|
||||
@@ -2,6 +2,13 @@ import React, { useState, useEffect, useContext, useCallback, useRef } from 'rea
|
||||
import { SimpleCodeEditor } from './SimpleCodeEditor';
|
||||
import { RuleContext } from '~/contexts/RuleContext';
|
||||
import { processFieldNames, areArraysDifferent, getArrayDifference, debounce } from '~/utils';
|
||||
import type {
|
||||
Rule as ModelRule,
|
||||
RuleType as ModelRuleType,
|
||||
LogicType,
|
||||
SuggestionMessageType,
|
||||
PostActionType
|
||||
} from '~/models/evaluation_points';
|
||||
|
||||
interface RuleType {
|
||||
id: string;
|
||||
@@ -38,9 +45,31 @@ interface ReviewSettingsProps {
|
||||
score?: number;
|
||||
scoreDisplay?: string;
|
||||
};
|
||||
// 添加选项数据参数
|
||||
ruleTypeOptions?: Array<{ value: string; label: string }>;
|
||||
logicTypeOptions?: Array<{ value: string; label: string }>;
|
||||
logicOperatorOptions?: Array<{ value: string; label: string }>;
|
||||
compareMethodOptions?: Array<{ value: string; label: string }>;
|
||||
formatTypeOptions?: Array<{ value: string; label: string }>;
|
||||
comparisonOperatorOptions?: Array<{ value: string; label: string }>;
|
||||
matchTypeOptions?: Array<{ value: string; label: string }>;
|
||||
suggestionMessageTypeOptions?: Array<{ value: string; label: string }>;
|
||||
postActionOptions?: Array<{ value: string; label: string }>;
|
||||
}
|
||||
|
||||
export function ReviewSettings({ onChange, initialData }: ReviewSettingsProps) {
|
||||
export function ReviewSettings({
|
||||
onChange,
|
||||
initialData,
|
||||
ruleTypeOptions = [],
|
||||
logicTypeOptions = [],
|
||||
logicOperatorOptions = [],
|
||||
compareMethodOptions = [],
|
||||
formatTypeOptions = [],
|
||||
comparisonOperatorOptions = [],
|
||||
matchTypeOptions = [],
|
||||
suggestionMessageTypeOptions = [],
|
||||
postActionOptions = []
|
||||
}: ReviewSettingsProps) {
|
||||
const [rules, setRules] = useState<RuleType[]>([
|
||||
{ id: '1', type: '', config: {} }
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 评查点分组表
|
||||
*/
|
||||
interface EvaluationPointGroup {
|
||||
id: number; // 主键,自增
|
||||
pid: number | null; // 所属分组ID,外键引用本表,可为空
|
||||
code: string; // 分组编码,唯一且非空
|
||||
name: string; // 分组名称,非空
|
||||
description?: string; // 分组描述,可为空
|
||||
is_enabled: boolean; // 是否启用,默认true
|
||||
created_at: string; // 创建时间,带时区,默认当前时间
|
||||
updated_at: string; // 更新时间,带时区,默认当前时间
|
||||
}
|
||||
|
||||
export type { EvaluationPointGroup };
|
||||
@@ -0,0 +1,308 @@
|
||||
/**
|
||||
* 评查点数据类型定义
|
||||
*/
|
||||
interface EvaluationPoint {
|
||||
id?: number;
|
||||
name?: string; // 评查点名称
|
||||
code?: string; // 评查点编码
|
||||
risk?: string; // 风险级别
|
||||
is_enabled?: boolean; // 是否启用
|
||||
description?: string; // 描述
|
||||
references_laws?: { // 法律法规引用
|
||||
name?: string; // 法规名称
|
||||
articles?: string[]; // 条款列表
|
||||
content?: string; // 法规内容
|
||||
};
|
||||
evaluation_point_groups_pid?: number | null; // 评查点类型组ID
|
||||
evaluation_point_groups_id?: number | null; // 所属评查组ID
|
||||
extraction_config?: ExtactionConfigType; // 抽取配置
|
||||
evaluation_config?: EvaluationConfigType; // 评查配置
|
||||
pass_message?: string; // 通过消息
|
||||
fail_message?: string; // 失败消息
|
||||
suggestion_message?: string; // 建议消息
|
||||
suggestion_message_type?: SuggestionMessageType; // 建议消息类型 默认warning(info/warning/error)
|
||||
post_action?: PostActionType; // 评查后动作 可为空(none/manual/replace)
|
||||
action_config?: string; // 动作配置
|
||||
score?: number; // 分数
|
||||
}
|
||||
|
||||
/**
|
||||
* 风险级别类型定义
|
||||
*/
|
||||
type RiskLevelType = 'high' | 'medium' | 'low';
|
||||
|
||||
/**
|
||||
* 建议消息类型定义
|
||||
*/
|
||||
type SuggestionMessageType = 'info' | 'warning' | 'error';
|
||||
|
||||
/**
|
||||
* 评查后动作类型定义
|
||||
*/
|
||||
type PostActionType = 'none' | 'manual' | 'replace';
|
||||
|
||||
/**
|
||||
* 抽取配置类型定义
|
||||
*/
|
||||
interface ExtactionConfigType {
|
||||
llm: {
|
||||
fields: string[];
|
||||
prompt_setting: PromptSetting;
|
||||
};
|
||||
vlm: {
|
||||
fields: Array<{
|
||||
name: string;
|
||||
type: VLMFieldType; // 多模态字段类型 默认、货币、打印、印章、骑缝章、英文、数字、手写
|
||||
}>;
|
||||
prompt_setting: PromptSetting;
|
||||
};
|
||||
regex: {
|
||||
fields: Array<{
|
||||
field: string;
|
||||
pattern: string;
|
||||
}>;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* VLM字段类型定义
|
||||
*/
|
||||
type VLMFieldType = 'default' | 'currency' | 'print' | 'seal' | 'cross-seal' | 'english' | 'number' | 'handwriting';
|
||||
|
||||
/**
|
||||
* 提示配置类型定义
|
||||
*/
|
||||
interface PromptSetting {
|
||||
type: PromptType; // "system" or "custom" 如果为 "custom" 则为自定义提示
|
||||
template: string; // 提示模板
|
||||
}
|
||||
|
||||
/**
|
||||
* 提示类型定义
|
||||
*/
|
||||
type PromptType = 'system' | 'custom';
|
||||
|
||||
/**
|
||||
* 评查配置类型定义
|
||||
*/
|
||||
interface EvaluationConfigType {
|
||||
logicType: LogicType;
|
||||
customLogic: string; // 自定义逻辑:(规则1 AND 规则2) OR 规则3
|
||||
rules: Rule[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑类型定义
|
||||
*/
|
||||
type LogicType = 'and' | 'or' | 'custom';
|
||||
|
||||
interface Rule {
|
||||
id: string;
|
||||
type: RuleType; // 规则类型 有无、一致性、格式、逻辑、正则、AI、代码
|
||||
config: {
|
||||
// exists 规则配置
|
||||
fields?: string[];
|
||||
logic?: LogicOperator;
|
||||
|
||||
// consistency 规则配置
|
||||
pairs?: Array<{
|
||||
sourceField: string;
|
||||
targetField: string;
|
||||
compareMethod: CompareMethod; // 比较方法 包含、精确、大模型语义
|
||||
}>;
|
||||
|
||||
// format 规则配置
|
||||
field?: string;
|
||||
formatType?: FormatType; // 格式类型 日期格式、数字格式、电话号码、电子邮箱、银行卡号、身份证号码、邮政编码、统一社会信用代码
|
||||
parameters?: string;
|
||||
|
||||
// logic 规则配置
|
||||
conditions?: Array<{
|
||||
field: string;
|
||||
operator: ComparisonOperator; // 比较运算符 等于、不等于、大于、大于等于、小于、小于等于、包含、不包含
|
||||
value: string;
|
||||
}>;
|
||||
|
||||
// regex 规则配置
|
||||
pattern?: string;
|
||||
matchType?: MatchType; // 匹配类型 必须匹配(符合为通过)、不得匹配(不符合为通过)
|
||||
|
||||
// ai 规则配置
|
||||
model?: string; // 大模型名称
|
||||
temperature?: number; // 温度
|
||||
prompt?: string; // 提示
|
||||
|
||||
// code 规则配置
|
||||
language?: ProgrammingLanguage;
|
||||
code?: string;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则类型定义
|
||||
*/
|
||||
type RuleType = 'exists' | 'consistency' | 'format' | 'logic' | 'regex' | 'ai' | 'code';
|
||||
|
||||
/**
|
||||
* 逻辑操作符定义
|
||||
*/
|
||||
type LogicOperator = 'and' | 'or';
|
||||
|
||||
/**
|
||||
* 比较方法定义
|
||||
*/
|
||||
type CompareMethod = 'contains' | 'exact' | 'semantic';
|
||||
|
||||
/**
|
||||
* 格式类型定义
|
||||
*/
|
||||
type FormatType = 'date' | 'number' | 'phone' | 'email' | 'bank' | 'id' | 'postal' | 'credit';
|
||||
|
||||
/**
|
||||
* 比较运算符定义
|
||||
*/
|
||||
type ComparisonOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'contains' | 'not_contains';
|
||||
|
||||
/**
|
||||
* 匹配类型定义
|
||||
*/
|
||||
type MatchType = 'match' | 'not_match';
|
||||
|
||||
/**
|
||||
* 编程语言定义
|
||||
*/
|
||||
type ProgrammingLanguage = 'python' | 'javascript';
|
||||
|
||||
/**
|
||||
* 下拉选项数据集
|
||||
*/
|
||||
export const EVALUATION_OPTIONS = {
|
||||
// 风险级别选项
|
||||
riskLevelOptions: [
|
||||
{ value: 'high', label: '高风险' },
|
||||
{ value: 'medium', label: '中风险' },
|
||||
{ value: 'low', label: '低风险' }
|
||||
],
|
||||
|
||||
// 建议消息类型选项
|
||||
suggestionMessageTypeOptions: [
|
||||
{ value: 'info', label: '提示' },
|
||||
{ value: 'warning', label: '警告' },
|
||||
{ value: 'error', label: '错误' }
|
||||
],
|
||||
|
||||
// 评查后动作选项
|
||||
postActionOptions: [
|
||||
{ value: 'none', label: '无' },
|
||||
{ value: 'manual', label: '人工确认' },
|
||||
{ value: 'replace', label: '内容替换' }
|
||||
],
|
||||
|
||||
// VLM字段类型选项
|
||||
vlmFieldTypeOptions: [
|
||||
{ value: 'default', label: '默认' },
|
||||
{ value: 'currency', label: '货币' },
|
||||
{ value: 'print', label: '打印' },
|
||||
{ value: 'seal', label: '印章' },
|
||||
{ value: 'cross-seal', label: '骑缝章' },
|
||||
{ value: 'english', label: '英文' },
|
||||
{ value: 'number', label: '数字' },
|
||||
{ value: 'handwriting', label: '手写' }
|
||||
],
|
||||
|
||||
// 提示类型选项
|
||||
promptTypeOptions: [
|
||||
{ value: 'system', label: '使用系统默认提示词' },
|
||||
{ value: 'custom', label: '使用自定义提示词' }
|
||||
],
|
||||
|
||||
// 逻辑类型选项
|
||||
logicTypeOptions: [
|
||||
{ value: 'and', label: '全部满足(AND)' },
|
||||
{ value: 'or', label: '任一满足(OR)' },
|
||||
{ value: 'custom', label: '自定义组合' }
|
||||
],
|
||||
|
||||
// 规则类型选项
|
||||
ruleTypeOptions: [
|
||||
{ value: 'exists', label: '有无判断' },
|
||||
{ value: 'consistency', label: '一致性判断' },
|
||||
{ value: 'format', label: '格式判断' },
|
||||
{ value: 'logic', label: '逻辑判断' },
|
||||
{ value: 'regex', label: '正则表达式' },
|
||||
{ value: 'ai', label: '大模型判断' },
|
||||
{ value: 'code', label: '自定义代码' }
|
||||
],
|
||||
|
||||
// 逻辑操作符选项
|
||||
logicOperatorOptions: [
|
||||
{ value: 'and', label: 'AND(所有条件都满足)' },
|
||||
{ value: 'or', label: 'OR(任一条件满足)' }
|
||||
],
|
||||
|
||||
// 比较方法选项
|
||||
compareMethodOptions: [
|
||||
{ value: 'contains', label: '包含关系' },
|
||||
{ value: 'exact', label: '精确匹配' },
|
||||
{ value: 'semantic', label: '大模型语义匹配' }
|
||||
],
|
||||
|
||||
// 格式类型选项
|
||||
formatTypeOptions: [
|
||||
{ value: 'date', label: '日期格式' },
|
||||
{ value: 'number', label: '数字格式' },
|
||||
{ value: 'phone', label: '电话号码' },
|
||||
{ value: 'email', label: '电子邮箱' },
|
||||
{ value: 'bank', label: '银行卡号' },
|
||||
{ value: 'id', label: '身份证号码' },
|
||||
{ value: 'postal', label: '邮政编码' },
|
||||
{ value: 'credit', label: '统一社会信用代码' }
|
||||
],
|
||||
|
||||
// 比较运算符选项
|
||||
comparisonOperatorOptions: [
|
||||
{ value: 'eq', label: '等于(=)' },
|
||||
{ value: 'neq', label: '不等于(≠)' },
|
||||
{ value: 'gt', label: '大于(>)' },
|
||||
{ value: 'gte', label: '大于等于(≥)' },
|
||||
{ value: 'lt', label: '小于(<)' },
|
||||
{ value: 'lte', label: '小于等于(≤)' },
|
||||
{ value: 'contains', label: '包含' },
|
||||
{ value: 'not_contains', label: '不包含' }
|
||||
],
|
||||
|
||||
// 匹配类型选项
|
||||
matchTypeOptions: [
|
||||
{ value: 'match', label: '必须匹配(符合为通过)' },
|
||||
{ value: 'not_match', label: '不得匹配(不符合为通过)' }
|
||||
],
|
||||
|
||||
// 编程语言选项
|
||||
programmingLanguageOptions: [
|
||||
{ value: 'python', label: 'Python' },
|
||||
{ value: 'javascript', label: 'JavaScript' }
|
||||
]
|
||||
};
|
||||
|
||||
// 导出类型定义供其他模块使用
|
||||
export type {
|
||||
EvaluationPoint,
|
||||
RiskLevelType,
|
||||
SuggestionMessageType,
|
||||
PostActionType,
|
||||
ExtactionConfigType,
|
||||
VLMFieldType,
|
||||
PromptSetting,
|
||||
PromptType,
|
||||
EvaluationConfigType,
|
||||
LogicType,
|
||||
Rule,
|
||||
RuleType,
|
||||
LogicOperator,
|
||||
CompareMethod,
|
||||
FormatType,
|
||||
ComparisonOperator,
|
||||
MatchType,
|
||||
ProgrammingLanguage
|
||||
};
|
||||
|
||||
+153
-1429
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1771,7 +1771,7 @@
|
||||
<label class="form-label text-sm">运算符</label>
|
||||
<select class="form-select">
|
||||
<option value="eq">等于 (=)</option>
|
||||
<option value="neq">不等于 (≠)</option>
|
||||
<option value="neq"> (≠)</option>
|
||||
<option value="gt">大于 (>)</option>
|
||||
<option value="gte">大于等于 (≥)</option>
|
||||
<option value="lt">小于 (<)</option>
|
||||
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
// 使用原生Node.js http模块发送请求
|
||||
import http from 'http';
|
||||
import { Buffer } from 'buffer';
|
||||
|
||||
// 测试GET请求 - 检查API服务器是否正常运行
|
||||
function testApiConnection() {
|
||||
console.log('测试API连接...');
|
||||
|
||||
// 设置请求选项
|
||||
const options = {
|
||||
hostname: '127.0.0.1',
|
||||
port: 9000,
|
||||
path: '/admin/evaluation_points',
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': '1234567890'
|
||||
}
|
||||
};
|
||||
|
||||
// 创建请求
|
||||
const req = http.request(options, (res) => {
|
||||
console.log(`状态码: ${res.statusCode}`);
|
||||
console.log('响应头:', res.headers);
|
||||
|
||||
let data = '';
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
console.log('响应数据:');
|
||||
try {
|
||||
const parsedData = JSON.parse(data);
|
||||
console.log(JSON.stringify(parsedData, null, 2));
|
||||
} catch (e) {
|
||||
console.log('无法解析响应为JSON:', data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
console.error('请求错误:', error.message);
|
||||
if (error.code === 'ECONNREFUSED') {
|
||||
console.error('无法连接到API服务器 - 请确保服务器已启动并监听端口9000');
|
||||
}
|
||||
});
|
||||
|
||||
// 完成请求
|
||||
req.end();
|
||||
}
|
||||
|
||||
// 测试POST请求 - 尝试创建一个测试评查点
|
||||
function testPostRequest() {
|
||||
console.log('\n测试POST请求...');
|
||||
|
||||
// 创建测试数据
|
||||
const testData = {
|
||||
code: 'TEST_CODE',
|
||||
name: '测试评查点',
|
||||
risk: 'low',
|
||||
is_enabled: false,
|
||||
is_draft: true,
|
||||
description: '这是一个测试评查点',
|
||||
references_laws: {
|
||||
name: '测试法规',
|
||||
articles: ['第一条'],
|
||||
content: '测试内容'
|
||||
},
|
||||
extraction_config: {
|
||||
llm: {
|
||||
fields: ['测试字段1', '测试字段2'],
|
||||
prompt_setting: {
|
||||
type: 'system',
|
||||
template: '测试提示词'
|
||||
}
|
||||
},
|
||||
vlm: {
|
||||
fields: [
|
||||
{ name: '图片字段1', type: 'default' }
|
||||
],
|
||||
prompt_setting: {
|
||||
type: 'system',
|
||||
template: '测试图片提示词'
|
||||
}
|
||||
},
|
||||
regex: {
|
||||
fields: [
|
||||
{ field: '正则字段1', pattern: '\\d+' }
|
||||
]
|
||||
}
|
||||
},
|
||||
evaluation_config: {
|
||||
logicType: 'and',
|
||||
customLogic: '',
|
||||
rules: []
|
||||
}
|
||||
};
|
||||
|
||||
// 将数据转换为JSON字符串
|
||||
const postData = JSON.stringify(testData);
|
||||
|
||||
// 设置请求选项
|
||||
const options = {
|
||||
hostname: '127.0.0.1',
|
||||
port: 9000,
|
||||
path: '/admin/evaluation_points',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': '1234567890',
|
||||
'Content-Length': Buffer.byteLength(postData)
|
||||
}
|
||||
};
|
||||
|
||||
// 创建请求
|
||||
const req = http.request(options, (res) => {
|
||||
console.log(`状态码: ${res.statusCode}`);
|
||||
console.log('响应头:', res.headers);
|
||||
|
||||
let data = '';
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
console.log('响应数据:');
|
||||
try {
|
||||
const parsedData = JSON.parse(data);
|
||||
console.log(JSON.stringify(parsedData, null, 2));
|
||||
} catch (e) {
|
||||
console.log('无法解析响应为JSON:', data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
console.error('请求错误:', error.message);
|
||||
});
|
||||
|
||||
// 发送数据
|
||||
req.write(postData);
|
||||
|
||||
// 完成请求
|
||||
req.end();
|
||||
}
|
||||
|
||||
// 执行测试
|
||||
testApiConnection();
|
||||
|
||||
// 等待3秒后执行POST测试
|
||||
setTimeout(() => {
|
||||
testPostRequest();
|
||||
}, 3000);
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
// 使用原生Node.js http模块发送请求
|
||||
import http from 'http';
|
||||
import { Buffer } from 'buffer';
|
||||
|
||||
// 测试POST请求 - 尝试创建一个测试评查点
|
||||
function testPostRequest() {
|
||||
console.log('测试POST请求...');
|
||||
|
||||
// 创建测试数据
|
||||
const testData = {
|
||||
code: 'TEST_CODE_' + Date.now(),
|
||||
name: '测试评查点',
|
||||
risk: 'low',
|
||||
is_enabled: false,
|
||||
description: '这是一个测试评查点',
|
||||
references_laws: {
|
||||
name: '测试法规',
|
||||
articles: ['第一条'],
|
||||
content: '测试内容'
|
||||
},
|
||||
extraction_config: {
|
||||
llm: {
|
||||
fields: ['测试字段1', '测试字段2'],
|
||||
prompt_setting: {
|
||||
type: 'system',
|
||||
template: '测试提示词'
|
||||
}
|
||||
},
|
||||
vlm: {
|
||||
fields: [
|
||||
{ name: '图片字段1', type: 'default' }
|
||||
],
|
||||
prompt_setting: {
|
||||
type: 'system',
|
||||
template: '测试图片提示词'
|
||||
}
|
||||
},
|
||||
regex: {
|
||||
fields: [
|
||||
{ field: '正则字段1', pattern: '\\d+' }
|
||||
]
|
||||
}
|
||||
},
|
||||
evaluation_config: {
|
||||
logicType: 'and',
|
||||
customLogic: '',
|
||||
rules: []
|
||||
},
|
||||
pass_message: '通过消息',
|
||||
fail_message: '失败消息',
|
||||
suggestion_message: '建议消息',
|
||||
suggestion_message_type: 'warning',
|
||||
post_action: 'none',
|
||||
action_config: ''
|
||||
};
|
||||
|
||||
// 将数据转换为JSON字符串
|
||||
const postData = JSON.stringify(testData);
|
||||
|
||||
// 设置请求选项
|
||||
const options = {
|
||||
hostname: '127.0.0.1',
|
||||
port: 9000,
|
||||
path: '/admin/evaluation_points',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': '1234567890',
|
||||
'Content-Length': Buffer.byteLength(postData)
|
||||
}
|
||||
};
|
||||
|
||||
// 创建请求
|
||||
const req = http.request(options, (res) => {
|
||||
console.log(`状态码: ${res.statusCode}`);
|
||||
console.log('响应头:', res.headers);
|
||||
|
||||
let data = '';
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
console.log('响应数据:');
|
||||
try {
|
||||
const parsedData = JSON.parse(data);
|
||||
console.log(JSON.stringify(parsedData, null, 2));
|
||||
} catch (e) {
|
||||
console.log('无法解析响应为JSON:', data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
console.error('请求错误:', error.message);
|
||||
});
|
||||
|
||||
// 发送数据
|
||||
req.write(postData);
|
||||
|
||||
// 完成请求
|
||||
req.end();
|
||||
}
|
||||
|
||||
// 执行测试
|
||||
testPostRequest();
|
||||
@@ -0,0 +1,162 @@
|
||||
import http from 'http';
|
||||
import { Buffer } from 'buffer';
|
||||
|
||||
// 测试评查点列表接口
|
||||
function testGetEvaluationPoints() {
|
||||
const options = {
|
||||
hostname: '127.0.0.1',
|
||||
port: 9000,
|
||||
path: '/admin/evaluation_points',
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
const req = http.request(options, (res) => {
|
||||
console.log(`状态码: ${res.statusCode}`);
|
||||
console.log(`响应头: ${JSON.stringify(res.headers)}`);
|
||||
|
||||
let data = '';
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
console.log('获取评查点列表成功!');
|
||||
try {
|
||||
const jsonData = JSON.parse(data);
|
||||
console.log(`共获取 ${jsonData.length} 条评查点数据`);
|
||||
console.log('第一条数据:', JSON.stringify(jsonData[0], null, 2).substring(0, 200) + '...');
|
||||
} catch (e) {
|
||||
console.error('解析JSON数据失败:', e.message);
|
||||
console.log('原始数据:', data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (e) => {
|
||||
console.error(`获取评查点列表请求失败: ${e.message}`);
|
||||
});
|
||||
|
||||
req.end();
|
||||
}
|
||||
|
||||
// 测试创建评查点接口
|
||||
function testCreateEvaluationPoint() {
|
||||
const testData = {
|
||||
name: '测试评查点',
|
||||
code: 'TEST_RULE_001',
|
||||
risk: 'medium',
|
||||
is_enabled: true,
|
||||
description: '这是一个用于测试接口的评查点',
|
||||
type: 'content',
|
||||
references_laws: {
|
||||
name: '《中华人民共和国民法典》',
|
||||
articles: ['第五百八十五条', '第五百八十六条'],
|
||||
content: '当事人应当按照约定全面履行自己的义务。'
|
||||
},
|
||||
evaluation_point_groups_id: 1,
|
||||
extraction_config: {
|
||||
llm: {
|
||||
fields: ['合同名称', '合同编号', '签订日期'],
|
||||
prompt_setting: {
|
||||
type: 'system',
|
||||
template: '请从文档中提取以下字段信息:合同名称、合同编号、签订日期'
|
||||
}
|
||||
},
|
||||
vlm: {
|
||||
fields: [
|
||||
{ name: '公章', type: 'seal' },
|
||||
{ name: '签名', type: 'handwriting' }
|
||||
],
|
||||
prompt_setting: {
|
||||
type: 'system',
|
||||
template: '请识别文档中的公章和签名'
|
||||
}
|
||||
},
|
||||
regex: {
|
||||
fields: [
|
||||
{ field: '合同编号', pattern: 'HT-\\d{4}-\\d{6}' }
|
||||
]
|
||||
}
|
||||
},
|
||||
evaluation_config: {
|
||||
logicType: 'and',
|
||||
customLogic: '',
|
||||
rules: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'exists',
|
||||
config: {
|
||||
fields: ['合同名称', '合同编号', '签订日期'],
|
||||
logic: 'and'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
pass_message: '文档检查通过,符合规范要求。',
|
||||
fail_message: '文档存在以下问题,请修改后重新提交。',
|
||||
suggestion_message: '',
|
||||
suggestion_message_type: 'warning',
|
||||
post_action: 'none',
|
||||
action_config: ''
|
||||
};
|
||||
|
||||
const postData = JSON.stringify(testData);
|
||||
|
||||
const options = {
|
||||
hostname: '127.0.0.1',
|
||||
port: 9000,
|
||||
path: '/admin/evaluation_points',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(postData),
|
||||
'Accept': 'application/json',
|
||||
'Prefer': 'return=representation'
|
||||
}
|
||||
};
|
||||
|
||||
const req = http.request(options, (res) => {
|
||||
console.log(`状态码: ${res.statusCode}`);
|
||||
console.log(`响应头: ${JSON.stringify(res.headers)}`);
|
||||
|
||||
let data = '';
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
console.log('创建评查点成功!');
|
||||
try {
|
||||
const jsonData = JSON.parse(data);
|
||||
console.log('创建的评查点ID:', jsonData.id);
|
||||
console.log('创建的评查点数据:', JSON.stringify(jsonData, null, 2).substring(0, 200) + '...');
|
||||
} catch (e) {
|
||||
console.error('解析JSON数据失败:', e.message);
|
||||
console.log('原始数据:', data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (e) => {
|
||||
console.error(`创建评查点请求失败: ${e.message}`);
|
||||
});
|
||||
|
||||
req.write(postData);
|
||||
req.end();
|
||||
}
|
||||
|
||||
// 运行测试
|
||||
console.log('开始测试评查点API...');
|
||||
console.log('1. 测试获取评查点列表...');
|
||||
testGetEvaluationPoints();
|
||||
|
||||
// 等待3秒后测试创建评查点
|
||||
setTimeout(() => {
|
||||
console.log('\n2. 测试创建评查点...');
|
||||
testCreateEvaluationPoint();
|
||||
}, 3000);
|
||||
Reference in New Issue
Block a user