暂时完善了一版可对接数据的了

This commit is contained in:
2025-04-10 10:01:53 +08:00
parent e235532469
commit 80a6764ba0
2 changed files with 61 additions and 19 deletions
+5
View File
@@ -13,6 +13,11 @@ export function BasicInfo({ onChange, initialData, evaluationPointGroups = [], r
const [formData, setFormData] = useState<EvaluationPoint>({
risk: 'medium', // 风险等级 默认中风险
is_enabled: true, // 是否启用 默认启用
references_laws: {
name: '',
articles: [],
content: ''
},
...(initialData || {}) // 合并初始数据
});
+56 -19
View File
@@ -431,28 +431,65 @@ export default function RuleNew() {
body: JSON.stringify(cleanedData)
})
.then(async response => {
if (!response.ok) {
// 尝试获取详细错误信息
let errorText = '';
try {
const errorData = await response.json();
errorText = JSON.stringify(errorData);
} catch (e) {
errorText = await response.text();
}
throw new Error(`API错误 (${response.status}): ${errorText}`);
// 尝试解析响应内容
let responseData;
try {
responseData = await response.json();
} catch (e) {
responseData = { code: 500, msg: "响应解析失败" };
}
// 根据响应码处理不同情况
if (responseData.code === 0) {
// 成功情况
console.log("保存成功:", responseData);
// 获取新创建或更新的评查点ID
const savedPointId = responseData.data[0]?.id;
if (savedPointId) {
// 显示成功消息
alert(`评查点${isEditMode ? '更新' : '创建'}成功!`);
// 保存成功后跳转到编辑页面,加载刚保存的数据
navigate(`/rules/new?id=${savedPointId}`);
} else {
// 无法获取ID的情况
alert(`评查点${isEditMode ? '更新' : '创建'}成功,但无法获取ID。正在返回列表页面。`);
navigate('/rules');
}
} else {
// 处理各种错误情况
console.error("API错误:", responseData);
// 根据错误码显示不同的错误消息
switch (responseData.code) {
case 400:
alert(`参数错误: ${responseData.msg}`);
break;
case 401:
alert(`未授权: ${responseData.msg}`);
break;
case 403:
alert(`禁止访问: ${responseData.msg}`);
break;
case 404:
alert(`未找到资源: ${responseData.msg}`);
break;
case 409:
alert(`资源冲突: ${responseData.msg}`);
break;
case 500:
alert(`服务器错误: ${responseData.msg}`);
break;
default:
alert(`保存失败: ${responseData.msg || '未知错误'}`);
}
}
return response.json();
})
.then(data => {
console.log("保存成功:", data);
alert(`评查点${isEditMode ? '更新' : '创建'}成功!`);
// 保存成功后返回列表页
navigate('/rules');
})
.catch(error => {
console.error("保存失败:", error);
alert(`保存失败: ${error.message}`);
console.error("网络或解析错误:", error);
alert(`网络或解析错误: ${error.message || '未知错误'}`);
})
.finally(() => {
setIsLoading(false);