feat: 智能风险分析分段增量展示(对齐 ai-web 体验)——轮询改为增量模式:每轮除状态外拉 /result 按新增键回调 onPartial,法规/风险辨识/专家分析每完成一段立即展示;超时 10 分钟放宽至 20 分钟且超时不清空已生成内容(任务仍在后台执行);面板四段增加'AI 正在生成…'占位状态
This commit is contained in:
+54
-4
@@ -542,11 +542,61 @@ export const aiDeepRiskAnalysis = (content: string, rows: CompareRow[], organiza
|
||||
organization_id: organizationId
|
||||
});
|
||||
|
||||
/** 深度分析任务轮询(复用 pollTask,返回 §5.5 结果契约) */
|
||||
export const pollDeepAnalysisTask = (
|
||||
/**
|
||||
* 深度分析任务增量轮询(与 ai-web 分段体验一致):
|
||||
* 每轮查状态回调 onProgress;processing 期间服务端每完成一步(法规/辨识/分析)就把该段
|
||||
* 落入任务 result,此处按新出现的键回调 onPartial(delta)——前端即可"每生成一部分就显示"。
|
||||
* 超时默认 20 分钟(四步 LLM 串行实测 5~12 分钟);超时抛 AiError,但已回调的部分内容不受影响。
|
||||
*/
|
||||
export async function pollDeepAnalysisTask(
|
||||
taskId: string,
|
||||
opts: { intervalMs?: number; timeoutMs?: number; onProgress?: (t: OpenTask) => void } = {}
|
||||
): Promise<DeepAnalysisResult> => pollTask(taskId, { intervalMs: 3000, timeoutMs: 600_000, ...opts });
|
||||
opts: {
|
||||
intervalMs?: number;
|
||||
timeoutMs?: number;
|
||||
onProgress?: (t: OpenTask) => void;
|
||||
onPartial?: (delta: Partial<DeepAnalysisResult>) => void;
|
||||
} = {}
|
||||
): Promise<DeepAnalysisResult> {
|
||||
const interval = opts.intervalMs ?? 3000;
|
||||
const deadline = Date.now() + (opts.timeoutMs ?? 1_200_000);
|
||||
const seenKeys = new Set<string>();
|
||||
for (;;) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const t = await getTask(taskId);
|
||||
opts.onProgress?.(t);
|
||||
if (t.status === 'completed') {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const r = await getTaskResult(taskId);
|
||||
return r?.result ?? r;
|
||||
}
|
||||
if (t.status === 'failed') throw new AiError(50202, t.error_msg || 'AI 任务执行失败');
|
||||
// processing/pending:增量拉取已完成段落(服务端分步写入 result;拉取失败不阻断轮询)
|
||||
if (opts.onPartial) {
|
||||
try {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const r = await getTaskResult(taskId);
|
||||
const res = r?.result;
|
||||
if (res && typeof res === 'object') {
|
||||
const delta: Record<string, any> = {};
|
||||
Object.keys(res).forEach(k => {
|
||||
if (!seenKeys.has(k)) {
|
||||
seenKeys.add(k);
|
||||
delta[k] = res[k];
|
||||
}
|
||||
});
|
||||
if (Object.keys(delta).length) opts.onPartial(delta as Partial<DeepAnalysisResult>);
|
||||
}
|
||||
} catch {
|
||||
/* 增量结果暂不可得:忽略,下一轮再试 */
|
||||
}
|
||||
}
|
||||
if (Date.now() > deadline) {
|
||||
throw new AiError(50202, 'AI 任务仍在后台执行(四步深度分析耗时较长),已生成内容已展示并保留,可稍后回来继续查看或重新发起');
|
||||
}
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await new Promise(r => setTimeout(r, interval));
|
||||
}
|
||||
}
|
||||
|
||||
export const aiApprovalAssist = (payload: {
|
||||
snapshot: object;
|
||||
|
||||
@@ -22,6 +22,8 @@ const themeStore = useThemeStore();
|
||||
|
||||
const props = defineProps<{
|
||||
data: DeepAnalysisPanelData;
|
||||
/** 分析进行中:内容为空的段落显示"AI 正在生成…"占位(分段增量展示) */
|
||||
generating?: boolean;
|
||||
}>();
|
||||
const emit = defineEmits(['update:data']);
|
||||
|
||||
@@ -30,6 +32,9 @@ const toggleEdit = (key: string) => {
|
||||
editKey.value = editKey.value === key ? '' : key;
|
||||
};
|
||||
|
||||
/** 段落生成中占位(generating 且该段尚无内容时显示) */
|
||||
const pending = (key: string) => props.generating && !String(local.value?.[key] ?? '').trim();
|
||||
|
||||
const local = ref<any>({ ...props.data });
|
||||
watch(
|
||||
() => props.data,
|
||||
@@ -69,7 +74,11 @@ const regCount = computed(() => (local.value?.regulations_data ?? []).length);
|
||||
</NButton>
|
||||
</div>
|
||||
<div class="p-4">
|
||||
<div v-if="pending('risk_identification')" class="flex items-center gap-2 rounded-lg bg-slate-50 px-3 py-2 text-xs text-slate-400">
|
||||
<Icon icon="ri:loader-4-fill" class="size-14px animate-spin" />AI 正在生成风险辨识报告,完成后自动展示…
|
||||
</div>
|
||||
<RichTextInput
|
||||
v-else
|
||||
:disabled="editKey !== 'risk_identification'"
|
||||
:modelValue="local.risk_identification"
|
||||
:minRows="3"
|
||||
@@ -91,7 +100,11 @@ const regCount = computed(() => (local.value?.regulations_data ?? []).length);
|
||||
</NButton>
|
||||
</div>
|
||||
<div class="p-4">
|
||||
<div v-if="pending('risk_analysis')" class="flex items-center gap-2 rounded-lg bg-slate-50 px-3 py-2 text-xs text-slate-400">
|
||||
<Icon icon="ri:loader-4-fill" class="size-14px animate-spin" />AI 正在进行专家研讨风险分析,完成后自动展示…
|
||||
</div>
|
||||
<RichTextInput
|
||||
v-else
|
||||
:disabled="editKey !== 'risk_analysis'"
|
||||
:modelValue="local.risk_analysis"
|
||||
:minRows="3"
|
||||
@@ -127,6 +140,9 @@ const regCount = computed(() => (local.value?.regulations_data ?? []).length);
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<div v-else-if="generating" class="flex items-center gap-2 rounded-lg bg-slate-50 px-3 py-2 text-xs text-slate-400">
|
||||
<Icon icon="ri:loader-4-fill" class="size-14px animate-spin" />AI 正在进行法规合规性分析,完成后自动展示…
|
||||
</div>
|
||||
<div v-else class="rounded-lg bg-slate-50 px-3 py-2 text-xs text-slate-500">
|
||||
本次分析未返回法规合规性条目(可能无适用法规或识别超时),可重新分析或人工补充。
|
||||
</div>
|
||||
@@ -145,7 +161,11 @@ const regCount = computed(() => (local.value?.regulations_data ?? []).length);
|
||||
</NButton>
|
||||
</div>
|
||||
<div class="p-4 space-y-4">
|
||||
<div v-if="pending('summary_text')" class="flex items-center gap-2 rounded-lg bg-slate-50 px-3 py-2 text-xs text-slate-400">
|
||||
<Icon icon="ri:loader-4-fill" class="size-14px animate-spin" />AI 正在进行深度总结(风险分析记录表与结论),完成后自动展示…
|
||||
</div>
|
||||
<RichTextInput
|
||||
v-else
|
||||
:disabled="editKey !== 'summary_text'"
|
||||
:modelValue="local.summary_text"
|
||||
:minRows="2"
|
||||
|
||||
@@ -86,7 +86,7 @@ const runIdentify = async () => {
|
||||
btnDisabled.value = false;
|
||||
}
|
||||
};
|
||||
// 运行智能风险分析(异步深度分析:识别→分析→法规→总结 四段)
|
||||
// 运行智能风险分析(异步深度分析:识别→分析→法规→总结 四段;每完成一段即增量展示)
|
||||
const runRiskAnalysis = async () => {
|
||||
if(form.value.description.trim() === '') {
|
||||
return window.$message?.warning('请先填写变更内容描述');
|
||||
@@ -98,13 +98,33 @@ const runRiskAnalysis = async () => {
|
||||
btnDisabled.value = true;
|
||||
deepError.value = '';
|
||||
taskProgress.value = { progress: 0, step: '' };
|
||||
// 增量回填骨架:保证法规/某一段先出时面板即显示(deepShow 依赖任一内容非空)
|
||||
form.value.deep_analysis = {
|
||||
...(form.value.deep_analysis ?? {}),
|
||||
task_id: form.value.deep_analysis?.task_id ?? '',
|
||||
status: 'processing',
|
||||
risk_identification: form.value.deep_analysis?.risk_identification ?? '',
|
||||
risk_analysis: form.value.deep_analysis?.risk_analysis ?? '',
|
||||
regulations_data: form.value.deep_analysis?.regulations_data ?? [],
|
||||
summary_text: form.value.deep_analysis?.summary_text ?? '',
|
||||
risk_table: form.value.deep_analysis?.risk_table ?? [],
|
||||
conclusion_text: form.value.deep_analysis?.conclusion_text ?? ''
|
||||
};
|
||||
try {
|
||||
const created = await aiDeepRiskAnalysis(form.value.description, form.value.compare_rows);
|
||||
const taskId = created?.task_id ?? '';
|
||||
if (!taskId) throw new AiError(-1, '任务创建失败(未返回 task_id)');
|
||||
form.value.deep_analysis.task_id = taskId;
|
||||
const result: DeepAnalysisResult = await pollDeepAnalysisTask(taskId, {
|
||||
onProgress: (t: OpenTask) => {
|
||||
taskProgress.value = { progress: t?.progress ?? 0, step: t?.current_step ?? '' };
|
||||
},
|
||||
// 增量:服务端每完成一段(法规/辨识/分析)即回填展示,与 ai-web 分段体验一致
|
||||
onPartial: (delta: any) => {
|
||||
if (!form.value.deep_analysis) return;
|
||||
if (delta?.report_risk_identification !== undefined) form.value.deep_analysis.risk_identification = delta.report_risk_identification;
|
||||
if (delta?.report_risk_analysis !== undefined) form.value.deep_analysis.risk_analysis = delta.report_risk_analysis;
|
||||
if (delta?.regulations_data !== undefined) form.value.deep_analysis.regulations_data = delta.regulations_data ?? [];
|
||||
}
|
||||
});
|
||||
// 已生成内容不无故清空:逐字段回填,缺省保留原值
|
||||
@@ -122,12 +142,15 @@ const runRiskAnalysis = async () => {
|
||||
window.$message?.success("智能风险分析完成:风险辨识 / 专家研讨 / 法规合规 / 风险总结 四段结果已生成,支持编辑");
|
||||
} catch (e: any) {
|
||||
deepError.value = e?.message || '智能风险分析失败';
|
||||
// 失败保留已生成部分内容,仅提示
|
||||
// 失败/超时:保留已生成部分内容(含增量段落)仅提示;超时场景任务可能仍在后台执行
|
||||
aiFail(e);
|
||||
} finally {
|
||||
analyzing.value = false;
|
||||
btnDisabled.value = false;
|
||||
taskProgress.value = null;
|
||||
if (form.value.deep_analysis?.status === 'processing') {
|
||||
form.value.deep_analysis.status = deepError.value ? 'partial' : 'processing';
|
||||
}
|
||||
}
|
||||
};
|
||||
// 生成变更申请单
|
||||
@@ -217,7 +240,7 @@ watch(() => props.currentForm, (newVal:any) => {
|
||||
</div>
|
||||
<!-- 深度分析四段结果 -->
|
||||
<template v-if="deepShow">
|
||||
<DeepAnalysisPanel :data="form.deep_analysis" @update:data="onDeepUpdate" />
|
||||
<DeepAnalysisPanel :data="form.deep_analysis" :generating="analyzing" @update:data="onDeepUpdate" />
|
||||
</template>
|
||||
<!-- 风险预分析报告(旧三段字段,读取兼容) -->
|
||||
<template v-if="preRiskShow">
|
||||
|
||||
Reference in New Issue
Block a user