几个插件入表功能字段修改

This commit is contained in:
2026-09-15 11:38:43 +08:00
parent 8dffb76a16
commit 052894332f
3 changed files with 101 additions and 113 deletions
+20 -27
View File
@@ -386,15 +386,13 @@ const findRowWithParents = (rowIndex: number = -1) => {
if(row){ if(row){
return { return {
...row, ...row,
scene: `${row.cause?row.cause+';':''}${currentDev.value?.deviation+';'}${row.consequence?'可能导致:'+row.consequence:''}`, scene: `${row.cause?row.cause+';':''}${row.effect?'可能导致:'+row.effect:''}`,
source: 'HAZOP', source: 'FMEA',
item: `${currentDev.value?.deviation}${currentNode.value?.node_name?`${currentNode.value?.node_name}`:''}`, item: `${currentDev.value?.deviation}${currentNode.value?.node_name?`${currentNode.value?.node_name}`:''}`,
safeguards: row?.safeguards?.map((item:any) => item.name).join('') || '', safeguards: row?.safeguards || '',
suggestions: row?.suggestions?.map((item:any) => item.name).join('') || '', suggestions: row?.suggestions || '',
residual_level: row?.residual_level || '', residual_level: row?.residual_level || '',
to_pssr: 0, to_pssr: 0,
safes: row?.safeguards || [],
sugs: row?.suggestions || [],
}; };
} }
return null; return null;
@@ -409,28 +407,23 @@ const enterToTable = (type: string, rowIndex: number = -1) => {
const enrichedRows:any[] = []; const enrichedRows:any[] = [];
nodes.value.forEach((node:any) => { nodes.value.forEach((node:any) => {
const node_ame = node.node_name; const node_ame = node.node_name;
node.objects.forEach((obj:any) => { node.deviations.forEach((dev:any) => {
const obj_ame = obj.obj_name; const deviation = dev.deviation;
obj.deviations.forEach((dev:any) => { if (dev.rows && dev.rows.length > 0) {
const deviation = dev.deviation; dev.rows.forEach((row:any) => {
if (dev.rows && dev.rows.length > 0) { // 创建新对象,保留原 row 全部属性,并添加父级信息
dev.rows.forEach((row:any) => { enrichedRows.push({
// 创建新对象,保留原 row 全部属性,并添加父级信息 ...row,
enrichedRows.push({ scene: `${row.cause?row.cause+';':''}${row.effect?'可能导致:'+row.effect:''}`,
...row, source: 'FMEA',
scene: `${row.cause?row.cause+';':''}${deviation?deviation+';':''}${row.consequence?'可能导致:'+row.consequence:''}`, item: `${deviation}${node_ame?`${node_ame}`:''}`,
source: 'HAZOP', safeguards: row?.safeguards || '',
item: `${deviation}${node_ame?`${node_ame}${obj_ame?`-${obj_ame}`:''}`:''}`, suggestions: row?.suggestions || '',
safeguards: row?.safeguards?.map((item:any) => item.name).join('') || '', residual_level: row?.residual_level || '',
suggestions: row?.suggestions?.map((item:any) => item.name).join('') || '', to_pssr: 0,
residual_level: row?.residual_level || '',
to_pssr: 0,
safes: row?.safeguards || [],
sugs: row?.suggestions || [],
});
}); });
} });
}); }
}); });
}); });
emit('toTable',type,enrichedRows); emit('toTable',type,enrichedRows);
+13 -3
View File
@@ -414,6 +414,16 @@ const save = async (isClick: boolean = false) => {
const { org_name, ...rest } = item; const { org_name, ...rest } = item;
return rest; return rest;
}); });
// 修改risk_value值
nodes.value?.forEach((node:any) =>
node.objects?.forEach((obj:any) =>{
obj?.deviations?.forEach((dev:any) =>
dev?.rows?.forEach((row:any) => {
row.risk_value = riskLevel(row?.l_value,row?.s_value)?.name || '';
})
)
})
);
const {error} = await hazopSaveApi(props.currentId, { const {error} = await hazopSaveApi(props.currentId, {
nodes: nodes.value, nodes: nodes.value,
users: workers, users: workers,
@@ -437,7 +447,7 @@ const findRowWithParents = (rowIndex: number = -1) => {
scene: `${row.cause?row.cause+';':''}${currentDev.value?.deviation+';'}${row.consequence?'可能导致:'+row.consequence:''}`, scene: `${row.cause?row.cause+';':''}${currentDev.value?.deviation+';'}${row.consequence?'可能导致:'+row.consequence:''}`,
source: 'HAZOP', source: 'HAZOP',
item: `${currentDev.value?.deviation}${currentNode.value?.node_name?`${currentNode.value?.node_name}${currentObj.value?.obj_name?`-${currentObj.value?.obj_name}`:''}`:''}`, item: `${currentDev.value?.deviation}${currentNode.value?.node_name?`${currentNode.value?.node_name}${currentObj.value?.obj_name?`-${currentObj.value?.obj_name}`:''}`:''}`,
inherent_level: row?.risk_value || '', inherent_level: riskLevel(row?.l_value,row?.s_value)?.name || '',
safeguards: row?.safeguards?.map((item:any) => item.name).join('') || '', safeguards: row?.safeguards?.map((item:any) => item.name).join('') || '',
suggestions: row?.suggestions?.map((item:any) => item.name).join('') || '', suggestions: row?.suggestions?.map((item:any) => item.name).join('') || '',
residual_level: countRiskLevel(row)?.name || '', residual_level: countRiskLevel(row)?.name || '',
@@ -470,7 +480,7 @@ const enterToTable = (type: string, rowIndex: number = -1) => {
scene: `${row.cause?row.cause+';':''}${deviation?deviation+';':''}${row.consequence?'可能导致:'+row.consequence:''}`, scene: `${row.cause?row.cause+';':''}${deviation?deviation+';':''}${row.consequence?'可能导致:'+row.consequence:''}`,
source: 'HAZOP', source: 'HAZOP',
item: `${deviation}${node_ame?`${node_ame}${obj_ame?`-${obj_ame}`:''}`:''}`, item: `${deviation}${node_ame?`${node_ame}${obj_ame?`-${obj_ame}`:''}`:''}`,
inherent_level: row?.risk_value || '', inherent_level: riskLevel(row?.l_value,row?.s_value)?.name || '',
safeguards: row?.safeguards?.map((item:any) => item.name).join('') || '', safeguards: row?.safeguards?.map((item:any) => item.name).join('') || '',
suggestions: row?.suggestions?.map((item:any) => item.name).join('') || '', suggestions: row?.suggestions?.map((item:any) => item.name).join('') || '',
residual_level: countRiskLevel(row)?.name || '', residual_level: countRiskLevel(row)?.name || '',
@@ -590,7 +600,7 @@ const addRow = async () => {
consequence: "", consequence: "",
l_value: l_options.value[0]?.key || 1, l_value: l_options.value[0]?.key || 1,
s_value: s_options.value[0]?.key || 1, s_value: s_options.value[0]?.key || 1,
risk_value: riskLevel(l_options.value[0]?.key || 1, s_options.value[0]?.key || 1)?.name || '', risk_value: '',
safeguards: [], safeguards: [],
suggestions: [], suggestions: [],
}); });
@@ -48,68 +48,33 @@ const TOOL_CARDS = [
]; ];
// 根据l和s获取风险等级 // 根据l和s获取风险等级
const hazopRiskLevel = (l: number, s: number) => { const hazopRiskLevel = (level: string) => {
const num = l * s;
for (let i = 0; i < hazopRiskMatrixConfig.value?.risk_grades.length; i++) { for (let i = 0; i < hazopRiskMatrixConfig.value?.risk_grades.length; i++) {
const item = hazopRiskMatrixConfig.value?.risk_grades[i]; const item = hazopRiskMatrixConfig.value?.risk_grades[i];
if (num >= item.min && num <= item.max) { if (level === item.name) {
return item; // 返回整条数据 return item; // 返回整条数据
} }
} }
return null; return null;
} }
const jsaRiskLevel = (l: number, s: number) => { const jsaRiskLevel = (level: string) => {
const num = l * s;
for (let i = 0; i < jsaRiskMatrixConfig.value?.risk_grades.length; i++) { for (let i = 0; i < jsaRiskMatrixConfig.value?.risk_grades.length; i++) {
const item = jsaRiskMatrixConfig.value?.risk_grades[i]; const item = jsaRiskMatrixConfig.value?.risk_grades[i];
if (num >= item.min && num <= item.max) { if (level === item.name) {
return item; // 返回整条数据 return item; // 返回整条数据
} }
} }
return null; return null;
} }
// 计算RR1风险等级 const fmeaRiskLevel = (level: string) => {
const countHazopRiskLevel = (row: any) => { for (let i = 0; i < fmeaRiskMatrixConfig.value?.risk_grades.length; i++) {
const l = row.l_value; const item = fmeaRiskMatrixConfig.value?.risk_grades[i];
const s = row.s_value; if (level === item.name) {
const newArr = [...row?.safes || [],...row?.sugs || []]; return item; // 返回整条数据
const result:any = { L: 0, S: 0 };
newArr.forEach(item => {
if (!item.value) return; // 跳过空值
const parts = item.value.split('_');
if (parts.length === 2) {
const type = parts[0].toUpperCase(); // 统一大写
const num = parseInt(parts[1], 10);
if (!isNaN(num) && (type === 'L' || type === 'S')) {
result[type] += num;
}
} }
}); }
const newL = (l - result.L) > 0 ? l - result.L : 1; return null;
const newS = (s - result.S) > 0 ? s - result.S : 1;
return hazopRiskLevel(newL, newS);
} }
const countJsaRiskLevel = (row: any) => {
const l = row.l_value;
const s = row.s_value;
const newArr = [...row?.safes || [],...row?.sugs || []];
const result:any = { L: 0, S: 0 };
newArr.forEach(item => {
if (!item.value) return; // 跳过空值
const parts = item.value.split('_');
if (parts.length === 2) {
const type = parts[0].toUpperCase(); // 统一大写
const num = parseInt(parts[1], 10);
if (!isNaN(num) && (type === 'L' || type === 'S')) {
result[type] += num;
}
}
});
const newL = (l - result.L) > 0 ? l - result.L : 1;
const newS = (s - result.S) > 0 ? s - result.S : 1;
return jsaRiskLevel(newL, newS);
}
// 删除记录 // 删除记录
const delRec = (i: number) => { const delRec = (i: number) => {
@@ -325,41 +290,51 @@ onMounted(() => {
</div> </div>
<div v-if="rec.source==='HAZOP'"> <div v-if="rec.source==='HAZOP'">
<NTag <NTag
v-if="rec.l_value>0 && rec.s_value>0" v-if="rec.inherent_level"
class="text-[11px]" class="text-[11px]"
size="small" size="small"
:color="{ :color="{
color: hazopRiskLevel(rec.l_value, rec.s_value)?.bg_color, color: hazopRiskLevel(rec.inherent_level)?.bg_color,
textColor: hazopRiskLevel(rec.l_value, rec.s_value)?.font_color, textColor: hazopRiskLevel(rec.inherent_level)?.font_color,
borderColor: hazopRiskLevel(rec.l_value, rec.s_value)?.bg_color, borderColor: hazopRiskLevel(rec.inherent_level)?.bg_color,
}" }"
> >
{{hazopRiskLevel(rec.l_value, rec.s_value)?.name}} {{rec.inherent_level}}
</NTag> </NTag>
</div> </div>
<div v-if="rec.source==='FMEA'">
<NTag
v-if="rec.inherent_level"
class="text-[11px]"
size="small"
:color="{
color: fmeaRiskLevel(rec.inherent_level)?.bg_color,
textColor: fmeaRiskLevel(rec.inherent_level)?.font_color,
borderColor: fmeaRiskLevel(rec.inherent_level)?.bg_color,
}"
>
{{rec.inherent_level}}
</NTag>
<span v-else>-</span>
</div>
<div v-if="rec.source==='JSA'"> <div v-if="rec.source==='JSA'">
<NTag <NTag
v-if="rec.l_value>0 && rec.s_value>0" v-if="rec.inherent_level"
class="text-[11px]" class="text-[11px]"
size="small" size="small"
:color="{ :color="{
color: jsaRiskLevel(rec.l_value, rec.s_value)?.bg_color, color: jsaRiskLevel(rec.inherent_level)?.bg_color,
textColor: jsaRiskLevel(rec.l_value, rec.s_value)?.font_color, textColor: jsaRiskLevel(rec.inherent_level)?.font_color,
borderColor: jsaRiskLevel(rec.l_value, rec.s_value)?.bg_color, borderColor: jsaRiskLevel(rec.inherent_level)?.bg_color,
}" }"
> >
{{jsaRiskLevel(rec.l_value, rec.s_value)?.name}} {{rec.inherent_level}}
</NTag> </NTag>
</div> </div>
<div v-if="rec.source==='RISK_CHECK'"> <div v-if="rec.source==='RISK_CHECK'">
<NTag <span>
class="text-[11px]" {{rec.inherent_level?rec.inherent_level:'-'}}
size="small" </span>
>
<span>
{{rec.inherent_level?rec.inherent_level:'-'}}
</span>
</NTag>
</div> </div>
</td> </td>
<td class="border px-1.5 py-1"> <td class="border px-1.5 py-1">
@@ -397,45 +372,55 @@ onMounted(() => {
</div> </div>
<div v-if="rec.source==='HAZOP'"> <div v-if="rec.source==='HAZOP'">
<NTag <NTag
v-if="rec.l_value>0 && rec.s_value>0" v-if="rec.residual_level"
class="text-[11px]" class="text-[11px]"
size="small" size="small"
:color="{ :color="{
color: countHazopRiskLevel(rec)?.bg_color, color: hazopRiskLevel(rec.residual_level)?.bg_color,
textColor: countHazopRiskLevel(rec)?.font_color, textColor: hazopRiskLevel(rec.residual_level)?.font_color,
borderColor: countHazopRiskLevel(rec)?.bg_color, borderColor: hazopRiskLevel(rec.residual_level)?.bg_color,
}" }"
> >
<span> <span>
{{countHazopRiskLevel(rec)?.name}} {{rec.residual_level}}
</span> </span>
</NTag> </NTag>
</div> </div>
<div v-if="rec.source==='JSA'"> <div v-if="rec.source==='FMEA'">
<NTag <NTag
v-if="rec.l_value>0 && rec.s_value>0" v-if="rec.residual_level"
class="text-[11px]" class="text-[11px]"
size="small" size="small"
:color="{ :color="{
color: countJsaRiskLevel(rec)?.bg_color, color: fmeaRiskLevel(rec.residual_level)?.bg_color,
textColor: countJsaRiskLevel(rec)?.font_color, textColor: fmeaRiskLevel(rec.residual_level)?.font_color,
borderColor: countJsaRiskLevel(rec)?.bg_color, borderColor: fmeaRiskLevel(rec.residual_level)?.bg_color,
}"
>
{{rec.residual_level}}
</NTag>
<span v-else>-</span>
</div>
<div v-if="rec.source==='JSA'">
<NTag
v-if="rec.residual_level"
class="text-[11px]"
size="small"
:color="{
color: jsaRiskLevel(rec.residual_level)?.bg_color,
textColor: jsaRiskLevel(rec.residual_level)?.font_color,
borderColor: jsaRiskLevel(rec.residual_level)?.bg_color,
}" }"
> >
<span> <span>
{{countJsaRiskLevel(rec)?.name}} {{rec.residual_level}}
</span> </span>
</NTag> </NTag>
</div> </div>
<div v-if="rec.source==='RISK_CHECK'"> <div v-if="rec.source==='RISK_CHECK'">
<NTag <span>
class="text-[11px]" {{rec.residual_level?rec.residual_level:'-'}}
size="small" </span>
>
<span>
{{rec.residual_level?rec.residual_level:'-'}}
</span>
</NTag>
</div> </div>
</td> </td>
<td class="border px-1.5 py-1 text-center align-top"> <td class="border px-1.5 py-1 text-center align-top">