#
luxiaotao1123
2024-10-23 3af87f4424fda51760188233983cd8d4a4586c50
zy-acs-flow/src/map/insight/shelf/ShelfMain.jsx
@@ -15,23 +15,36 @@
import { grey } from '@mui/material/colors';
import ConfirmButton from '../../../page/components/ConfirmButton';
let shelfThree;
const ShelfMain = (props) => {
    const { row, bay, curLocNo, curShelfInfo: info, setCurLocNo } = props;
    const translate = useTranslate();
    const dataProvider = useDataProvider();
    const redirect = useRedirect();
    const containerRef = useRef();
    const [selectedLoc, setSelectedLoc] = useState(null);   // loc obj
    const [loading, setLoading] = useState(true);
    const shelfThreeRef = useRef(null);
const startThree = (dom) => {
    shelfThree = new ShelfThree(dom);
    shelfThree.startup();
        if (shelfThreeRef.current) {
            shelfThreeRef.current.destroy();
}
        shelfThreeRef.current = new ShelfThree(dom);
        shelfThreeRef.current.startup();
    };
const endThree = () => {
    if (shelfThree) {
        shelfThree.destroy();
        shelfThree = null;
        if (shelfThreeRef.current) {
            shelfThreeRef.current.destroy();
            shelfThreeRef.current = null;
    }
}
    };
const renderThree = (info, curLocNo) => {
    if (info && shelfThree) {
        shelfThree.generateMesh((loader, addObject) => {
        if (info && shelfThreeRef.current) {
            shelfThreeRef.current.generateMesh((loader, addObject) => {
            const promises = [];
            const singleHeight = 123;
            for (const item of info) {
@@ -58,58 +71,46 @@
                                    default:
                                        break;
                                }
                                child.name = item.locNo
                                    child.name = item.locNo;
                                child.castShadow = true;
                                child.receiveShadow = true;
                            }
                        });
                        addObject(mesh);
                        resolve();
                    })
                        });
                }));
            }
            Promise.all(promises).then(() => {
                if (shelfThree) {
                    if (typeof shelfThree.setNewSelectedMesh === 'function') {
                        shelfThree.setNewSelectedMesh(curLocNo);
                    if (shelfThreeRef.current) {
                        if (typeof shelfThreeRef.current.setNewSelectedMesh === 'function') {
                            shelfThreeRef.current.setNewSelectedMesh(curLocNo);
                    }
                    if (typeof shelfThree.rePerspective === 'function') {
                        shelfThree.rePerspective(singleHeight * info.length, 500);
                        if (typeof shelfThreeRef.current.rePerspective === 'function') {
                            shelfThreeRef.current.rePerspective(singleHeight * info.length, 500);
                    }
                }
            }).catch(error => {
                console.error(error);
            });
        })
            });
    }
}
const ShelfMain = (props) => {
    const { row, bay, curLocNo, curShelfInfo: info, setCurLocNo } = props;
    const translate = useTranslate();
    const dataProvider = useDataProvider();
    const redirect = useRedirect();
    const containerRef = useRef();
    const [selectedLoc, setSelectedLoc] = useState(null);   // loc obj
    const [loading, setLoading] = useState(true);
    };
    useEffect(() => {
        if (info) {
            setSelectedLoc(info[0]);
            endThree();
            setLoading(true);
            setTimeout(() => {
                startThree(containerRef.current);
                shelfThree.handleClick = (objName) => {
                shelfThreeRef.current.handleClick = (objName) => {
                    setCurLocNo(objName);
                    setSelectedLoc(info.find(loc => objName === loc.locNo));
                };
                renderThree(info, curLocNo);
                setLoading(false);
            }, 200)
            }, 200);
        }
        return endThree;
    }, [info]);
@@ -127,7 +128,7 @@
            notify.success(translate('common.response.fail'));
            console.error(`Error: ${error.message}`);
        });
    }
    };
    return (
        <Box display="flex" height="100%">