Commit 45ebf8e3f956129dd7b9e4805b6a913b9622ac63

Authored by chenxt
1 parent ebc96979

颜色选择输入框

src/mes/common/commonModelComponent/index.js
1 /* eslint-disable */ 1 /* eslint-disable */
2 -import React, { useEffect, useRef, useState } from "react"; 2 +import React, { useEffect, useRef, useState, useCallback, memo } from "react";
3 import moment from "moment"; 3 import moment from "moment";
4 import { cloneDeep } from "lodash"; 4 import { cloneDeep } from "lodash";
5 -import { Tabs, Modal, Space, Button, DatePicker, Radio, message, Avatar, Row, Col, Table } from "antd"; 5 +import { Tabs, Modal, Space, Button, DatePicker, Radio, message, Avatar, Row, Col, Table, Input } from "antd";
6 import * as commonUtils from "@/utils/utils"; 6 import * as commonUtils from "@/utils/utils";
7 import * as commonConfig from "@/utils/config"; 7 import * as commonConfig from "@/utils/config";
8 import * as commonServices from "@/services/services"; 8 import * as commonServices from "@/services/services";
@@ -3487,6 +3487,34 @@ const TaskConfirmModal = props => { @@ -3487,6 +3487,34 @@ const TaskConfirmModal = props => {
3487 ); 3487 );
3488 }; 3488 };
3489 3489
  3490 +// 板数输入框:本地 state 维护输入值,仅 blur 时同步到父级,避免输入过程中表格重渲染导致失焦
  3491 +const PlateNumInput = memo(({ value, sId, onCommit }) => {
  3492 + const [inputValue, setInputValue] = useState(value || 0);
  3493 +
  3494 + // 父级 value 变化时同步本地(本行 blur 提交后或外部改动)
  3495 + useEffect(() => {
  3496 + setInputValue(value || 0);
  3497 + }, [value]);
  3498 +
  3499 + const handleChange = (e) => {
  3500 + const filtered = (e.target.value || '').toString().replace(/[^\d]/g, '');
  3501 + setInputValue(filtered);
  3502 + };
  3503 +
  3504 + const handleBlur = () => {
  3505 + onCommit(inputValue, sId);
  3506 + };
  3507 +
  3508 + return (
  3509 + <Input
  3510 + value={inputValue}
  3511 + onChange={handleChange}
  3512 + onBlur={handleBlur}
  3513 + style={{ width: '120px', border: '1px solid #d9d9d9', borderRadius: '4px' }}
  3514 + />
  3515 + );
  3516 +});
  3517 +
3490 const SisColorChooseComponent = props => { 3518 const SisColorChooseComponent = props => {
3491 const { sisColorChooseVisible, sisColorField, sisTableName, controlSelectedRowId } = props; 3519 const { sisColorChooseVisible, sisColorField, sisTableName, controlSelectedRowId } = props;
3492 3520
@@ -3517,6 +3545,18 @@ const SisColorChooseComponent = props =&gt; { @@ -3517,6 +3545,18 @@ const SisColorChooseComponent = props =&gt; {
3517 setRightData([]); 3545 setRightData([]);
3518 } 3546 }
3519 }, [props.sisColorSelectedData, props.sisColorChooseVisible, sisTableName, controlSelectedRowId, sisColorField, props]) 3547 }, [props.sisColorSelectedData, props.sisColorChooseVisible, sisTableName, controlSelectedRowId, sisColorField, props])
  3548 +
  3549 + // 注意:此处 useCallback 必须在下面的 early return 之前调用,否则会违反 Rules of Hooks
  3550 + const handlePlateNumChange = useCallback((value, sId) => {
  3551 + const numValue = (value || '').toString().replace(/[^\d]/g, '');
  3552 + setRightData(prev => prev.map(item => {
  3553 + if (item.sId === sId) {
  3554 + return { ...item, dColor: Number(numValue) };
  3555 + }
  3556 + return item;
  3557 + }));
  3558 + }, []);
  3559 +
3520 if (!sisColorChooseVisible) return ""; 3560 if (!sisColorChooseVisible) return "";
3521 3561
3522 const handleClose = () => { 3562 const handleClose = () => {
@@ -3666,34 +3706,16 @@ const SisColorChooseComponent = props =&gt; { @@ -3666,34 +3706,16 @@ const SisColorChooseComponent = props =&gt; {
3666 }, 3706 },
3667 ]; 3707 ];
3668 3708
3669 - const handlePlateNumChange = (value, record) => {  
3670 - const numValue = value.replace(/[^\d]/g, '');  
3671 - const newData = rightData.map(item => {  
3672 - if (item.sId === record.sId) {  
3673 - return { ...item, dColor: Number(numValue) || 0 };  
3674 - }  
3675 - return item;  
3676 - });  
3677 - setRightData(newData);  
3678 - };  
3679 -  
3680 const rightColumns = [ 3709 const rightColumns = [
3681 ...baseColumns.map(col => { 3710 ...baseColumns.map(col => {
3682 if (col.dataIndex === 'dColor') { 3711 if (col.dataIndex === 'dColor') {
3683 return { 3712 return {
3684 ...col, 3713 ...col,
3685 render: (text, record) => ( 3714 render: (text, record) => (
3686 - <input  
3687 - type="text"  
3688 - value={text || 0}  
3689 - onChange={(e) => handlePlateNumChange(e.target.value, record)}  
3690 - style={{  
3691 - width: '120px',  
3692 - padding: '4px 8px',  
3693 - border: '1px solid #d9d9d9',  
3694 - borderRadius: '4px',  
3695 - fontSize: '14px'  
3696 - }} 3715 + <PlateNumInput
  3716 + value={text}
  3717 + sId={record.sId}
  3718 + onCommit={handlePlateNumChange}
3697 /> 3719 />
3698 ) 3720 )
3699 }; 3721 };