| | |
| | | Stack, |
| | | } from '@mui/material'; |
| | | import ShelfThree from './ShelfThree'; |
| | | import request from '@/utils/request'; |
| | | import { getLocGroup } from '../../http'; |
| | | |
| | | let shelfThree; |
| | | |
| | | const startThree = (dom) => { |
| | | shelfThree = new ShelfThree(dom); |
| | | shelfThree.startup(); |
| | | } |
| | | |
| | | const endThree = () => { |
| | | if (shelfThree) { |
| | | shelfThree.destroy(); |
| | | shelfThree = null; |
| | | } |
| | | } |
| | | |
| | | const renderThree = (info, curLocNo) => { |
| | | if (info && shelfThree) { |
| | | shelfThree.generateMesh((loader, addObject) => { |
| | | const promises = []; |
| | | const singleHeight = 123; |
| | | for (const item of info) { |
| | | const { lev } = item; |
| | | promises.push(new Promise((resolve) => { |
| | | loader.load('model/shelf.fbx', (mesh) => { |
| | | mesh.position.set(0, singleHeight * (lev - 1), 0); |
| | | mesh.scale.set(5, 5, 5); |
| | | mesh.name = item.locNo; |
| | | mesh.traverse(function (child) { |
| | | if (child.isMesh) { |
| | | if (child.name === '货架') { |
| | | child.material.color.set(0x4680BF); |
| | | } |
| | | let palletVisible = true, cargoVisible = true; |
| | | switch (item.locStsEl) { |
| | | case 'STOCK': |
| | | cargoVisible = false; |
| | | break; |
| | | case 'IDLE': |
| | | palletVisible = false; |
| | | cargoVisible = false; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | if (child.name === '托盘') { |
| | | child.visible = palletVisible; |
| | | child.material.color.set(0xBEBEBE); |
| | | } |
| | | if (child.name === '不规则') { |
| | | child.visible = cargoVisible; |
| | | child.material.color.set(0xE8B67E); |
| | | } |
| | | child.name = item.locNo |
| | | child.castShadow = true; |
| | | child.receiveShadow = true; |
| | | } |
| | | }); |
| | | addObject(mesh); |
| | | resolve(); |
| | | }) |
| | | })); |
| | | |
| | | } |
| | | |
| | | Promise.all(promises).then(() => { |
| | | shelfThree.setNewSelectedMesh(curLocNo); |
| | | shelfThree.rePerspective(singleHeight * info.length, 500); |
| | | }).catch(error => { |
| | | console.error(error); |
| | | }); |
| | | |
| | | }) |
| | | } |
| | | } |
| | | |
| | | const ShelfMain = (props) => { |
| | | const { data, curLocNo, setCurLocNo } = props; |
| | |
| | | const [loading, setLoading] = useState(true); |
| | | const [shelfThree, setShelfThree] = useState(null); |
| | | const [info, setInfo] = useState(null); |
| | | |
| | | |
| | | |
| | | useEffect(() => { |
| | | if (data) { |
| | | getLocGroup(data.row, data.bay, (response) => { |
| | | setInfo(response); |
| | | setCurLocNo(response[0]?.locNo); |
| | | }); |
| | | } |
| | | }, [data]); |
| | | |
| | | useEffect(() => { |
| | | if (info) { |
| | | endThree(); |
| | | setLoading(true); |
| | | |
| | | setTimeout(() => { |
| | | startThree(containerRef.current); |
| | | shelfThree.handleClick = (objName) => { |
| | | setCurLocNo(objName); |
| | | }; |
| | | renderThree(info, curLocNo); |
| | | setLoading(false); |
| | | }, 300) |
| | | |
| | | } |
| | | |
| | | return endThree; |
| | | }, [info]); |
| | | |
| | | |
| | | |
| | | useEffect(() => { |
| | | const initThree = () => { |
| | |
| | | setShelfThree(shelfThreeInstance); |
| | | setLoading(false); |
| | | // Fetch initial data |
| | | fetchShelfInfo(curLocNo); |
| | | }; |
| | | |
| | | initThree(); |
| | |
| | | }; |
| | | }, []); |
| | | |
| | | useEffect(() => { |
| | | if (curLocNo) { |
| | | fetchShelfInfo(curLocNo); |
| | | } |
| | | }, [curLocNo]); |
| | | |
| | | const fetchShelfInfo = async (locNo) => { |
| | | // 假设有一个函数来获取货架信息 |
| | | const res = await fetchShelfData(locNo); |
| | | if (res?.data) { |
| | | setInfo(res.data); |
| | | } |
| | | }; |
| | | |
| | | return ( |
| | | <Box display="flex" height="500px"> |
| | |
| | | )} |
| | | </Box> |
| | | <Box width="40%" height="100%" overflow="auto" p={2}> |
| | | <Paper elevation={3} style={{ padding: '16px' }}> |
| | | {/* <Paper elevation={3} style={{ padding: '16px' }}> |
| | | <Typography variant="h6" gutterBottom> |
| | | {translate('map.loc.no', { defaultMessage: '库位号' })}: {curLocNo} |
| | | </Typography> |
| | |
| | | </Stack> |
| | | </Grid> |
| | | </Grid> |
| | | </Paper> |
| | | </Paper> */} |
| | | </Box> |
| | | </Box> |
| | | ); |