Commit 5ad0fab19d4bde908ce4e9d08a3e7386a7ec5ce6

Authored by Min
1 parent c1b7f387

1.封装上报参数组件,职责清晰

src/mes/common/commonModelComponent/index.js
@@ -2338,134 +2338,6 @@ const CommonViewTableComponent = props => { @@ -2338,134 +2338,6 @@ const CommonViewTableComponent = props => {
2338 const { masterData, sModelsType, app } = props 2338 const { masterData, sModelsType, app } = props
2339 const { bCheck = false } = masterData || {} 2339 const { bCheck = false } = masterData || {}
2340 const imgSrc = commonBusiness.handleAddIcon(masterData, sModelsType, app); 2340 const imgSrc = commonBusiness.handleAddIcon(masterData, sModelsType, app);
2341 -  
2342 - // 上报参数区域状态管理  
2343 - const [reportExpand, setReportExpand] = useState(true);  
2344 -  
2345 - // 解析上报参数  
2346 - let reportParam = null;  
2347 - if(true || props.sModelsId === '17087428780006438414984564455000'){  
2348 - if(viewRow.sReportParam){  
2349 - reportParam = JSON.parse(viewRow.sReportParam);  
2350 - }  
2351 - }  
2352 -  
2353 - // 构建上报参数的配置  
2354 - const reportViewConfigs = reportParam ? Object.keys(reportParam).filter(key => key.startsWith('sParam') && !key.includes('Default') && !key.includes('NotEmpty') && !key.includes('DropDown')).map(key => {  
2355 - const paramNum = key.replace('sParam', '');  
2356 - // 查找对应的下拉数据源 sParamDropDown1, sParamDropDown2...  
2357 - const dropDownKey = `sParamDropDown${paramNum}`;  
2358 - const hasDropDown = reportParam[dropDownKey] && Object.keys(reportParam[dropDownKey]).length > 0;  
2359 - // 将下拉对象转换为数组格式 [{sId, sName}]  
2360 - const dropDownArray = hasDropDown ? Object.keys(reportParam[dropDownKey]).map(dKey => ({  
2361 - sId: dKey,  
2362 - sName: reportParam[dropDownKey][dKey]  
2363 - })) : [];  
2364 -  
2365 - // 字段名映射:sParam1 -> sParamValue1, sParam2 -> sParamValue2  
2366 - const valueKey = `sParamValue${paramNum}`;  
2367 -  
2368 - return {  
2369 - sId: valueKey, // 使用 sParamValue1, sParamValue2 作为字段名  
2370 - sName: valueKey, // 使用 sParamValue1, sParamValue2 作为字段名  
2371 - showName: reportParam[key] || key,  
2372 - sControlName: `reportParam_${valueKey}`,  
2373 - iColValue: 12,  
2374 - iOrder: parseInt(paramNum) || 0,  
2375 - bVisible: true,  
2376 - bReadonly: false, // 允许编辑  
2377 - enabled: true, // 确保字段可编辑  
2378 - sDefault: '', // 不使用默认值,避免显示 new_type  
2379 - sDropDownType: hasDropDown ? 'const' : '', // 使用 const 类型而不是 sql  
2380 - showDropDown: hasDropDown ? dropDownArray : [], // 直接传入数组数据  
2381 - dropDownData: hasDropDown ? dropDownArray : [], // 备用数据源  
2382 - iTag: 3, // iTag=3 强制允许编辑  
2383 - specialControl: false // 确保不是特殊控件  
2384 - };  
2385 - }) : [];  
2386 -  
2387 - // 构建上报参数的视图数据,并合并到主视图数据中  
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', '');  
2390 - const valueKey = `sParamValue${paramNum}`; // 使用 sParamValue1, sParamValue2  
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 - // 获取默认值并检查是否有效  
2399 - const defaultValue = reportParam[`${key}Default`];  
2400 - const isDefaultValueValid = defaultValue !== undefined && defaultValue !== '' && defaultValue !== 'new_type' && defaultValue !== 'newType';  
2401 -  
2402 - // 优先使用 viewRow 中的有效值,否则使用有效的默认值,否则为空  
2403 - acc[valueKey] = isViewRowValueValid ? viewRowValue : (isDefaultValueValid ? defaultValue : '');  
2404 - return acc;  
2405 - }, {}) : {};  
2406 -  
2407 - // 将上报参数数据合并到 viewRow,确保数据同步到主表  
2408 - Object.keys(reportViewRow).forEach(key => {  
2409 - // 如果 viewRow 中已有值,检查是否是无效值(new_type),如果是则替换  
2410 - const existingValue = viewRow[key];  
2411 - if (existingValue === 'new_type' || existingValue === 'newType') {  
2412 - viewRow[key] = reportViewRow[key];  
2413 - } else if (viewRow[key] === undefined) {  
2414 - viewRow[key] = reportViewRow[key];  
2415 - }  
2416 - });  
2417 -  
2418 - // 组装 sParams 字段  
2419 - if (reportParam && commonUtils.isNotEmptyObject(reportParam)) {  
2420 - const sParamData = [];  
2421 - for (const key of Object.keys(reportParam)) {  
2422 - if (key.startsWith('sParam') && !key.includes('NotEmpty') && !key.includes('DropDown') && !key.includes('Default')) {  
2423 - const obj = {};  
2424 - obj.sId = commonUtils.createSid();  
2425 - obj.sParamKey = key;  
2426 - obj.sParamName = reportParam[key];  
2427 -  
2428 - // 找到数字  
2429 - const num = key.replace(/[^\d]/g, '').trim();  
2430 - if (Number(num)) {  
2431 - const number = Number(num);  
2432 - const sParamDropDownKey = `sParamDropDown${number}`;  
2433 - obj.sDropDownData = reportParam[sParamDropDownKey];  
2434 -  
2435 - // 从 viewRow 中获取用户输入的值  
2436 - const sParamValueKey = `sParamValue${number}`;  
2437 - const sParamValue = viewRow[sParamValueKey];  
2438 -  
2439 - // 如果有值且不是无效值,才添加到 sParams  
2440 - if (sParamValue !== undefined && sParamValue !== '' && sParamValue !== 'new_type' && sParamValue !== 'newType') {  
2441 - obj.sParamValue = sParamValue;  
2442 - obj.bSelfCbx = true;  
2443 - }  
2444 - }  
2445 - sParamData.push(obj);  
2446 - }  
2447 - }  
2448 -  
2449 - // 只保留用户选择了的值  
2450 - const sParamSeletedData = sParamData.filter(item => item.bSelfCbx);  
2451 - if (commonUtils.isNotEmptyArr(sParamSeletedData)) {  
2452 - viewRow.sParams = JSON.stringify(sParamSeletedData);  
2453 - } else {  
2454 - viewRow.sParams = '';  
2455 - }  
2456 - }  
2457 -  
2458 - const reportProps = {  
2459 - ...props,  
2460 - viewConfigs: reportViewConfigs,  
2461 - tableConfig: config,  
2462 - iColValueView: 24,  
2463 - viewRow: viewRow, // 使用合并后的 viewRow  
2464 - tableName: sName, // 使用与报工信息相同的表名,确保数据正确存储  
2465 - enabled: props.enabled, // 继承父组件的 enabled 属性  
2466 - enabledNew: props.enabledNew, // 继承父组件的 enabledNew 属性  
2467 - onDataChange: props.onDataChange // 确保 onChange 事件能够正确触发  
2468 - };  
2469 return ( 2341 return (
2470 <> 2342 <>
2471 {sName === "master" ? ( 2343 {sName === "master" ? (
@@ -2489,10 +2361,7 @@ const CommonViewTableComponent = props =&gt; { @@ -2489,10 +2361,7 @@ const CommonViewTableComponent = props =&gt; {
2489 viewProps.enabledNew = false; 2361 viewProps.enabledNew = false;
2490 } 2362 }
2491 2363
2492 - // 传递上报参数给主视图  
2493 - if(reportParam){  
2494 - viewProps.reportParam = reportParam;  
2495 - } 2364 +
2496 2365
2497 return ( 2366 return (
2498 <> 2367 <>
@@ -2502,44 +2371,8 @@ const CommonViewTableComponent = props =&gt; { @@ -2502,44 +2371,8 @@ const CommonViewTableComponent = props =&gt; {
2502 ); 2371 );
2503 })} 2372 })}
2504 2373
2505 - {/* 上报参数区域 - 只显示一次,放在循环外面 */}  
2506 - {reportParam && reportViewConfigs.length > 0 && (  
2507 - <div style={{ marginTop: '10px', border: '1px solid #d9d9d9', borderRadius: '4px', fontSize: '14px' }}>  
2508 - {/* 上报参数标题栏 */}  
2509 - <div  
2510 - style={{  
2511 - display: 'flex',  
2512 - alignItems: 'center',  
2513 - height: '36px',  
2514 - fontSize: '16px',  
2515 - cursor: 'pointer',  
2516 - borderBottom: '1px solid #d9d9d9',  
2517 - paddingLeft: '12px',  
2518 - fontWeight: 'bold',  
2519 - color: '#1890ff'  
2520 - }}  
2521 - onClick={() => setReportExpand(!reportExpand)}  
2522 - >  
2523 - <span style={{  
2524 - width: '0',  
2525 - height: '0',  
2526 - borderLeft: '6px solid transparent',  
2527 - borderRight: '6px solid transparent',  
2528 - borderTop: reportExpand ? '6px solid #1890ff' : 'none',  
2529 - borderBottom: reportExpand ? 'none' : '6px solid #1890ff',  
2530 - marginRight: '8px'  
2531 - }} />  
2532 - 上报参数  
2533 - </div>  
2534 -  
2535 - {/* 上报参数内容 */}  
2536 - {reportExpand && (  
2537 - <div style={{ padding: '10px', fontSize: '14px' }}>  
2538 - <CommonViewTable {...reportProps} />  
2539 - </div>  
2540 - )}  
2541 - </div>  
2542 - )} 2374 + {/* 上报参数区域 */}
  2375 + <ReportParamComponent {...props} viewRow={viewRow} masterData={masterData} config={config} sName={sName} onDataChange={props.onDataChange} />
2543 {sName !== "master" ? ( 2376 {sName !== "master" ? (
2544 <CommonOperationBarComponent {...operationBarProps} /> 2377 <CommonOperationBarComponent {...operationBarProps} />
2545 ) : ( 2378 ) : (
@@ -3347,6 +3180,161 @@ const CommonViewChooseComponent = props =&gt; { @@ -3347,6 +3180,161 @@ const CommonViewChooseComponent = props =&gt; {
3347 ); 3180 );
3348 }; 3181 };
3349 3182
  3183 +// 上报参数组件
  3184 +const ReportParamComponent = props => {
  3185 + const { viewRow, masterData, config, sName, onDataChange } = props;
  3186 +
  3187 + const [reportExpand, setReportExpand] = useState(true);
  3188 +
  3189 + if (!viewRow || !viewRow.sReportParam) {
  3190 + return '';
  3191 + }
  3192 +
  3193 + const reportParam = JSON.parse(viewRow.sReportParam);
  3194 +
  3195 + if (!reportParam || !commonUtils.isNotEmptyObject(reportParam)) {
  3196 + return '';
  3197 + }
  3198 +
  3199 + const reportViewConfigs = Object.keys(reportParam).filter(key => key.startsWith('sParam') && !key.includes('Default') && !key.includes('NotEmpty') && !key.includes('DropDown')).map(key => {
  3200 + const paramNum = key.replace('sParam', '');
  3201 + const dropDownKey = `sParamDropDown${paramNum}`;
  3202 + const hasDropDown = reportParam[dropDownKey] && Object.keys(reportParam[dropDownKey]).length > 0;
  3203 + const dropDownArray = hasDropDown ? Object.keys(reportParam[dropDownKey]).map(dKey => ({
  3204 + sId: dKey,
  3205 + sName: reportParam[dropDownKey][dKey]
  3206 + })) : [];
  3207 +
  3208 + const valueKey = `sParamValue${paramNum}`;
  3209 +
  3210 + return {
  3211 + sId: valueKey,
  3212 + sName: valueKey,
  3213 + showName: reportParam[key] || key,
  3214 + sControlName: `reportParam_${valueKey}`,
  3215 + iColValue: 12,
  3216 + iOrder: parseInt(paramNum) || 0,
  3217 + bVisible: true,
  3218 + bReadonly: false,
  3219 + enabled: true,
  3220 + sDefault: '',
  3221 + sDropDownType: hasDropDown ? 'const' : '',
  3222 + showDropDown: hasDropDown ? dropDownArray : [],
  3223 + dropDownData: hasDropDown ? dropDownArray : [],
  3224 + iTag: 3,
  3225 + specialControl: false
  3226 + };
  3227 + });
  3228 +
  3229 + if (reportViewConfigs.length === 0) {
  3230 + return '';
  3231 + }
  3232 +
  3233 + const reportViewRow = Object.keys(reportParam).filter(key => key.startsWith('sParam') && !key.includes('Default') && !key.includes('NotEmpty') && !key.includes('DropDown')).reduce((acc, key) => {
  3234 + const paramNum = key.replace('sParam', '');
  3235 + const valueKey = `sParamValue${paramNum}`;
  3236 + const viewRowValue = viewRow[valueKey];
  3237 + const isViewRowValueValid = viewRowValue !== undefined && viewRowValue !== '' && viewRowValue !== 'new_type' && viewRowValue !== 'newType';
  3238 + const defaultValue = reportParam[`${key}Default`];
  3239 + const isDefaultValueValid = defaultValue !== undefined && defaultValue !== '' && defaultValue !== 'new_type' && defaultValue !== 'newType';
  3240 + acc[valueKey] = isViewRowValueValid ? viewRowValue : (isDefaultValueValid ? defaultValue : '');
  3241 + return acc;
  3242 + }, {});
  3243 +
  3244 + Object.keys(reportViewRow).forEach(key => {
  3245 + const existingValue = viewRow[key];
  3246 + if (existingValue === 'new_type' || existingValue === 'newType') {
  3247 + viewRow[key] = reportViewRow[key];
  3248 + } else if (viewRow[key] === undefined) {
  3249 + viewRow[key] = reportViewRow[key];
  3250 + }
  3251 + });
  3252 +
  3253 + const sParamData = [];
  3254 + for (const key of Object.keys(reportParam)) {
  3255 + if (key.includes('sParam') && !key.includes('NotEmpty') && !key.includes('DropDown') && !key.includes('Default')) {
  3256 + const obj = {};
  3257 + obj.sId = commonUtils.createSid();
  3258 + obj.sParamKey = key;
  3259 + obj.sParamName = reportParam[key];
  3260 + const num = key.replace(/[^\d]/g, '').trim();
  3261 + if (Number(num)) {
  3262 + const number = Number(num);
  3263 + const sParamDropDownKey = `sParamDropDown${number}`;
  3264 + obj.sDropDownData = reportParam[sParamDropDownKey];
  3265 + const sParamDefaultKey = `sParamDefault${number}`;
  3266 + const defaultVal = reportParam[sParamDefaultKey];
  3267 + if (defaultVal !== undefined && defaultVal !== '' && defaultVal !== 'new_type' && defaultVal !== 'newType') {
  3268 + obj.sParamValue = defaultVal;
  3269 + } else {
  3270 + obj.sParamValue = '';
  3271 + }
  3272 + const sParamValueKey = `sParamValue${number}`;
  3273 + const sParamValue = viewRow[sParamValueKey];
  3274 + if (commonUtils.isNotEmptyObject(sParamValue) && sParamValue !== '0') {
  3275 + obj.sParamValue = sParamValue;
  3276 + obj.bSelfCbx = true;
  3277 + }
  3278 + }
  3279 + sParamData.push(obj);
  3280 + }
  3281 + }
  3282 +
  3283 + const sParamSeletedData = sParamData.filter(item => item.bSelfCbx);
  3284 + if (commonUtils.isNotEmptyArr(sParamSeletedData)) {
  3285 + viewRow.sParams = JSON.stringify(sParamSeletedData);
  3286 + } else {
  3287 + viewRow.sParams = '';
  3288 + }
  3289 +
  3290 + const reportProps = {
  3291 + ...props,
  3292 + viewConfigs: reportViewConfigs,
  3293 + tableConfig: config,
  3294 + iColValueView: 24,
  3295 + viewRow: viewRow,
  3296 + tableName: sName,
  3297 + enabled: props.enabled,
  3298 + enabledNew: props.enabledNew,
  3299 + onDataChange: onDataChange
  3300 + };
  3301 +
  3302 + return (
  3303 + <div style={{ marginTop: '10px', border: '1px solid #d9d9d9', borderRadius: '4px', fontSize: '14px' }}>
  3304 + <div
  3305 + style={{
  3306 + display: 'flex',
  3307 + alignItems: 'center',
  3308 + height: '36px',
  3309 + fontSize: '16px',
  3310 + cursor: 'pointer',
  3311 + borderBottom: '1px solid #d9d9d9',
  3312 + paddingLeft: '12px',
  3313 + fontWeight: 'bold',
  3314 + color: '#1890ff'
  3315 + }}
  3316 + onClick={() => setReportExpand(!reportExpand)}
  3317 + >
  3318 + <span style={{
  3319 + width: '0',
  3320 + height: '0',
  3321 + borderLeft: '6px solid transparent',
  3322 + borderRight: '6px solid transparent',
  3323 + borderTop: reportExpand ? '6px solid #1890ff' : 'none',
  3324 + borderBottom: reportExpand ? 'none' : '6px solid #1890ff',
  3325 + marginRight: '8px'
  3326 + }} />
  3327 + 上报参数
  3328 + </div>
  3329 + {reportExpand && (
  3330 + <div style={{ padding: '10px', fontSize: '14px' }}>
  3331 + <CommonViewTable {...reportProps} />
  3332 + </div>
  3333 + )}
  3334 + </div>
  3335 + );
  3336 +};
  3337 +
3350 // (定制功能)工单参数详情弹窗 3338 // (定制功能)工单参数详情弹窗
3351 const CommonParamsModalComponent = props => { 3339 const CommonParamsModalComponent = props => {
3352 const modalName = "sWorkParamsModalVisible"; // commonParamVisible 3340 const modalName = "sWorkParamsModalVisible"; // commonParamVisible