/* eslint-disable */ import React, { useEffect, useState, useRef } from "react"; import { VerticalLeftOutlined, VerticalRightOutlined } from "@ant-design/icons"; import styles from "./index.less"; import { bottom } from "react-grid-layout/build/utils"; import { transform } from "@antv/g2/lib/util/transform"; const BoxShowImgMaterial = props => { const boxRef = useRef(null); const textRef = useRef(null); const textRefs = useRef(null); const nTextRefs = useRef(null); const nTextRef = useRef(null); const [boxKey, setBoxKey] = useState(new Date().getTime()); const clientWidth = 300; const clientHeight = 250; // 找出盒型信息 const { slaveData, selectedNode } = props.state; const { boxModel } = props; const slaveDataDetail = slaveData?.find(item => item.sTreeNodeName === selectedNode.showName && item.sBoxModel === boxModel); if (slaveDataDetail) { // 最大上机长 上机宽 排版长 排版宽 材料长 材料宽 var { dMaxLength, dMaxWidth, dMachineLength, dMachineWidth, dWlcd, dWlkd, dSBLB, dXBLB, dZBLB, dYBLB, scale } = slaveDataDetail; } // 计算可以放置的盒子数量 const horizontalBoxes = Math.floor(dWlcd / dMachineLength); const verticalBoxes = Math.floor(dWlkd / dMachineWidth); const scaleX = (clientWidth - 70) / (dWlcd); const scaleY = (clientHeight - 70) / (dWlkd); // 动态生成多个 materialBox const generateMaterialBoxes = () => { const boxes = []; for (let i = 0; i < horizontalBoxes * verticalBoxes; i++) { boxes.push(
{dMachineLength}
{dMachineWidth}
); } return boxes; }; // 计算材料利用率 const availability = ( ((horizontalBoxes * verticalBoxes * (Number(dMachineLength) * Number(dMachineWidth))) / (Number(dWlcd) * Number(dWlkd))) * 100 ).toFixed(2); useEffect( () => { // setBoxKey(new Date().getTime()); setTimeout(() => { // if (boxRef.current && textRef.current && textRefs.current && nTextRef.current && nTextRefs.current) if (boxRef.current && textRef.current && textRefs.current && nTextRef.current && nTextRefs.current) { // 计算父元素的缩放因子 // 对父元素应用缩放 boxRef.current.style.transform = `scale(${scaleX}, ${scaleY})`; boxRef.current.style.transformOrigin = "top left"; // // 对子元素应用逆缩放 textRef.current.style.transform = `scale(${1 / scaleX}, ${1 / scaleY})`; textRef.current.style.transformOrigin = "top left"; textRefs.current.style.transform = `scale(${1 / scaleX}, ${1 / scaleY})`; textRefs.current.style.transformOrigin = "top left"; } }, 0); }, [slaveDataDetail] ); const isMax = slaveDataDetail?.dMaxWidth * slaveDataDetail?.dMaxLength > slaveDataDetail?.dMachineLength * slaveDataDetail?.dMachineWidth; const isDPartsLength = slaveDataDetail?.dPartsLength < slaveDataDetail?.dMaxLength && slaveDataDetail?.dPartsWidth < slaveDataDetail?.dMaxWidth; const isShow = isDPartsLength && slaveDataDetail && slaveDataDetail.dMachineLength && slaveDataDetail.dMaxWidth && slaveDataDetail.dMaxLength && isMax; return ( <> {isShow ? (
{dWlcd} 材料利用率: {availability}%
{dWlkd}
{generateMaterialBoxes()}
) : ( "" )} ); }; export default BoxShowImgMaterial;