feat: 发起变更页 AI 接口全量接入(T02~T10)——预识别智能风险分析异步任务四段展示(DeepAnalysisPanel)+precheck.deep_analysis;风险页 aiOrganize/preInfo 下发/generateRiskCheck 后台编排(不弹抽屉);riskPre/hazop/fmea/riskCheck 四插件空实现与模拟 loading 全部替换为真实接口(hazop 节点/偏离推演、fmea 步骤/失效模式推演、全部偏离/失效模式顺序生成);培训/PSSR 传入真实风险记录+行动项+固定四组模板(group_type 优先匹配);等级评分按 dim 匹配+缺失维度人工补评提示;修复仅看是过滤丢数据;typecheck 基线持平/build 通过

This commit is contained in:
2026-11-13 10:06:48 +08:00
parent f97f2b4a87
commit 3da29f2d9f
14 changed files with 1262 additions and 181 deletions
@@ -4,9 +4,11 @@ import { inject, watch, ref, computed } from 'vue';
import { Icon } from '@iconify/vue'
import { useThemeStore } from '@/store/modules/theme';
import { getColorWithOpacity } from "@/utils/common";
import { AiError, aiApplication, aiRecognize, aiRiskPreAnalysis } from "@/service/api/ai";
import { AiError, aiApplication, aiRecognize, aiDeepRiskAnalysis, pollDeepAnalysisTask } from "@/service/api/ai";
import type { DeepAnalysisResult, OpenTask } from "@/service/api/ai";
import ChangeCompareTable from "./ChangeCompareTable.vue";
import PreRisk from "./preRisk.vue";
import DeepAnalysisPanel from "./DeepAnalysisPanel.vue";
const themeStore = useThemeStore();
@@ -23,25 +25,46 @@ const aiFail = (e: any) => {
const preLoading = ref<boolean>(false);
// 生成变更申请单loading
const generateLoading = ref<boolean>(false);
// 风险预分析loading
// 风险预分析(异步深度分析)loading
const analyzing = ref<boolean>(false);
// 是否显示险预分析
const preRiskShow = computed(() => form.value.severity || form.value.probability || form.value.protection);
// 异步任务进度
const taskProgress = ref<{ progress: number; step: string } | null>(null);
// 深度分析错误信息(可重试)
const deepError = ref<string>('');
// 深度分析任务是否在跑(禁止重复提交)
const deepRunning = computed(() => analyzing.value);
// 是否显示险预分析(旧三段字段,读取兼容)
const preRiskShow = computed(() => !!(form.value.severity || form.value.probability || form.value.protection));
// 是否已生成深度分析结果(任一部分有内容即展示,避免法规/表格部分结果被隐藏)
const deepShow = computed(() => {
const data = form.value.deep_analysis;
return !!data && !!(data.risk_identification || data.risk_analysis || data.summary_text || data.conclusion_text || data.regulations_data?.length || data.risk_table?.length);
});
// 是否显示变更识别结果
const identifyShow = computed(() => form.value.compare_rows.length > 0);
// 任务步骤文案
const STEP_LABELS: Record<string, string> = {
regulations: '法规合规性分析',
risk_identification: '风险辨识',
risk_analysis: '专家研讨分析',
deep_summary: '深度总结'
};
const stepLabel = (step?: string) => STEP_LABELS[step ?? ''] ?? step ?? '';
// 表单
const form = ref<{
description: string,
compare_rows: {item: string, before_text: string, after_text: string}[],
severity: string,
probability: string,
protection: string
protection: string,
deep_analysis: any
}>({
description: '',
compare_rows: [],
severity: "",
probability: "",
protection: "",
deep_analysis: null,
});
// AI 变更识别
const runIdentify = async () => {
@@ -63,27 +86,48 @@ const runIdentify = async () => {
btnDisabled.value = false;
}
};
// 运行风险预分析
// 运行智能风险分析(异步深度分析:识别→分析→法规→总结 四段)
const runRiskAnalysis = async () => {
if(form.value.description.trim() === '') {
return window.$message?.warning('请先填写变更内容描述');
}
if (deepRunning.value) {
return window.$message?.warning('智能风险分析正在执行中,请勿重复提交');
}
analyzing.value = true;
btnDisabled.value = true;
deepError.value = '';
taskProgress.value = { progress: 0, step: '' };
try {
const res = await aiRiskPreAnalysis(form.value.description, form.value.compare_rows);
form.value = {
...form.value,
severity: res?.severity ?? form.value.severity,
probability: res?.probability ?? form.value.probability,
protection: res?.protection ?? form.value.protection,
const created = await aiDeepRiskAnalysis(form.value.description, form.value.compare_rows);
const taskId = created?.task_id ?? '';
if (!taskId) throw new AiError(-1, '任务创建失败(未返回 task_id)');
const result: DeepAnalysisResult = await pollDeepAnalysisTask(taskId, {
onProgress: (t: OpenTask) => {
taskProgress.value = { progress: t?.progress ?? 0, step: t?.current_step ?? '' };
}
});
// 已生成内容不无故清空:逐字段回填,缺省保留原值
form.value.deep_analysis = {
...(form.value.deep_analysis ?? {}),
task_id: taskId,
status: 'completed',
risk_identification: result?.report_risk_identification ?? form.value.deep_analysis?.risk_identification ?? '',
risk_analysis: result?.report_risk_analysis ?? form.value.deep_analysis?.risk_analysis ?? '',
regulations_data: result?.regulations_data ?? form.value.deep_analysis?.regulations_data ?? [],
summary_text: result?.summary_text ?? form.value.deep_analysis?.summary_text ?? '',
risk_table: result?.risk_table ?? form.value.deep_analysis?.risk_table ?? [],
conclusion_text: result?.conclusion_text ?? form.value.deep_analysis?.conclusion_text ?? ''
};
window.$message?.success("AI 风险预分析报告已生成(危害严重性 / 事件概率 / 保护措施影响),内容支持手动修改");
window.$message?.success("智能风险分析完成:风险辨识 / 专家研讨 / 法规合规 / 风险总结 四段结果已生成,支持编辑");
} catch (e: any) {
deepError.value = e?.message || '智能风险分析失败';
// 失败保留已生成部分内容,仅提示
aiFail(e);
} finally {
analyzing.value = false;
btnDisabled.value = false;
taskProgress.value = null;
}
};
// 生成变更申请单
@@ -105,21 +149,26 @@ const genForm = async () => {
}
};
// 深度分析结果编辑回写
const onDeepUpdate = (val: any) => {
form.value.deep_analysis = { ...form.value.deep_analysis, ...val };
};
// 保存草稿
const saveDraft = () => {
emit('save');
}
defineExpose({form})
defineExpose({form, runRiskAnalysis})
watch(() => props.currentForm, (newVal:any) => {
const {
const {
attachments,
change_id,
created_at,
id,
updated_at,
...rest
change_id,
created_at,
id,
updated_at,
...rest
} = newVal;
form.value = rest;
})
@@ -153,18 +202,35 @@ watch(() => props.currentForm, (newVal:any) => {
@update:data="(d) => form.compare_rows = d"
/>
</template>
<!-- 风险预分析报告 -->
<!-- 异步任务进度 -->
<div v-if="analyzing" class="rounded-lg border border-blue-200 bg-blue-50 px-4 py-3">
<div class="flex items-center gap-2 text-xs text-blue-700">
<Icon icon="ri:loader-4-fill" class="size-14px animate-spin" />
<span>智能风险分析执行中{{ taskProgress?.step ? `:${stepLabel(taskProgress.step)}` : '' }}({{ taskProgress?.progress ?? 0 }}%),通常需要 2~5 分钟,请勿关闭页面</span>
</div>
<NProgress class="mt-2" type="line" :percentage="taskProgress?.progress ?? 0" :show-indicator="false" status="info" />
</div>
<!-- 失败重试提示 -->
<div v-if="deepError" class="rounded-lg border border-red-200 bg-red-50 px-4 py-2 text-xs text-red-600 flex items-center">
<Icon icon="mdi:alert-circle-outline" class="size-14px mr-1" />
<span>{{ deepError }};已生成内容已保留,可点击「智能风险分析」重试,或继续手动填写</span>
</div>
<!-- 深度分析四段结果 -->
<template v-if="deepShow">
<DeepAnalysisPanel :data="form.deep_analysis" @update:data="onDeepUpdate" />
</template>
<!-- 风险预分析报告(旧三段字段,读取兼容) -->
<template v-if="preRiskShow">
<PreRisk :formInfo="form" @update:data="(key:'severity' | 'probability' | 'protection',val:string) => form[key] = val" />
</template>
</div>
</div>
<div class="flex flex-wrap items-center gap-x-4 gap-y-2 px-4 py-2.5" :style="{ backgroundColor: getColorWithOpacity(themeStore.themeColor, 0.15)}">
<span class="text-xs text-slate-500">预识别阶段不设审批人与提交:完成识别与预分析后,请切换至「变更申请表」选择审批人并提交</span>
<span class="text-xs text-slate-500">预识别阶段不设审批人与提交:完成识别与智能风险分析后,请切换至「变更申请表」选择审批人并提交</span>
<div class="ml-auto flex shrink-0 gap-2">
<NButton ghost type="warning" size="small" @click="runRiskAnalysis" :disabled="btnDisabled">
<Icon v-if="analyzing" icon="ri:loader-4-fill" class="size-14px animate-spin" />
<Icon v-else icon="mdi:shield-alert-outline" class="size-14px" />风险预分析
<Icon v-else icon="mdi:shield-alert-outline" class="size-14px" />智能风险分析
</NButton>
<NButton type="primary" size="small" :disabled="btnDisabled" :loading="saveLoading" @click="saveDraft">保存</NButton>
<NButton ghost type="success" size="small" :loading="generateLoading" :disabled="btnDisabled" @click="genForm">
@@ -178,4 +244,4 @@ watch(() => props.currentForm, (newVal:any) => {
height: calc(100vh - 326px);
overflow-y: auto;
}
</style>
</style>