Commit c1b7f3877fb854bf46f401b2a94e184cee4e401d
1 parent
8e23cad2
1.组装报工的sParams
Showing
1 changed file
with
16 additions
and
9 deletions
src/mes/common/commonModelComponent/index.js
| @@ -2388,10 +2388,19 @@ const CommonViewTableComponent = props => { | @@ -2388,10 +2388,19 @@ const CommonViewTableComponent = props => { | ||
| 2388 | const reportViewRow = reportParam ? Object.keys(reportParam).filter(key => key.startsWith('sParam') && !key.includes('Default') && !key.includes('NotEmpty') && !key.includes('DropDown')).reduce((acc, key) => { | 2388 | const reportViewRow = reportParam ? Object.keys(reportParam).filter(key => key.startsWith('sParam') && !key.includes('Default') && !key.includes('NotEmpty') && !key.includes('DropDown')).reduce((acc, key) => { |
| 2389 | const paramNum = key.replace('sParam', ''); | 2389 | const paramNum = key.replace('sParam', ''); |
| 2390 | const valueKey = `sParamValue${paramNum}`; // 使用 sParamValue1, sParamValue2 | 2390 | const valueKey = `sParamValue${paramNum}`; // 使用 sParamValue1, sParamValue2 |
| 2391 | - // 使用 viewRow 中已有的值,如果没有则使用空字符串(不使用 reportParam 中的默认值) | 2391 | + |
| 2392 | + // 获取 viewRow 中的值 | ||
| 2393 | + const viewRowValue = viewRow[valueKey]; | ||
| 2394 | + | ||
| 2395 | + // 检查 viewRow 值是否有效(不是 undefined、空字符串、new_type、newType) | ||
| 2396 | + const isViewRowValueValid = viewRowValue !== undefined && viewRowValue !== '' && viewRowValue !== 'new_type' && viewRowValue !== 'newType'; | ||
| 2397 | + | ||
| 2398 | + // 获取默认值并检查是否有效 | ||
| 2392 | const defaultValue = reportParam[`${key}Default`]; | 2399 | const defaultValue = reportParam[`${key}Default`]; |
| 2393 | - const isValidValue = defaultValue !== 'new_type' && defaultValue !== 'newType'; | ||
| 2394 | - acc[valueKey] = viewRow[valueKey] !== undefined ? viewRow[valueKey] : (isValidValue ? defaultValue : ''); | 2400 | + const isDefaultValueValid = defaultValue !== undefined && defaultValue !== '' && defaultValue !== 'new_type' && defaultValue !== 'newType'; |
| 2401 | + | ||
| 2402 | + // 优先使用 viewRow 中的有效值,否则使用有效的默认值,否则为空 | ||
| 2403 | + acc[valueKey] = isViewRowValueValid ? viewRowValue : (isDefaultValueValid ? defaultValue : ''); | ||
| 2395 | return acc; | 2404 | return acc; |
| 2396 | }, {}) : {}; | 2405 | }, {}) : {}; |
| 2397 | 2406 | ||
| @@ -2415,18 +2424,18 @@ const CommonViewTableComponent = props => { | @@ -2415,18 +2424,18 @@ const CommonViewTableComponent = props => { | ||
| 2415 | obj.sId = commonUtils.createSid(); | 2424 | obj.sId = commonUtils.createSid(); |
| 2416 | obj.sParamKey = key; | 2425 | obj.sParamKey = key; |
| 2417 | obj.sParamName = reportParam[key]; | 2426 | obj.sParamName = reportParam[key]; |
| 2418 | - | 2427 | + |
| 2419 | // 找到数字 | 2428 | // 找到数字 |
| 2420 | const num = key.replace(/[^\d]/g, '').trim(); | 2429 | const num = key.replace(/[^\d]/g, '').trim(); |
| 2421 | if (Number(num)) { | 2430 | if (Number(num)) { |
| 2422 | const number = Number(num); | 2431 | const number = Number(num); |
| 2423 | const sParamDropDownKey = `sParamDropDown${number}`; | 2432 | const sParamDropDownKey = `sParamDropDown${number}`; |
| 2424 | obj.sDropDownData = reportParam[sParamDropDownKey]; | 2433 | obj.sDropDownData = reportParam[sParamDropDownKey]; |
| 2425 | - | 2434 | + |
| 2426 | // 从 viewRow 中获取用户输入的值 | 2435 | // 从 viewRow 中获取用户输入的值 |
| 2427 | const sParamValueKey = `sParamValue${number}`; | 2436 | const sParamValueKey = `sParamValue${number}`; |
| 2428 | const sParamValue = viewRow[sParamValueKey]; | 2437 | const sParamValue = viewRow[sParamValueKey]; |
| 2429 | - | 2438 | + |
| 2430 | // 如果有值且不是无效值,才添加到 sParams | 2439 | // 如果有值且不是无效值,才添加到 sParams |
| 2431 | if (sParamValue !== undefined && sParamValue !== '' && sParamValue !== 'new_type' && sParamValue !== 'newType') { | 2440 | if (sParamValue !== undefined && sParamValue !== '' && sParamValue !== 'new_type' && sParamValue !== 'newType') { |
| 2432 | obj.sParamValue = sParamValue; | 2441 | obj.sParamValue = sParamValue; |
| @@ -2436,7 +2445,7 @@ const CommonViewTableComponent = props => { | @@ -2436,7 +2445,7 @@ const CommonViewTableComponent = props => { | ||
| 2436 | sParamData.push(obj); | 2445 | sParamData.push(obj); |
| 2437 | } | 2446 | } |
| 2438 | } | 2447 | } |
| 2439 | - | 2448 | + |
| 2440 | // 只保留用户选择了的值 | 2449 | // 只保留用户选择了的值 |
| 2441 | const sParamSeletedData = sParamData.filter(item => item.bSelfCbx); | 2450 | const sParamSeletedData = sParamData.filter(item => item.bSelfCbx); |
| 2442 | if (commonUtils.isNotEmptyArr(sParamSeletedData)) { | 2451 | if (commonUtils.isNotEmptyArr(sParamSeletedData)) { |
| @@ -2457,8 +2466,6 @@ const CommonViewTableComponent = props => { | @@ -2457,8 +2466,6 @@ const CommonViewTableComponent = props => { | ||
| 2457 | enabledNew: props.enabledNew, // 继承父组件的 enabledNew 属性 | 2466 | enabledNew: props.enabledNew, // 继承父组件的 enabledNew 属性 |
| 2458 | onDataChange: props.onDataChange // 确保 onChange 事件能够正确触发 | 2467 | onDataChange: props.onDataChange // 确保 onChange 事件能够正确触发 |
| 2459 | }; | 2468 | }; |
| 2460 | - console.log('222', props); | ||
| 2461 | - | ||
| 2462 | return ( | 2469 | return ( |
| 2463 | <> | 2470 | <> |
| 2464 | {sName === "master" ? ( | 2471 | {sName === "master" ? ( |