/* eslint-disable */ import React, { useEffect, useState, useRef } from "react"; import { VerticalLeftOutlined, VerticalRightOutlined } from "@ant-design/icons"; import styles from "./index.less"; import * as commonFunc from "@/components/Common/commonFunc"; 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); const getNum =(num)=>{ return Number(num).toFixed(0); } // 动态生成多个 materialBox const generateMaterialBoxes = () => { const boxes = []; for (let i = 0; i < horizontalBoxes * verticalBoxes; i++) { boxes.push(
{getNum(dMachineLength)}
{getNum(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"; } }, 1); // umijs 需要延时处理 }, [slaveDataDetail] ); const isMax = slaveDataDetail?.dMaxWidth * slaveDataDetail?.dMaxLength > slaveDataDetail?.dMachineLength * slaveDataDetail?.dMachineWidth; const isDPartsLength = Number(slaveDataDetail?.dWlcd) <= slaveDataDetail?.dMaxLength && Number(slaveDataDetail?.dWlkd) <= slaveDataDetail?.dMaxWidth; const MaterialUtilizationRate = commonFunc.showLocalMessage(props, "MaterialUtilizationRate", "材料利用率"); const isShow = slaveDataDetail && slaveDataDetail.dMachineLength && slaveDataDetail.dMaxWidth && slaveDataDetail.dMaxLength && isMax; return ( <> {isShow ? (
{getNum(dWlcd)} {MaterialUtilizationRate}: {availability}%
{getNum(dWlkd)}
{generateMaterialBoxes()}
) : ( "" )} ); }; export default BoxShowImgMaterial;