Files
moc/src/views/my/initiateChange/modules/fmea.vue
T

1497 lines
57 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { computed, h, onBeforeUnmount, onMounted, reactive, ref } from "vue";
import { Icon } from '@iconify/vue'
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','preInfo'])
const emit = defineEmits(['close','toTable']);
const loading = ref<boolean>(false);
const analyzing = ref<boolean>(false);
const inferring = ref<boolean>(false)
const inferred = ref<boolean>(false)
const keyword = ref<string>('');
// 新增/编辑弹窗
const editModal = ref<boolean>(false);
// 当前弹框标题
const currentModalTitle = ref<string>('');
// 当前弹框类型
const currentModalType = ref<string>('');
// 当前弹框对象
const currentModalObj = ref<string>('');
// 评分标准弹框
const ruleModal = ref<boolean>(false);
// 项目总体信息与过程设置弹窗
const openSetModal = ref<boolean>(false);
// 项目总体信息
const description = ref<string>('');
const nodeList = ref<any[]>([]);
const name = ref<string>('');
// 步骤流程描述
const node_description = ref<string>('');
// 步骤操作方式
const node_way = ref<string>('');
// 步骤保护措施
const node_protection = ref<string>('');
// 分析列表弹窗
const openListModal = ref<boolean>(false);
// 分析列表弹框使用过程
const currentNodeListSource = ref<any>([])
const currentNodeList = ref<any>([])
const currentNodeIndex = ref<number>(-1)
// 打开分析列表弹框
const openList = () => {
currentNodeList.value = JSON.parse(JSON.stringify(nodes.value[currentNodeIndex.value]?.deviations || []))
currentNodeListSource.value = JSON.parse(JSON.stringify(currentNodeList.value))
node_description.value = currentNode.value?.description || ''
openListModal.value = true
}
// 保存数据
const saveData = () => {
currentNodeListSource.value = JSON.parse(JSON.stringify(currentNodeList.value))
}
// 搜索关键字
const handleSearch = () => {
const kw = keyword.value.trim()
if(!kw){
currentNodeList.value = JSON.parse(JSON.stringify(currentNodeListSource.value))
return
}
currentNodeList.value = currentNodeListSource.value.map((item:any) => {
const objMatched = item.deviation?.includes(kw)
// deviation 命中 → 保留全部 deviations;否则只保留命中的 deviations
if (objMatched) {
return { ...item } // 浅拷贝,结构不变
}
return null
}).filter(Boolean)
}
// 点击失效模式
const clickDev = (dev:any,nodeIndex:number) => {
currentNodeIndex.value = nodeIndex
currentNodeList.value = JSON.parse(JSON.stringify(nodes.value[nodeIndex]?.deviations || []))
currentNodeListSource.value = JSON.parse(JSON.stringify(currentNodeList.value))
currentDev.value = dev
}
// 分析列表弹框添加
const addListItem = () => {
currentNodeList.value.push({
id: 0,
deviation: '',
rows: []
})
currentNodeListSource.value = JSON.parse(JSON.stringify(currentNodeList.value))
}
// 分析列表弹框删除
const removeListItem = (devIndex:number = -1) => {
currentNodeList.value.splice(devIndex, 1)
currentNodeListSource.value = JSON.parse(JSON.stringify(currentNodeList.value))
}
// 分析列表弹框复制
const copyListItem = (devIndex:number = -1) => {
let list = currentNodeList.value[devIndex]?.rows?.map((item:any) => ({
...item,
id: 0,
}));
currentNodeList.value.push({
id: 0,
deviation: currentNodeList.value[devIndex]?.deviation,
rows: list || []
})
currentNodeListSource.value = JSON.parse(JSON.stringify(currentNodeList.value))
}
// 分析列表弹框保存
const listSave = () => {
const hasEmptyObjName = currentNodeList.value.some((item:any) => item.deviation.trim() === '')
if (hasEmptyObjName) {
return window.$message?.warning('失效模式名称不能为空')
}
nodes.value[currentNodeIndex.value].deviations = currentNodeList.value
openListModal.value = false
}
const options = [
{
label: '分析当前失效模式',
key: 'current'
},
{
label: '分析全部失效模式',
key: 'all'
}
]
const columns = ref([
{
title: '序号',
key: 'index',
width: 60,
align: 'center',
render: (_:any, index:number) => {
return h('span',{}, { default:()=>index+1 })
}
},
{
title: '步骤名称',
key: 'node_name',
align: 'center',
render: (row:any) => {
return h(NInput,{
size:'small',
type:'textarea',
placeholder:'步骤名称',
class:'text-left',
value:row.node_name,
autosize: { minRows: 1 },
clearable: true,
onUpdateValue: (val:string) => {
row.node_name = val
}
})
}
},
{
title: '步骤描述',
key: 'description',
align: 'center',
render: (row:any) => {
return h(NInput,{
size:'small',
type:'textarea',
placeholder:'步骤描述',
class:'text-left',
value:row.description,
autosize: { minRows: 1 },
clearable: true,
onUpdateValue: (val:string) => {
row.description = val
}
})
}
},
{
title: '操作',
key: 'action',
width: 60,
align: 'center',
fixed: 'right',
render: (_:any,index:number) => {
return h('div', {class:'flex items-center justify-center gap-[5px]'}, {
default: () => [
h(NPopconfirm,{
// 组件 Props
positiveText: '确定',
negativeText: '取消',
onPositiveClick: () => {
removeItem(index)
},
// 可选:自定义确认/取消按钮的样式
positiveButtonProps: { size: 'tiny', type: 'primary' },
negativeButtonProps: { size: 'tiny' }
},{
// 插槽 (Slots)
trigger: () => h(
NButton,
{
text: true,
size: 'tiny',
type: 'error',
},
{
icon: () => h(Icon, { icon: 'ep:delete',class:'size-14px' }),
default: () => '' // 按钮文字
}
),
default: () => '确定要删除吗?' // 弹出框的提示内容
}),
]
})
}
},
])
// 弹框新增步骤
const addStep = () => {
nodeList.value.push({id:0,node_name:name.value,deviations:[]})
}
// 弹框删除步骤
const removeItem = (index:number) => {
nodeList.value.splice(index, 1);
}
// 弹框保存步骤
const setSave = async () => {
const hasEmptyNodeName = nodeList.value.some((item:any) => item.node_name === '');
if(hasEmptyNodeName){
return window.$message?.warning('请填写步骤名称');
}
nodes.value = nodes.value.concat(nodeList.value);
openSetModal.value = false;
}
// 处理下拉菜单选择
const handleSelect = (key: string) => {
runAi(key);
}
const s_options = computed(() => {
const newArr = props.fmeaRiskMatrixConfig?.s_grades?.map((item:any) => ({
label: item.label+'('+item.score+')',
text: item.label,
value: item.score,
key: item.score
}));
return newArr;
});
const p_options = computed(() => {
const newArr = props.fmeaRiskMatrixConfig?.p_grades?.map((item:any) => ({
label: item.label+'('+item.score+')',
text: item.label,
value: item.score,
key: item.score
}));
return newArr;
});
const d_options = computed(() => {
const newArr = props.fmeaRiskMatrixConfig?.d_grades?.map((item:any) => ({
label: item.label+'('+item.score+')',
text: item.label,
value: item.score,
key: item.score
}));
return newArr;
});
// 用value找到text
const getText = (value:number, options:any[]) => {
const item = options.find((item:any) => item.value === value);
return item?.text || '';
}
// 右键菜单状态
const contextMenuShow = ref<boolean>(false)
const contextMenuX = ref<number>(0)
const contextMenuY = ref<number>(0)
// 存储当前右键点击的目标数据
const contextTarget = ref<{type: string, node: any, dev: any, nodeIndex: number, devIndex: number}>({
type: '', // 'node' | 'obj' | 'dev'
node: null,
dev: null,
nodeIndex: -1,
devIndex: -1,
})
// 当前步骤
const currentNode = computed(() => {
const targetId = currentDev.value?.id;
if (!targetId) return null;
for (const top of nodes.value) {
const matchedObj = top.deviations?.some((dev:any) => dev.id === targetId);
if (matchedObj) return top;
}
return null;
});
// 当前失效模式
const currentDev = ref<any>(null);
// 展开收起
const collapsed = ref<Record<string, boolean>>({})
// 列表
const nodes = ref<any>([]);
// 表格样式
const TH = "border bg-slate-100 px-2 py-1.5 text-[11px] font-medium text-slate-500";
const TD = "border px-1.5 py-1 align-top";
// 失效模式总数
const devTotal = computed(() => {
let total = 0;
nodes.value.forEach((node:any) => {
total += node.deviations.length;
});
return total;
});
// 已分析失效模式数
const devDone = computed(() => {
let nonEmptyCount = 0;
nodes.value.forEach((node:any) => {
node.deviations.forEach((dev:any) => {
if (dev.rows && dev.rows.length > 0) {
nonEmptyCount++;
}
});
});
return nonEmptyCount;
});
// 已完成记录总数
const recTotal = computed(() => {
const totalRows = nodes.value.flatMap((node:any) => node.deviations)
.filter((dev:any) => dev.rows && dev.rows.length > 0)
.reduce((sum:number, d:any) => sum + d.rows.length, 0);
return totalRows;
});
// 人员列表源数据
const workers = ref<{user_id:number,user_name:string,org_name?:string}[]>([]);
// 选中的人员
const selectedWorkers = ref<{user_id:number,user_name:string,org_name?:string}[]>([]);
// 选择分析人员弹窗
const openSelectWorker = ref(false);
// 搜索分析人员
const searchWorker = ref("");
// 分析人员列表
const workerList = computed(() => workers.value.filter((x:{user_id:number,user_name:string,org_name?:string}) => !searchWorker.value || x.user_name.includes(searchWorker.value)));
// 选择分析人员
const selectWorker = (n: {user_id:number,user_name:string,org_name?:string}) => {
selectedWorkers.value = selectedWorkers.value.includes(n) ? selectedWorkers.value.filter((x:any) => x.user_id !== n.user_id) : [...selectedWorkers.value, n];
};
// 匹配是否有人员
const hasWorker = (id:number) => {
return selectedWorkers.value.some((item:{user_id:number,user_name:string,org_name?:string}) => item.user_id === id);
};
// 保存
const save = async (isClick: boolean = false) => {
loading.value = isClick;
const workers = (selectedWorkers.value ?? []).map((item: { org_name?:string; user_id: number; user_name: string }) => {
const { org_name, ...rest } = item;
return rest;
});
// 修改residual_level值
nodes.value?.forEach((node:any) =>
node?.deviations?.forEach((dev:any) =>
dev?.rows?.forEach((row:any) => {
row.residual_level = calculateRiskGrade(row.s_value, row.p_value, row.d_value)?.name || '';
})
)
);
const {error} = await fmeaSaveApi(props.currentId, {
nodes: nodes.value,
users: workers,
});
if(!error){
if(isClick){
window.$message?.success("保存成功");
getFmeaNodes();
}
}
loading.value = false;
};
// AI整理如表、入表
const enterToTable = (type: string, rowIndex: number = -1) => {
if(type==='single'){
const row = currentDev.value.rows[rowIndex];
if(!row?.id){
return window.$message?.warning("请先保存再入表");
}
const enrichedRow = {
id: row?.id || 0,
scene: `${row.cause?row.cause+';':''}${row.effect?'可能导致:'+row.effect:''}`,
source: 'FMEA',
item: `${currentDev.value?.deviation}${currentNode.value?.node_name?`(${currentNode.value?.node_name})`:''}`,
safeguards: row?.safeguards || '',
suggestions: row?.suggestions || '',
// 当前评分档作为固有风险;无措施后评分,剩余风险留空人工判定(不照抄固有)
inherent_level: row?.residual_level || '',
residual_level: '',
to_pssr: 0,
source_row_id: row?.id || 0,
};
emit('toTable',type,enrichedRow?[enrichedRow]:[]);
}
if(type==='all'){
const invalidRows = nodes.value.flatMap((root:any) =>
(root.deviations || []).flatMap((dev:any) =>
(dev.rows || [])
.map((row:any, index:number) => ({
deviation_id: dev.id,
rowIndex: index,
row
}))
.filter(({ row }:any) => !row.id)
)
);
if(invalidRows.length){
return window.$message?.warning("请先保存再入表");
}
const enrichedRows:any[] = [];
nodes.value.forEach((node:any) => {
const node_ame = node.node_name;
node.deviations.forEach((dev:any) => {
const deviation = dev.deviation;
if (dev.rows && dev.rows.length > 0) {
dev.rows.forEach((row:any) => {
// 创建新对象,保留原 row 全部属性,并添加父级信息
enrichedRows.push({
id: row?.id || 0,
scene: `${row.cause?row.cause+';':''}${row.effect?'可能导致:'+row.effect:''}`,
source: 'FMEA',
item: `${deviation}${node_ame?`(${node_ame})`:''}`,
safeguards: row?.safeguards || '',
suggestions: row?.suggestions || '',
// 当前评分档作为固有风险;无措施后评分,剩余风险留空人工判定(不照抄固有)
inherent_level: row?.residual_level || '',
residual_level: '',
to_pssr: 0,
source_row_id: row.id || 0,
});
});
}
});
});
emit('toTable',type,enrichedRows);
}
}
// 导出 Word
const exportWord = () => {
window.$message?.info('还差接口')
}
// AI 自动分析失效模式
const runAi = async (type: string) => {
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 分析: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
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;
const levels = props.fmeaRiskMatrixConfig?.risk_grades || [];
if (!Number.isFinite(rpn)) {
return null
}
return levels.find((item:any) => rpn >= item.min_rpn && rpn <= item.max_rpn) || null;
}
// 新增行
const addRow = async () => {
if(!currentDev.value){
return window.$message?.warning("请先在左侧选择失效模式")
}
currentDev.value.rows.push({
id: 0,
cause: "",
effect: "",
s_value: null,
p_value: null,
d_value: null,
residual_level: '',
safeguards: '',
suggestions: '',
});
};
// 删除行
const delRow = async (index: number) => {
currentDev.value.rows.splice(index, 1);
save()
}
// 展开收起
const leftToggle = (id: string) => {
collapsed.value = { ...collapsed.value, [id]: !collapsed.value[id] }
}
// 打开弹窗
const openModal = (type: string,obj: string, title: string,editName: string = '',editDescription: string = '') => {
if(type==='add'){
name.value = '';
}else{
name.value = editName;
node_description.value = editDescription;
}
currentModalType.value = type;
currentModalObj.value = obj;
currentModalTitle.value = title;
editModal.value = true;
}
// 新增/编辑保存
const modalSave = async () => {
if(name.value===''){
return window.$message?.warning("名称不能为空")
}
// 新增步骤
if(currentModalType.value==='add' && currentModalObj.value==='step'){
nodes.value.push({id:0,node_name:name.value,deviations:[],description:node_description.value});
window.$message?.success("新增步骤成功")
editModal.value = false;
}
// 编辑步骤
if(currentModalType.value==='edit' && currentModalObj.value==='step'){
nodes.value[contextTarget.value?.nodeIndex].node_name = name.value;
nodes.value[contextTarget.value?.nodeIndex].description = node_description.value;
window.$message?.success("编辑步骤成功")
editModal.value = false;
}
// 新增失效模式
if(currentModalType.value==='add' && currentModalObj.value==='dev'){
let dev = {
id: 0,
deviation: name.value,
rows: []
}
if(nodes.value[contextTarget.value?.nodeIndex].deviations){
nodes.value[contextTarget.value?.nodeIndex].deviations.push(dev);
}else {
nodes.value[contextTarget.value?.nodeIndex].deviations = [dev];
}
window.$message?.success("新增失效模式成功")
editModal.value = false;
}
// 编辑失效模式
if(currentModalType.value==='edit' && currentModalObj.value==='dev'){
nodes.value[contextTarget.value?.nodeIndex].deviations[contextTarget.value?.devIndex].deviation = name.value;
window.$message?.success("编辑失效模式成功")
editModal.value = false;
}
}
// 打开删除弹框
const openDelModal = (type: string) => {
let txt = ''
if(type==='step'){
txt = `确定删除步骤「${contextTarget.value?.node?.node_name}」吗?`
}
if(type==='dev'){
txt = `确定删除失效模式「${contextTarget.value?.dev?.deviation}」吗?`
}
dialog.info({
title: '删除',
content: txt,
positiveText: '确定',
negativeText: '取消',
onPositiveClick: () => {
// 删除步骤
if(type==='step'){
nodes.value.splice(contextTarget.value?.nodeIndex, 1);
node_description.value = '';
window.$message?.success("删除步骤成功")
}
// 删除失效模式
if(type==='dev'){
nodes.value[contextTarget.value?.nodeIndex].deviations.splice(contextTarget.value?.devIndex, 1);
window.$message?.success("删除失效模式成功")
}
},
onNegativeClick: () => {
}
})
}
// 菜单选项配置(根据不同层级返回不同菜单)
const getMenuOptions = (type: string) => {
const nodeOptions = [
{ label: '新增失效模式', key: 'addDev' },
{ label: '编辑步骤', key: 'editNode' },
{ label: '删除步骤', key: 'delNode' },
]
const devOptions = [
{ label: '编辑失效模式', key: 'editDev' },
{ label: '删除失效模式', key: 'delDev' },
]
const map:any = {
node: nodeOptions,
dev: devOptions,
}
return map[type] || []
}
// 计算当前菜单选项
const contextMenuOptions = computed(() => {
return getMenuOptions(contextTarget.value.type)
})
// 点击页面其他区域关闭菜单(可选)
const closeMenu = () => {
contextMenuShow.value = false
}
// 右键菜单事件处理
const handleContextMenu = (event: MouseEvent, type: string, node: any, dev: any, nodeIndex: number, devIndex: number) => {
// 阻止浏览器默认右键菜单
event.preventDefault()
// 记录目标数据
contextTarget.value = { type, node, dev, nodeIndex, devIndex }
// 计算菜单位置
contextMenuX.value = Math.max(0, event.clientX)
contextMenuY.value = Math.max(0, event.clientY)
contextMenuShow.value = true
}
// 菜单选中回调
// ============================================================
const handleMenuSelect = (key: string) => {
const { type, node, dev } = contextTarget.value
switch (key) {
// ---------- 过程操作 ----------
case 'addDev':
// 新增失效模式
openModal('add','dev','新增失效模式');
break
case 'editNode':
// 编辑步骤
openModal('edit','step','编辑步骤',node?.node_name,node?.description);
break
case 'delNode':
// 删除步骤
openDelModal('step');
break
// ---------- 失效模式操作 ----------
case 'editDev':
// 编辑失效模式
openModal('edit','dev','编辑失效模式',dev?.deviation);
break
case 'delDev':
// 删除失效模式
openDelModal('dev');
break
default:
console.warn('未知菜单项:', key)
}
// 关闭菜单
closeMenu()
}
// 监听全局点击关闭菜单
// 注意:这里需要排除菜单自身,使用 Naive UI 的 mask 或手动处理
// 简单起见,我们利用 n-dropdown 的 mask: false,并在外部点击时关闭
// 但更好的方式是监听 document 的 click 事件
if (typeof window !== 'undefined') {
document.addEventListener('click', (e) => {
// 如果点击的不是菜单内部,关闭菜单
const menuEl = document.querySelector('.n-dropdown')
if (menuEl && !menuEl.contains(e.target as Node)) {
closeMenu()
}
})
}
function findRowsById(data:any, targetId: number) {
for (const node of data) {
if (!node?.deviations) continue;
for (const dev of node.deviations) {
if (dev.id === targetId) {
return dev.rows ?? [];
}
}
}
return [];
}
// 获取FMEA列表
const getFmeaNodes = async () => {
loading.value = true;
const {data,error} = await fmeaNodesApi(props.currentId);
if(!error){
nodes.value = data.nodes;
selectedWorkers.value = data.users;
if(!currentDev.value){
clickDev(nodes.value[0]?.deviations[0] || null,0)
}else{
const rows = findRowsById(nodes.value,currentDev.value?.id);
currentDev.value.rows = rows;
}
}
loading.value = false;
}
// 获取人员列表
const getWorkers = async () => {
const {data,error} = await peopleListApi();
if(!error){
const transformed = data.map((item:any) => ({
user_id: item.id,
user_name: item.realname,
org_name: item.user_departments.map((d:any) => d.label).join(';')
}));
workers.value = transformed;
}
}
// ========== 拖拽状态记录(只记录设备卡片和失效模式项) ==========
const isDevDragging = ref(false)
const draggedDevInfo = reactive({ deviceIdx: -1 })
// ========== 分析拖拽逻辑 ==========
const onDeviceDragStart = (e: DragEvent, dIdx: number) => {
if (keyword.value)
return // 搜索过滤态下索引与暂存数组不一致,禁用拖拽排序
isDevDragging.value = true
draggedDevInfo.deviceIdx = dIdx
if (e.dataTransfer)
e.dataTransfer.effectAllowed = 'move'
}
const onDeviceDrop = (e: DragEvent, targetDeviceIdx: number) => {
e.preventDefault()
if (keyword.value)
return
if (!isDevDragging.value)
return
const { deviceIdx: srcDeviceIdx } = draggedDevInfo
if (srcDeviceIdx === targetDeviceIdx) {
resetDeviceDragState()
return
}
// 1. 移除源卡片
const [deviceItem] = currentNodeList.value.splice(srcDeviceIdx, 1)
// 2. 直接使用目标索引进行插入(上往下拖落在目标后,下往上拖落在目标前)
currentNodeList.value.splice(targetDeviceIdx, 0, deviceItem)
resetDeviceDragState()
}
const resetDeviceDragState = () => {
isDevDragging.value = false
draggedDevInfo.deviceIdx = -1
}
onMounted(() => {
getWorkers();
getFmeaNodes();
})
onBeforeUnmount(() => {
document.removeEventListener('click', closeMenu)
})
</script>
<template>
<NSpin :show="loading" size="small">
<div class="space-y-3">
<div
class="flex flex-wrap items-center gap-2 rounded-lg border border-[#ACC6E5] bg-[#EAF0F9] px-3 py-2"
:style="{
'--theme-color': themeStore.themeColor
}"
>
<NButton size="small" ghost type="primary" class="text-xs" @click="emit('close')">
<Icon icon="basil:arrow-left-outline" class="size-18px" />
返回工具列表
</NButton>
<NButton size="small" ghost type="primary" class="text-xs" @click="save(true)">保存</NButton>
<span class="text-sm font-bold text-[var(--theme-color)]">FMEA 分析插件</span>
<NTag size="small" type="info">插件</NTag>
<span class="text-[11px] text-slate-500">{{ `分析进度 ${devDone}/${devTotal} 个失效模式 · ${recTotal} 条记录` }}</span>
<div class="relative">
<NButton size="small" ghost type="primary" class="text-[11px]" @click="openSelectWorker = !openSelectWorker">
<Icon icon="lucide:users" class="size-12px" /> 分析组成员 · 已选 {{ selectedWorkers.length }} 人
</NButton>
<template v-if="openSelectWorker">
<div class="fixed inset-0 z-10" @click="openSelectWorker = false"></div>
<div class="absolute right-0 top-8 z-20 w-72 rounded-lg border bg-white p-2 shadow-xl">
<div class="mb-1.5 flex items-center justify-between">
<span class="text-xs font-semibold text-slate-700">选择分析组成员(岗位人员库)</span>
<span class="text-[11px] text-slate-400">已选 {{ selectedWorkers.length }} 人</span>
</div>
<NInput v-model:value="searchWorker" size="small" placeholder="搜索人名…" class="mb-1.5 text-xs" />
<div class="max-h-48 space-y-0.5 overflow-y-auto">
<div v-for="x in workerList" :key="x.user_id" @click="selectWorker(x)"
class="cursor-pointer flex w-full items-center min-h-34px gap-2 rounded-md px-2 py-1.5 text-left text-xs"
:class="hasWorker(x.user_id) ? 'bg-[#DFE9F6]' : 'hover:bg-slate-50'">
<span class="flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border text-[10px]"
:class="hasWorker(x.user_id) ? 'border-[var(--theme-color)] bg-[var(--theme-color)] text-white' : 'border-slate-300'">{{ hasWorker(x.user_id) ? "✓" : "" }}</span>
<span class="font-medium text-slate-800">{{ x.user_name }}</span>
<span class="text-[11px] text-slate-400">{{ x.org_name }}</span>
<NTag v-if="selectedWorkers[0]?.user_id === x.user_id" size="small" type="primary" class="ml-auto">组长</NTag>
</div>
</div>
<div class="mt-1.5 border-t pt-1.5 text-[11px] leading-4 text-slate-400">
首位选择者默认为组长;成员为选择式(非手写),参与记录自动归属到人,用于「参与风险分析次数」统计采集。
</div>
</div>
</template>
</div>
<div class="ml-auto flex items-center gap-1.5">
<NButton size="small" ghost type="primary" class="text-xs" @click="openSetModal = true;nodeList = [];description = '';">
<Icon icon="akar-icons:file" class="size-12px mr-1" /> 项目总体信息与过程设置
</NButton>
<NButton size="small" ghost type="primary" class="text-xs" :disabled="recTotal === 0" @click="enterToTable('all')">
<Icon icon="carbon:document-import" class="size-14px mr-1" /> 全部整理入表
</NButton>
<NButton size="small" ghost type="primary" class="text-xs" @click="exportWord">
<Icon icon="material-symbols:download" class="size-14px" /> 导出 Word
</NButton>
<NDropdown
v-if="isAiOpen"
trigger="hover"
:options="options"
@select="handleSelect"
>
<NButton size="small" type="primary" class="text-xs" :disabled="analyzing">
<Icon v-if="analyzing" icon="ri:loader-4-fill" class="size-14px animate-spin" />
<Icon v-else icon="lucide:sparkles" class="size-12px" />
AI 自动分析
<Icon icon="ant-design:caret-down-filled" class="size-12px ml-1" />
</NButton>
</NDropdown>
</div>
</div>
<div class="flex items-center gap-2 text-xs text-slate-500">
<span>当前位置:</span>
<NTag size="small" type="success">工作步骤:{{ currentNode?.node_name ?? '未选择' }}</NTag>
<span>›</span>
<NTag size="small" type="warning">失效模式:{{ currentDev?.deviation ?? '未选择' }}</NTag>
</div>
<div
class="flex gap-3"
:style="{
'--theme-color': themeStore.themeColor,
'--success-color': themeStore.otherColor.success
}"
>
<!-- 左:树 -->
<div class="w-240px">
<NButton size="small" type="primary" ghost block class="mb-2 text-xs" @click="openModal('add','step','新增步骤')">
<Icon icon="ic:round-plus" class="size-14px" />新增步骤
</NButton>
<div class="shrink-0 rounded-md border p-2 scroll">
<p v-if="nodes.length === 0" class="text-center text-xs text-slate-400 py-10">暂无数据</p>
<div v-for="(node, nodeIndex) in nodes" :key="nodeIndex">
<div
class="cursor-pointer flex items-center select-none"
@click="leftToggle(node.id)"
@contextmenu.prevent="handleContextMenu($event, 'node', node, null, Number(nodeIndex), -1)"
>
<Icon v-if="collapsed[node.id]" icon="akar-icons:chevron-right" class="size-12px" />
<Icon v-else icon="akar-icons:chevron-down" class="size-12px" />
<p class="flex-1 px-2 py-1.5 text-xs font-semibold text-slate-700">步骤{{ Number(nodeIndex) + 1 }}:{{ node.node_name }}</p>
</div>
<template v-if="!collapsed[node.id]">
<div v-for="(dev, devIndex) in node.deviations" :key="devIndex"
@click="clickDev(dev,Number(nodeIndex))"
@contextmenu.prevent="handleContextMenu($event, 'dev', node, dev, Number(nodeIndex), Number(devIndex))"
class="cursor-pointer flex items-center ml-4 gap-1.5 rounded-md px-2 py-1.5 text-left text-xs transition"
:class="currentDev?.id === dev.id ? 'bg-[var(--theme-color)] text-white' : 'text-slate-600 hover:bg-slate-100'"
>
<span class="flex-1">{{ dev.deviation }}</span>
<Icon v-if="dev.analyzing" icon="ri:loader-4-fill" class="size-14px animate-spin text-blue-500" />
<span v-else-if="dev.rows.length" class="rounded-full bg-emerald-100 px-1.5 text-[10px] text-emerald-600">
{{ dev.rows.length }}条
</span>
<span v-else class="rounded-full bg-slate-100 px-1.5 text-[10px] text-slate-400">待分析</span>
</div>
</template>
</div>
</div>
<NButton size="small" type="primary" ghost block class="mt-2 text-xs" @click="ruleModal = true">
评分标准
</NButton>
</div>
<!-- 右:HAZOP 记录表 -->
<div class="min-w-0 flex-1 bg-white">
<div class="flex items-center gap-2 pb-2">
<NButton size="small" ghost type="primary" class="text-xs" @click="addRow">
<Icon icon="ic:round-plus" class="size-14px" /> 新增行
</NButton>
<NButton v-if="currentDev" size="small" type="primary" class="text-xs" @click="openList">
<Icon icon="ant-design:bars-outlined" class="size-14px" /> 分析列表
</NButton>
<NButton v-if="isAiOpen && currentDev" size="small" type="primary" class="text-xs" :disabled="analyzing" @click="runAi('current')">
<Icon v-if="analyzing" icon="ri:loader-4-fill" class="size-14px animate-spin" />
<Icon v-else icon="lucide:sparkles" class="size-12px" />
AI 分析当前失效模式
</NButton>
<span class="text-[11px] text-slate-400">风险等级按风险矩阵RPN = S × P × D 取值实时重算;「入表」将本条选入风险分析记录表</span>
</div>
<div class="scroll2">
<table class="w-full border-collapse text-xs">
<thead>
<tr>
<th :class="TH" class="w-16">操作</th>
<th :class="TH">失效后果</th>
<th :class="TH" class="w-22">S</th>
<th :class="TH">失效原因</th>
<th :class="TH" class="w-22">P</th>
<th :class="TH">现有措施</th>
<th :class="TH" class="w-22">D</th>
<th :class="TH" class="w-20">RPN</th>
<th :class="TH" class="w-20">风险等级</th>
<th :class="TH">建议措施</th>
</tr>
</thead>
<tbody>
<tr v-if="!currentDev || currentDev?.rows?.length === 0">
<td colspan="10" class="px-3 py-8 text-center text-xs text-slate-400">
当前失效模式暂无分析记录,点击右上角「AI 分析当前失效模式」自动生成,或「新增行」手动填写
</td>
</tr>
<tr v-for="(row, ri) in currentDev?.rows" :key="ri">
<td :class="TD">
<div class="flex items-center justify-between px-1 mt-1">
<NButton text type="primary" class="mt-1px text-[11px] hover:underline" title="选入风险分析记录表"
@click="enterToTable('single', Number(ri))">入表
</NButton>
<NPopconfirm
positive-text="确定"
:positiveButtonProps="{ size: 'tiny' }"
:negativeButtonProps="{ size: 'tiny' }"
@positive-click="delRow(Number(ri))"
>
<template #trigger>
<NButton text type="error" title="删除行">
<Icon icon="ep:delete" class="size-14px" />
</NButton>
</template>
确定删除吗?
</NPopconfirm>
</div>
</td>
<td :class="TD">
<NInput type="textarea" size="small" v-model:value="row.effect" :autosize="{minRows:1}" class="text-xs" />
</td>
<td :class="TD" class="text-center">
<NDropdown trigger="click" :options="s_options" @select="(key) => row.s_value = key">
<div class="cursor-pointer" title="点击选择">
<p>{{row.s_value || '-'}}</p>
<p class="text-slate-400">{{getText(row.s_value, s_options) || '点击选择'}}</p>
</div>
</NDropdown>
</td>
<td :class="TD">
<NInput type="textarea" size="small" v-model:value="row.cause" :autosize="{minRows:1}" class="text-xs" />
</td>
<td :class="TD" class="text-center">
<NDropdown trigger="click" :options="p_options" @select="(key) => row.p_value = key">
<div class="cursor-pointer" title="点击选择">
<p>{{row.p_value || '-'}}</p>
<p class="text-slate-400">{{getText(row.p_value, p_options) || '点击选择'}}</p>
</div>
</NDropdown>
</td>
<td :class="TD">
<NInput type="textarea" size="small" v-model:value="row.safeguards" :autosize="{minRows:1}" class="text-xs" />
</td>
<td :class="TD" class="text-center">
<NDropdown trigger="click" :options="d_options" @select="(key) => row.d_value = key">
<div class="cursor-pointer" title="点击选择">
<p>{{row.d_value || '-'}}</p>
<p class="text-slate-400">{{getText(row.d_value, d_options) || '点击选择'}}</p>
</div>
</NDropdown>
</td>
<td :class="TD" class="text-center">
<NTag
v-if="calculateRiskGrade(row.s_value, row.p_value, row.d_value)"
class="text-[11px]"
size="small"
:color="{
color: calculateRiskGrade(row.s_value, row.p_value, row.d_value)?.bg_color,
textColor: calculateRiskGrade(row.s_value, row.p_value, row.d_value)?.font_color,
borderColor: calculateRiskGrade(row.s_value, row.p_value, row.d_value)?.bg_color,
}"
>
{{row.s_value * row.p_value * row.d_value}}
</NTag>
<span v-else>-</span>
</td>
<td :class="TD" class="text-center">
<NTag
v-if="calculateRiskGrade(row.s_value, row.p_value, row.d_value)"
class="text-[11px]"
size="small"
:color="{
color: calculateRiskGrade(row.s_value, row.p_value, row.d_value)?.bg_color,
textColor: calculateRiskGrade(row.s_value, row.p_value, row.d_value)?.font_color,
borderColor: calculateRiskGrade(row.s_value, row.p_value, row.d_value)?.bg_color,
}"
>
{{calculateRiskGrade(row.s_value, row.p_value, row.d_value)?.name}}
</NTag>
<span v-else>-</span>
</td>
<td :class="TD">
<NInput type="textarea" size="small" v-model:value="row.suggestions" :autosize="{minRows:1}" class="text-xs" @blur="save()" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</NSpin>
<!-- ========== 右键菜单 ========== -->
<NDropdown
v-model:show="contextMenuShow"
:x="contextMenuX"
:y="contextMenuY"
:options="contextMenuOptions"
@select="handleMenuSelect"
placement="bottom-start"
trigger="manual"
:mask="false"
to="body"
flip
/>
<!-- 新增/编辑弹窗 -->
<NModal
v-model:show="editModal"
preset="card"
:title="currentModalTitle"
:auto-focus="true"
:style="{ width: '450px', height: 'auto' }"
:segmented="{ content: true, footer: true }"
>
<div>
<NInput v-model:value="name" placeholder="请输入名称" />
<NInput v-if="currentModalObj==='step'" class="mt-3" v-model:value="node_description" placeholder="请输入过程描述" />
</div>
<template #footer>
<div class="flex justify-end gap-[10px]">
<NButton size="small" @click="editModal = false">取消</NButton>
<NButton size="small" type="primary" @click="modalSave">确定</NButton>
</div>
</template>
</NModal>
<!-- 总体工艺描述与工艺步骤设置 -->
<NModal
v-model:show="openSetModal"
preset="card"
title="总体工艺描述与工艺步骤设置"
:auto-focus="true"
:style="{ width: '1000px', height: 'auto' }"
:segmented="{ content: true, footer: true }"
>
<div>
<div v-if="isAiOpen" class="rounded-lg border border-indigo-100 bg-indigo-50/60 p-3 mb-3">
<div class="flex items-center justify-between">
<div class="flex items-center gap-2 text-sm text-indigo-700">
<Icon icon="bx:bot" class="size-16px" />
{{
inferring
? 'AI正在根据工艺描述推演…'
: inferred
? 'AI推演完成,已补全空缺内容,可手动修改后保存'
: '可点击右侧按钮,由AI根据工艺描述自动推演'
}}
</div>
<n-button size="small" type="primary" @click="runInference" :disabled="inferring || !description">
<Icon v-if="inferring" icon="ri:loader-4-fill" class="size-14px animate-spin" />
<Icon v-else icon="lucide:sparkles" class="size-12px" />
{{ inferring ? '推演中…' : 'AI自动推演' }}
</n-button>
</div>
</div>
<p class="mb-1">工艺描述</p>
<NInput
v-model:value="description"
type="textarea"
:rows="4"
clearable
placeholder="请输入工艺描述,如:冻干粉针剂生产工艺:原辅料经称量、配液溶解后..."
/>
<div class="flex items-center justify-between mt-3">
<label class="block text-sm font-medium text-slate-700">
工艺步骤设置
<span class="ml-2 text-xs font-normal text-slate-400">通常一个步骤一行,涉及多个时逐行罗列</span>
</label>
<NButton size="small" dashed type="primary" @click="addStep">
<Icon icon="ic:round-plus" class="size-14px" />新增步骤
</NButton>
</div>
<NDataTable
class="mt-1"
size="small"
:single-line="false"
:columns="columns"
:data="nodeList"
:pagination="false"
:max-height="220"
>
<template #empty>
<p class="text-slate-400 text-sm">
暂无步骤 — 点击「新增步骤」手动添加{{isAiOpen?',或点击上方「AI自动推演」自动生成':''}}
</p>
</template>
</NDataTable>
</div>
<template #footer>
<div class="flex justify-end gap-[10px]">
<NButton size="small" @click="openSetModal = false">取消</NButton>
<NButton size="small" type="primary" @click="setSave">确定</NButton>
</div>
</template>
</NModal>
<!-- 分析列表弹窗 -->
<NModal
v-model:show="openListModal"
preset="card"
:auto-focus="true"
:style="{ width: '1200px', height: 'auto' }"
:segmented="{ content: true, footer: true }"
>
<template #header>
<div class="flex items-center justify-between">
<h2 class="flex items-center gap-2 text-base text-lg leading-none font-semibold">
分析列表
<span class="text-xs font-normal text-slate-400">编辑该步骤下全部失效模式,支持增删改与拖拽排序</span>
</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" :loading="aiModeSuggesting" :disabled="aiModeSuggesting" @click="aiSetMode"><Icon icon="lucide:sparkles" class="size-14px" />AI设置失效模式</NButton>
<NInput
size="small"
v-model:value="keyword"
clearable
placeholder="输入关键字"
@clear="keyword = ''; handleSearch()"
>
<template #suffix>
<NButton text @click="handleSearch">
<Icon icon="akar-icons:search" class="size-14px text-slate-400 ml-1" />
</NButton>
</template>
</NInput>
</div>
</div>
</template>
<template #default>
<div class="flex">
<div class="flex-1 max-h-[60vh] overflow-y-auto border-r mr-3 pr-3">
<div>
<p class="mb-1">本步骤流程描述</p>
<NInput v-model:value="node_description" type="textarea" :autosize="{ minRows: 4,}" clearable placeholder="请输入本步骤流程描述" />
</div>
<div class="mt-3">
<p class="mb-1">本步骤操作方式描述</p>
<NInput v-model:value="node_way" type="textarea" :autosize="{ minRows: 4,}" clearable placeholder="请输入本步骤操作方式描述" />
</div>
<div class="mt-3">
<p class="mb-1">本步骤现有保护措施罗列</p>
<NInput v-model:value="node_protection" type="textarea" :autosize="{ minRows: 4,}" clearable placeholder="请输入本步骤现有保护措施罗列" />
</div>
</div>
<div class="w-500px max-h-[60vh] overflow-y-auto">
<div v-if="currentNodeList.length" class="flex flex-col gap-2">
<div
v-for="(dev, devIndex) in currentNodeList"
:key="devIndex"
class="flex items-center justify-between"
>
<div class="flex items-center gap-[5px]">
<div
class="mr-[5px] cursor-grab"
:draggable="true"
@dragstart="onDeviceDragStart($event, Number(devIndex))"
@dragover.prevent
@drop="onDeviceDrop($event, Number(devIndex))"
>
<Icon icon="gravity-ui:grip" class="size-12px" />
</div>
<NInput v-model:value="dev.deviation" size="small" clearable placeholder="失效模式名称" style="width: 300px;" @blur="saveData" />
</div>
<div class="flex items-center gap-[10px]">
<span v-if="dev?.rows?.length" class="rounded-full bg-emerald-100 px-1.5 text-[10px] text-emerald-600">
{{ dev?.rows?.length }}条
</span>
<span v-else class="rounded-full bg-slate-100 px-1.5 text-[10px] text-slate-400">待分析</span>
<NButton text @click="copyListItem(Number(devIndex))">
<Icon icon="boxicons:copy" class="size-14px" />
</NButton>
<NPopconfirm
positive-text="确定"
:positiveButtonProps="{ size: 'tiny', type: 'primary' }"
:negativeButtonProps="{ size: 'tiny' }"
@positive-click="removeListItem(Number(devIndex))"
>
<template #trigger>
<NButton text type="error">
<Icon icon="ep:delete" class="size-14px" />
</NButton>
</template>
确定删除吗?
</NPopconfirm>
</div>
</div>
</div>
<NEmpty v-else description="暂无数据" size="large">
<template #icon>
<Icon icon="lucide:file-search-corner" class="size-48px" />
</template>
</NEmpty>
</div>
</div>
</template>
<template #footer>
<div class="flex justify-end gap-[10px]">
<NButton size="small" @click="openListModal = false">取消</NButton>
<NButton size="small" type="primary" @click="listSave">确定</NButton>
</div>
</template>
</NModal>
<!-- 评分标准弹窗 -->
<NModal
v-model:show="ruleModal"
preset="card"
title="FMEA 评分标准"
:auto-focus="false"
:style="{ width: '700px', height: 'auto' }"
:segmented="{ content: true, footer: false }"
>
<div class="space-y-3 scroll3">
<p class="bg-[#F7FAFF] px-3 py-1.5 rounded-4px" :style="{color: themeStore.themeColor}">风险优先系数(RPN)= 严重性(S)× 可能性(P)× 可测定性(D)</p>
<div>
<p class="mb-1 font-13px font-600">表 1:风险的严重程度(SEV)评分制</p>
<NTable size="small" :single-line="false">
<thead>
<tr>
<th class="!text-center w-100px">结果</th>
<th>结果的严重性</th>
<th class="!text-center w-50px">评分</th>
</tr>
</thead>
<tbody>
<tr v-for="(item,index) in fmeaRiskMatrixConfig?.s_grades" :key="index">
<td class="text-center">{{item.label}}</td>
<td>{{item.description}}</td>
<td class="text-center">{{item.score}}</td>
</tr>
</tbody>
</NTable>
</div>
<div>
<p class="mb-1 font-13px font-600">表 2:风险的发生几率(OCC)评分制</p>
<NTable size="small" :single-line="false">
<thead>
<tr>
<th>失败发生的可能性</th>
<th class="!text-center w-50px">评分</th>
</tr>
</thead>
<tbody>
<tr v-for="(item,index) in fmeaRiskMatrixConfig?.p_grades" :key="index">
<td>{{item.label}}:{{item.description}}</td>
<td class="text-center">{{item.score}}</td>
</tr>
</tbody>
</NTable>
</div>
<div>
<p class="mb-1 font-13px font-600">表 3:风险被检测或发现的可能性(DET)评分制</p>
<NTable size="small" :single-line="false">
<thead>
<tr>
<th class="!text-center w-100px">发现的可能性</th>
<th>在发生之前通过过程控制可以检测出缺陷的可能性大小</th>
<th class="!text-center w-50px">评分</th>
</tr>
</thead>
<tbody>
<tr v-for="(item,index) in fmeaRiskMatrixConfig?.d_grades" :key="index">
<td class="text-center">{{item.label}}</td>
<td>{{item.description}}</td>
<td class="text-center">{{item.score}}</td>
</tr>
</tbody>
</NTable>
</div>
<div>
<p class="mb-1 font-13px font-600">评价结果</p>
<p class="mb-2">风险评价结果首先遵循:<span class="font-600">风险严重程度为高风险的即为高风险。</span></p>
<div class="flex flex-col gap-2">
<div v-for="(item,index) in fmeaRiskMatrixConfig?.risk_grades" :key="index" class="flex items-center">
<NTag
size="small"
:color="{
color: item.bg_color,
textColor: item.font_color,
borderColor: item.bg_color,
}"
>
{{item.name}}
</NTag>
<span class="ml-2">{{item.min_rpn}}-{{item.max_rpn}}分:</span>
<span>{{item.control_measure}}</span>
</div>
</div>
</div>
</div>
</NModal>
</template>
<style scoped lang="scss">
.scroll {
height: calc(100vh - 196px);
overflow-y: auto;
}
.scroll2 {
height: calc(100vh - 160px);
overflow-y: auto;
}
.scroll3 {
max-height: calc(100vh - 140px);
overflow-y: auto;
}
</style>