From 8e23cad238c986ea79bcc43903723dfd6b921440 Mon Sep 17 00:00:00 2001 From: pengm <674192343@qq.com> Date: Thu, 28 May 2026 14:38:19 +0800 Subject: [PATCH] 1.增加上报参数下拉选择的功能 --- src/mes/common/commonModelComponent/index.js | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 80 insertions(+), 14 deletions(-) diff --git a/src/mes/common/commonModelComponent/index.js b/src/mes/common/commonModelComponent/index.js index 3a5ff77..01d2bf7 100644 --- a/src/mes/common/commonModelComponent/index.js +++ b/src/mes/common/commonModelComponent/index.js @@ -2356,42 +2356,108 @@ const CommonViewTableComponent = props => { // 查找对应的下拉数据源 sParamDropDown1, sParamDropDown2... const dropDownKey = `sParamDropDown${paramNum}`; const hasDropDown = reportParam[dropDownKey] && Object.keys(reportParam[dropDownKey]).length > 0; + // 将下拉对象转换为数组格式 [{sId, sName}] + const dropDownArray = hasDropDown ? Object.keys(reportParam[dropDownKey]).map(dKey => ({ + sId: dKey, + sName: reportParam[dropDownKey][dKey] + })) : []; + + // 字段名映射:sParam1 -> sParamValue1, sParam2 -> sParamValue2 + const valueKey = `sParamValue${paramNum}`; return { - sId: key, - sName: key, + sId: valueKey, // 使用 sParamValue1, sParamValue2 作为字段名 + sName: valueKey, // 使用 sParamValue1, sParamValue2 作为字段名 showName: reportParam[key] || key, - sControlName: `reportParam_${key}`, - iColValue: 8, + sControlName: `reportParam_${valueKey}`, + iColValue: 12, iOrder: parseInt(paramNum) || 0, bVisible: true, bReadonly: false, // 允许编辑 enabled: true, // 确保字段可编辑 - sDefault: reportParam[`${key}Default`] || '', - sDropDownType: hasDropDown ? 'sql' : '', - sChineseDropDown: hasDropDown ? JSON.stringify(reportParam[dropDownKey]) : '', - showDropDropDown: hasDropDown ? JSON.stringify(reportParam[dropDownKey]) : '', - iTag: 3, // iTag=3 强制允许编辑(CommonViewTable中iTag=3时enabledNew=true) + sDefault: '', // 不使用默认值,避免显示 new_type + sDropDownType: hasDropDown ? 'const' : '', // 使用 const 类型而不是 sql + showDropDown: hasDropDown ? dropDownArray : [], // 直接传入数组数据 + dropDownData: hasDropDown ? dropDownArray : [], // 备用数据源 + iTag: 3, // iTag=3 强制允许编辑 specialControl: false // 确保不是特殊控件 }; }) : []; - // 构建上报参数的视图数据 + // 构建上报参数的视图数据,并合并到主视图数据中 const reportViewRow = reportParam ? Object.keys(reportParam).filter(key => key.startsWith('sParam') && !key.includes('Default') && !key.includes('NotEmpty') && !key.includes('DropDown')).reduce((acc, key) => { - acc[key] = reportParam[`${key}Default`] || ''; + const paramNum = key.replace('sParam', ''); + const valueKey = `sParamValue${paramNum}`; // 使用 sParamValue1, sParamValue2 + // 使用 viewRow 中已有的值,如果没有则使用空字符串(不使用 reportParam 中的默认值) + const defaultValue = reportParam[`${key}Default`]; + const isValidValue = defaultValue !== 'new_type' && defaultValue !== 'newType'; + acc[valueKey] = viewRow[valueKey] !== undefined ? viewRow[valueKey] : (isValidValue ? defaultValue : ''); return acc; }, {}) : {}; + // 将上报参数数据合并到 viewRow,确保数据同步到主表 + Object.keys(reportViewRow).forEach(key => { + // 如果 viewRow 中已有值,检查是否是无效值(new_type),如果是则替换 + const existingValue = viewRow[key]; + if (existingValue === 'new_type' || existingValue === 'newType') { + viewRow[key] = reportViewRow[key]; + } else if (viewRow[key] === undefined) { + viewRow[key] = reportViewRow[key]; + } + }); + + // 组装 sParams 字段 + if (reportParam && commonUtils.isNotEmptyObject(reportParam)) { + const sParamData = []; + for (const key of Object.keys(reportParam)) { + if (key.startsWith('sParam') && !key.includes('NotEmpty') && !key.includes('DropDown') && !key.includes('Default')) { + const obj = {}; + 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; + obj.bSelfCbx = true; + } + } + sParamData.push(obj); + } + } + + // 只保留用户选择了的值 + const sParamSeletedData = sParamData.filter(item => item.bSelfCbx); + if (commonUtils.isNotEmptyArr(sParamSeletedData)) { + viewRow.sParams = JSON.stringify(sParamSeletedData); + } else { + viewRow.sParams = ''; + } + } + const reportProps = { ...props, viewConfigs: reportViewConfigs, tableConfig: config, iColValueView: 24, - viewRow: reportViewRow, - tableName: `${sName}_report`, + viewRow: viewRow, // 使用合并后的 viewRow + tableName: sName, // 使用与报工信息相同的表名,确保数据正确存储 enabled: props.enabled, // 继承父组件的 enabled 属性 - enabledNew: props.enabledNew // 继承父组件的 enabledNew 属性 + enabledNew: props.enabledNew, // 继承父组件的 enabledNew 属性 + onDataChange: props.onDataChange // 确保 onChange 事件能够正确触发 }; + console.log('222', props); return ( <> -- libgit2 0.22.2