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
+168 -13
View File
@@ -5,11 +5,12 @@ import { useThemeStore } from '@/store/modules/theme';
import { useDialog, NInput, NPopconfirm, NButton } from 'naive-ui';
import { peopleListApi } from '@/service/api/system';
import { fmeaNodesApi, fmeaSaveApi } from "@/service/api/plugin";
import { AiError, aiFmeaProcessSuggest, aiFmeaModeSuggest, aiFmeaAnalyze } from '@/service/api/ai';
const themeStore = useThemeStore();
const dialog = useDialog();
const props = defineProps(['isAiOpen','currentId','fmeaRiskMatrixConfig'])
const props = defineProps(['isAiOpen','currentId','fmeaRiskMatrixConfig','preInfo'])
const emit = defineEmits(['close','toTable']);
const loading = ref<boolean>(false);
@@ -393,7 +394,9 @@ const enterToTable = (type: string, rowIndex: number = -1) => {
item: `${currentDev.value?.deviation}${currentNode.value?.node_name?`(${currentNode.value?.node_name})`:''}`,
safeguards: row?.safeguards || '',
suggestions: row?.suggestions || '',
residual_level: row?.residual_level || '',
// 当前评分档作为固有风险;无措施后评分,剩余风险留空人工判定(不照抄固有)
inherent_level: row?.residual_level || '',
residual_level: '',
to_pssr: 0,
source_row_id: row?.id || 0,
};
@@ -429,7 +432,9 @@ const enterToTable = (type: string, rowIndex: number = -1) => {
item: `${deviation}${node_ame?`(${node_ame})`:''}`,
safeguards: row?.safeguards || '',
suggestions: row?.suggestions || '',
residual_level: row?.residual_level || '',
// 当前评分档作为固有风险;无措施后评分,剩余风险留空人工判定(不照抄固有)
inherent_level: row?.residual_level || '',
residual_level: '',
to_pssr: 0,
source_row_id: row.id || 0,
});
@@ -448,30 +453,180 @@ const exportWord = () => {
// AI 自动分析失效模式
const runAi = async (type: string) => {
if(currentDev.value.rows.length){
if (type==='current' && currentDev.value?.rows?.length){
return window.$message?.info("当前失效模式已有分析记录,可手动新增行补充");
}
// 分析当前失效模式
if(type==='current'){
if(!currentDev.value){
return window.$message?.warning("请先在左侧选择失效模式")
}
if(analyzing.value) return;
analyzing.value = true;
try {
await analyzeOneMode(currentDev.value);
window.$message?.success("AI 已生成当前失效模式分析行(S/P/D 越界或缺失项请人工补评)");
await save();
} catch (e: any) {
aiFmeaFail(e);
} finally {
analyzing.value = false;
}
}
// 分析全部失效模式
// 分析全部失效模式(当前步骤全部失效模式,顺序逐个处理,单条失败不覆盖已成功记录)
if(type==='all'){
const node = nodes.value?.[currentNodeIndex.value];
const devs = node?.deviations ?? [];
if (!devs.length) {
return window.$message?.warning("当前步骤暂无失效模式,请先添加或使用「AI设置失效模式」");
}
if(analyzing.value) return;
analyzing.value = true;
let ok = 0;
let skip = 0;
let fail = 0;
try {
for (const dev of devs) {
if (dev.rows?.length) {
skip += 1; // 已有分析记录跳过,不覆盖
continue;
}
try {
// eslint-disable-next-line no-await-in-loop
await analyzeOneMode(dev);
ok += 1;
} catch (err) {
fail += 1; // 单条失败隔离
}
}
window.$message?.success(`全部失效模式分析完成:成功 ${ok} 条${skip ? `、跳过已有 ${skip} 条` : ''}${fail ? `、失败 ${fail} 条(可单条重试)` : ''}`);
await save();
} finally {
analyzing.value = false;
}
}
};
// AI 自动推演
/** 单失效模式 AI 分析:S/P/D 按页面评分表传入并夹取,非法值置 null 待人工补评 */
const analyzeOneMode = async (dev: any) => {
const node = nodes.value?.[currentNodeIndex.value];
if (!node || !dev) throw new Error('未找到失效模式所属步骤');
const res = await aiFmeaAnalyze({
step_name: node.node_name ?? '',
step_description: node.description ?? '',
deviation: dev.deviation ?? '',
change_context: {
description: props.preInfo?.description ?? '',
compare_rows: (props.preInfo?.compare_rows ?? []).map((r: any) => ({ item: r.item, before_text: r.before_text, after_text: r.after_text }))
},
matrix_payload: {
s_grades: props.fmeaRiskMatrixConfig?.s_grades ?? [],
p_grades: props.fmeaRiskMatrixConfig?.p_grades ?? [],
d_grades: props.fmeaRiskMatrixConfig?.d_grades ?? [],
risk_grades: props.fmeaRiskMatrixConfig?.risk_grades ?? []
}
});
const rows = res?.rows ?? [];
if (!rows.length) throw new Error('AI 未返回分析行');
rows.forEach((r: any) => {
dev.rows.push({
id: 0,
cause: r.cause ?? '',
effect: r.effect ?? '',
s_value: r.s ?? null,
p_value: r.p ?? null,
d_value: r.d ?? null,
residual_level: '',
safeguards: r.safeguards ?? '',
suggestions: r.suggestions ?? '',
});
});
};
const aiFmeaFail = (e: any) => {
if (e instanceof AiError) window.$message?.warning(`FMEA AI 分析失败:${e.message}`);
else window.$message?.warning(`FMEA AI 分析失败:${e?.message ?? '未知错误'}`);
};
// AI 自动推演(/open/v1/moc/fmea/process-suggest:总体工艺描述 → 工作步骤,只补空缺)
const runInference = async () => {
if (!description.value.trim()) {
return window.$message?.warning('请先填写项目总体工艺描述');
}
inferring.value = true
inferred.value = false
setTimeout(() => {
inferring.value = false
inferred.value = true
}, 1000)
try {
const res = await aiFmeaProcessSuggest(description.value, {
compare_rows: (props.preInfo?.compare_rows ?? []).map((r: any) => ({ item: r.item, before_text: r.before_text, after_text: r.after_text }))
});
const steps = res?.steps ?? [];
if (!steps.length) {
window.$message?.warning('AI 未推演出工作步骤,请手动添加或补充工艺描述');
return;
}
const existing = new Set(nodeList.value.map((n: any) => String(n.node_name ?? '')));
let added = 0;
steps.forEach((s: any) => {
if (existing.has(String(s.node_name ?? ''))) return;
nodeList.value.push({
id: 0,
node_name: s.node_name ?? '',
deviations: [],
description: s.description ?? ''
});
added += 1;
});
inferred.value = true;
window.$message?.success(added > 0
? `AI 推演出 ${added} 个工作步骤(已加入列表,请人工确认后点「确定」保存)`
: 'AI 推演步骤均与现有步骤重名,未新增');
} catch (e: any) {
aiFmeaFail(e);
} finally {
inferring.value = false;
}
}
// AI 设置失效模式(/open/v1/moc/fmea/mode-suggest:当前步骤 → 候选失效模式,进暂存区人工确认)
const aiSetMode = async () => {
const node = nodes.value?.[currentNodeIndex.value];
if (!node) {
return window.$message?.warning('请先在左侧选择步骤');
}
if (aiModeSuggesting.value) return;
aiModeSuggesting.value = true;
try {
const res = await aiFmeaModeSuggest({
step_name: node.node_name ?? '',
step_description: node_description.value ?? node.description ?? '',
existing_modes: (currentNodeList.value ?? []).map((d: any) => d.deviation).filter(Boolean),
change_context: { description: props.preInfo?.description ?? '' }
});
const deviations = res?.deviations ?? [];
if (!deviations.length) {
window.$message?.warning('AI 未返回失效模式建议(可能已有内容已覆盖),可手动添加');
return;
}
const existing = new Set((currentNodeList.value ?? []).map((d: any) => String(d.deviation ?? '')));
let added = 0;
deviations.forEach((s: any) => {
if (existing.has(String(s.deviation ?? ''))) return;
currentNodeList.value.push({ id: 0, deviation: s.deviation ?? '', rows: [] });
existing.add(String(s.deviation ?? ''));
added += 1;
});
saveData();
window.$message?.success(added > 0
? `AI 失效模式建议已加入暂存区 ${added} 条,请人工确认后点「保存」`
: 'AI 建议失效模式均与现有重名,未新增');
} catch (e: any) {
aiFmeaFail(e);
} finally {
aiModeSuggesting.value = false;
}
};
// AI 设置失效模式 loading
const aiModeSuggesting = ref<boolean>(false);
// 计算风险等级
const calculateRiskGrade = (s: number,p: number,d: number) => {
const rpn = s * p * d;
@@ -1144,7 +1299,7 @@ onBeforeUnmount(() => {
</h2>
<div class="flex items-center gap-[10px] mr-[10px]">
<NButton size="small" dashed type="primary" @click="addListItem"><Icon icon="ic:round-plus" class="size-14px" />失效模式</NButton>
<NButton size="small" dashed type="primary">AI设置失效模式</NButton>
<NButton size="small" dashed type="primary" :loading="aiModeSuggesting" :disabled="aiModeSuggesting" @click="aiSetMode"><Icon icon="lucide:sparkles" class="size-14px" />AI设置失效模式</NButton>
<NInput
size="small"
v-model:value="keyword"