fix(api): 修复风险评估接口参数类型及状态处理逻辑
Some checks failed
Lint Code / Lint Code (push) Failing after 3m2s

- 将 submitRiskAssessment 函数的 projectId 参数类型从 number 改为 number|string,支持字符串ID
- 调整调用处传参,避免项目ID精度丢失,改为传递字符串类型
- 优化风险评估完成通知,消息内容改为更通用提示
- 增加状态变化日志输出,方便调试风险评估状态
- 修改状态重置流程,评估完成后延迟2秒重置状态,提升用户体验
- 保持错误状态处理不变,确保通知正常显示
This commit is contained in:
2026-03-30 16:04:33 +08:00
parent 16e698ceab
commit e269a40d14
3 changed files with 28 additions and 16 deletions

View File

@@ -426,7 +426,7 @@ export type RiskTaskStats = {
}; };
/** 提交异步风险评估任务 */ /** 提交异步风险评估任务 */
export const submitRiskAssessment = (projectId: number) => { export const submitRiskAssessment = (projectId: number | string) => {
return http.request<Result<string>>( return http.request<Result<string>>(
"post", "post",
`/api/v1/risk/sse/assess/${projectId}` `/api/v1/risk/sse/assess/${projectId}`

View File

@@ -149,12 +149,13 @@ export const useSseStore = defineStore("sse", () => {
riskAssessTask.value = data; riskAssessTask.value = data;
riskAssessProgress.value = 100; riskAssessProgress.value = 100;
riskAssessStatus.value = "completed"; riskAssessStatus.value = "completed";
console.log("SSE Store: 风险评估完成", data.result); console.log("SSE Store: 风险评估完成,完整数据:", data);
console.log("SSE Store: result 结构:", data.result);
// 发送通知 // 发送通知 - 使用更通用的消息
ElNotification({ ElNotification({
title: "风险评估完成", title: "风险评估完成",
message: `项目风险评估已完成,已识别 ${data.result?.identifiedRisks?.length || 0} 个风险。`, message: "项目风险评估已完成,请查看风险列表。",
type: "success", type: "success",
duration: 5000, duration: 5000,
position: "top-right" position: "top-right"

View File

@@ -85,17 +85,27 @@ const isAssessing = computed(
); );
// 监听风险评估完成 // 监听风险评估完成
watch(riskAssessStatus, newStatus => { watch(
() => sseStore.riskAssessStatus,
newStatus => {
console.log("风险状态变化:", newStatus);
if (newStatus === "completed") { if (newStatus === "completed") {
message("风险评估完成!", { type: "success" }); message("风险评估完成!", { type: "success" });
loadRiskList(); loadRiskList();
loadStatistics(); loadStatistics();
// 延迟重置状态,让用户看到完成效果
setTimeout(() => {
sseStore.resetRiskAssessStatus(); sseStore.resetRiskAssessStatus();
}, 2000);
} else if (newStatus === "error") { } else if (newStatus === "error") {
message(riskAssessErrorMessage.value || "风险评估失败", { type: "error" }); message(riskAssessErrorMessage.value || "风险评估失败", {
type: "error"
});
sseStore.resetRiskAssessStatus(); sseStore.resetRiskAssessStatus();
} }
}); },
{ immediate: false }
);
// 分页 // 分页
const pagination = ref({ const pagination = ref({
@@ -516,7 +526,8 @@ async function handleCreate() {
} }
try { try {
const res = await submitRiskAssessment(Number(queryParams.value.projectId)); // 直接传递字符串ID避免精度丢失
const res = await submitRiskAssessment(String(queryParams.value.projectId));
console.log("风险评估API响应:", res); console.log("风险评估API响应:", res);
console.log("res.data:", res.data); console.log("res.data:", res.data);
const responseData = res.data as any; const responseData = res.data as any;