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>>(
"post",
`/api/v1/risk/sse/assess/${projectId}`

View File

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

View File

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