Commit c1b7f3877fb854bf46f401b2a94e184cee4e401d

Authored by Min
1 parent 8e23cad2

1.组装报工的sParams

src/mes/common/commonModelComponent/index.js
... ... @@ -2388,10 +2388,19 @@ const CommonViewTableComponent = props => {
2388 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 2389 const paramNum = key.replace('sParam', '');
2390 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 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 2404 return acc;
2396 2405 }, {}) : {};
2397 2406  
... ... @@ -2415,18 +2424,18 @@ const CommonViewTableComponent = props => {
2415 2424 obj.sId = commonUtils.createSid();
2416 2425 obj.sParamKey = key;
2417 2426 obj.sParamName = reportParam[key];
2418   -
  2427 +
2419 2428 // 找到数字
2420 2429 const num = key.replace(/[^\d]/g, '').trim();
2421 2430 if (Number(num)) {
2422 2431 const number = Number(num);
2423 2432 const sParamDropDownKey = `sParamDropDown${number}`;
2424 2433 obj.sDropDownData = reportParam[sParamDropDownKey];
2425   -
  2434 +
2426 2435 // 从 viewRow 中获取用户输入的值
2427 2436 const sParamValueKey = `sParamValue${number}`;
2428 2437 const sParamValue = viewRow[sParamValueKey];
2429   -
  2438 +
2430 2439 // 如果有值且不是无效值,才添加到 sParams
2431 2440 if (sParamValue !== undefined && sParamValue !== '' && sParamValue !== 'new_type' && sParamValue !== 'newType') {
2432 2441 obj.sParamValue = sParamValue;
... ... @@ -2436,7 +2445,7 @@ const CommonViewTableComponent = props => {
2436 2445 sParamData.push(obj);
2437 2446 }
2438 2447 }
2439   -
  2448 +
2440 2449 // 只保留用户选择了的值
2441 2450 const sParamSeletedData = sParamData.filter(item => item.bSelfCbx);
2442 2451 if (commonUtils.isNotEmptyArr(sParamSeletedData)) {
... ... @@ -2457,8 +2466,6 @@ const CommonViewTableComponent = props => {
2457 2466 enabledNew: props.enabledNew, // 继承父组件的 enabledNew 属性
2458 2467 onDataChange: props.onDataChange // 确保 onChange 事件能够正确触发
2459 2468 };
2460   - console.log('222', props);
2461   -
2462 2469 return (
2463 2470 <>
2464 2471 {sName === "master" ? (
... ...