From c1b7f3877fb854bf46f401b2a94e184cee4e401d Mon Sep 17 00:00:00 2001 From: pengm <674192343@qq.com> Date: Thu, 28 May 2026 14:49:20 +0800 Subject: [PATCH] 1.组装报工的sParams --- src/mes/common/commonModelComponent/index.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/mes/common/commonModelComponent/index.js b/src/mes/common/commonModelComponent/index.js index 01d2bf7..3d675e3 100644 --- a/src/mes/common/commonModelComponent/index.js +++ b/src/mes/common/commonModelComponent/index.js @@ -2388,10 +2388,19 @@ const CommonViewTableComponent = props => { const reportViewRow = reportParam ? Object.keys(reportParam).filter(key => key.startsWith('sParam') && !key.includes('Default') && !key.includes('NotEmpty') && !key.includes('DropDown')).reduce((acc, key) => { const paramNum = key.replace('sParam', ''); const valueKey = `sParamValue${paramNum}`; // 使用 sParamValue1, sParamValue2 - // 使用 viewRow 中已有的值,如果没有则使用空字符串(不使用 reportParam 中的默认值) + + // 获取 viewRow 中的值 + const viewRowValue = viewRow[valueKey]; + + // 检查 viewRow 值是否有效(不是 undefined、空字符串、new_type、newType) + const isViewRowValueValid = viewRowValue !== undefined && viewRowValue !== '' && viewRowValue !== 'new_type' && viewRowValue !== 'newType'; + + // 获取默认值并检查是否有效 const defaultValue = reportParam[`${key}Default`]; - const isValidValue = defaultValue !== 'new_type' && defaultValue !== 'newType'; - acc[valueKey] = viewRow[valueKey] !== undefined ? viewRow[valueKey] : (isValidValue ? defaultValue : ''); + const isDefaultValueValid = defaultValue !== undefined && defaultValue !== '' && defaultValue !== 'new_type' && defaultValue !== 'newType'; + + // 优先使用 viewRow 中的有效值,否则使用有效的默认值,否则为空 + acc[valueKey] = isViewRowValueValid ? viewRowValue : (isDefaultValueValid ? defaultValue : ''); return acc; }, {}) : {}; @@ -2415,18 +2424,18 @@ const CommonViewTableComponent = props => { obj.sId = commonUtils.createSid(); obj.sParamKey = key; obj.sParamName = reportParam[key]; - + // 找到数字 const num = key.replace(/[^\d]/g, '').trim(); if (Number(num)) { const number = Number(num); const sParamDropDownKey = `sParamDropDown${number}`; obj.sDropDownData = reportParam[sParamDropDownKey]; - + // 从 viewRow 中获取用户输入的值 const sParamValueKey = `sParamValue${number}`; const sParamValue = viewRow[sParamValueKey]; - + // 如果有值且不是无效值,才添加到 sParams if (sParamValue !== undefined && sParamValue !== '' && sParamValue !== 'new_type' && sParamValue !== 'newType') { obj.sParamValue = sParamValue; @@ -2436,7 +2445,7 @@ const CommonViewTableComponent = props => { sParamData.push(obj); } } - + // 只保留用户选择了的值 const sParamSeletedData = sParamData.filter(item => item.bSelfCbx); if (commonUtils.isNotEmptyArr(sParamSeletedData)) { @@ -2457,8 +2466,6 @@ const CommonViewTableComponent = props => { enabledNew: props.enabledNew, // 继承父组件的 enabledNew 属性 onDataChange: props.onDataChange // 确保 onChange 事件能够正确触发 }; - console.log('222', props); - return ( <> {sName === "master" ? ( -- libgit2 0.22.2