Commit 6da837081e2baa695c75ca2c3f0b50a1c0694639
1 parent
1bc3c73f
使用eval计算
Showing
2 changed files
with
95 additions
and
63 deletions
src/components/Common/Typesetting/typesetting.js
| ... | ... | @@ -38,13 +38,13 @@ const Typesetting = props => { |
| 38 | 38 | sColumnNameConfig, |
| 39 | 39 | bAdvancedSetting, // 高级设置 |
| 40 | 40 | } = slaveRowData; |
| 41 | - | |
| 41 | + | |
| 42 | 42 | const { masterData, selectedNode, slaveData } = state; |
| 43 | 43 | // 如果是卷筒类 那么上下左右留白等于左留白 |
| 44 | - if (selectedNode && selectedNode.sTypeKey === 'juantong') { | |
| 45 | - dSBLB = dZBLB | |
| 46 | - dXBLB = dZBLB | |
| 47 | - dYBLB = dZBLB | |
| 44 | + if (selectedNode && selectedNode.sTypeKey === "juantong") { | |
| 45 | + dSBLB = dZBLB; | |
| 46 | + dXBLB = dZBLB; | |
| 47 | + dYBLB = dZBLB; | |
| 48 | 48 | } |
| 49 | 49 | // 生成盒子图片 |
| 50 | 50 | const [boxKey, setBoxKey] = useState(new Date().getTime()); |
| ... | ... | @@ -86,10 +86,10 @@ const Typesetting = props => { |
| 86 | 86 | // 如果需要自定义排版数 |
| 87 | 87 | |
| 88 | 88 | // 确认是竖向排列还是横向排列 |
| 89 | - const L = masterData?.dLength; | |
| 90 | - const W = masterData?.dWidth; | |
| 91 | - const H = masterData?.dWidth; | |
| 92 | - const D = masterData?.dHeight; | |
| 89 | + const L = Number(masterData?.dLength) ?? 0; | |
| 90 | + const W = Number(masterData?.dWidth) ?? 0; | |
| 91 | + const H = Number(masterData?.dWidth) ?? 0; | |
| 92 | + const D = Number(masterData?.dHeight) ?? 0; | |
| 93 | 93 | |
| 94 | 94 | // 动态计算公式值 |
| 95 | 95 | const evaluateFormula = (formula, variables) => { |
| ... | ... | @@ -109,6 +109,7 @@ const Typesetting = props => { |
| 109 | 109 | return 0; |
| 110 | 110 | } |
| 111 | 111 | }; |
| 112 | + | |
| 112 | 113 | // 计算公式值 |
| 113 | 114 | const variables = { |
| 114 | 115 | L, |
| ... | ... | @@ -139,43 +140,52 @@ const Typesetting = props => { |
| 139 | 140 | { name: "右贴边位", value: "dYTBW" }, |
| 140 | 141 | { name: "右(下)插位组件", value: "dYXCW" }, |
| 141 | 142 | ]; |
| 142 | - slaveNewData.forEach(x => { | |
| 143 | - let key = 0; | |
| 144 | - if (x.sAssignFormula) { | |
| 145 | - key = evaluateFormula(x.sAssignFormula, variables); | |
| 146 | - } else { | |
| 147 | - key = slaveRowData[x.sName]; | |
| 148 | - } | |
| 149 | - boxList.push({ | |
| 150 | - value: key, | |
| 151 | - sName: titleList1.find(item => item.value === x.sName)?.name || "", | |
| 152 | - isEditable: true, | |
| 153 | - isSelect: false, | |
| 154 | - selectValue: null, | |
| 155 | - selectLabel: "", | |
| 156 | - selectImage: null, | |
| 157 | - type: x.sTypes || null, | |
| 158 | - show: true, | |
| 159 | - sCode: titleList1.find(item => item.value === x.sName)?.value || "", | |
| 160 | - showName: x.showName, // 参数名称 | |
| 143 | + const results = slaveNewData.reduce((acc, { sName, sDefault }) => ({ ...acc, [sName]: sDefault }), {}); | |
| 144 | + let { dSFHS, dHDC, dXFHS, dZSCW, dZTBW, dZXCW, dYSCW, dYTBW, dYXCW } = results; | |
| 145 | + if (results) { | |
| 146 | + slaveNewData.forEach(x => { | |
| 147 | + let key = 0; | |
| 148 | + if (x.sAssignFormula) { | |
| 149 | + const i = titleList1.findIndex(item => item.value === x.sAssignFormula); | |
| 150 | + if (i !== -1) { | |
| 151 | + key = results[x.sAssignFormula]; | |
| 152 | + } else { | |
| 153 | + key = eval(x.sAssignFormula); | |
| 154 | + } | |
| 155 | + } else { | |
| 156 | + key = slaveRowData[x.sName]; | |
| 157 | + } | |
| 158 | + boxList.push({ | |
| 159 | + value: key, | |
| 160 | + sName: titleList1.find(item => item.value === x.sName)?.name || "", | |
| 161 | + isEditable: true, | |
| 162 | + isSelect: false, | |
| 163 | + selectValue: null, | |
| 164 | + selectLabel: "", | |
| 165 | + selectImage: null, | |
| 166 | + type: x.sTypes || null, | |
| 167 | + show: true, | |
| 168 | + sCode: titleList1.find(item => item.value === x.sName)?.value || "", | |
| 169 | + showName: x.showName, // 参数名称 | |
| 170 | + sAssignFormula: x.sAssignFormula, | |
| 171 | + }); | |
| 161 | 172 | }); |
| 162 | - }); | |
| 163 | - tables.forEach(x => { | |
| 164 | - boxList.push({ | |
| 165 | - value: x.value, | |
| 166 | - sName: x.name, | |
| 167 | - isEditable: true, | |
| 168 | - isSelect: false, | |
| 169 | - selectValue: null, | |
| 170 | - selectLabel: "", | |
| 171 | - selectImage: null, | |
| 172 | - type: x.type || null, | |
| 173 | - show: true, | |
| 174 | - showName: x.name, // 参数名称 | |
| 173 | + tables.forEach(x => { | |
| 174 | + boxList.push({ | |
| 175 | + value: x.value, | |
| 176 | + sName: x.name, | |
| 177 | + isEditable: true, | |
| 178 | + isSelect: false, | |
| 179 | + selectValue: null, | |
| 180 | + selectLabel: "", | |
| 181 | + selectImage: null, | |
| 182 | + type: x.type || null, | |
| 183 | + show: true, | |
| 184 | + showName: x.name, // 参数名称 | |
| 185 | + }); | |
| 175 | 186 | }); |
| 176 | - }); | |
| 187 | + } | |
| 177 | 188 | } |
| 178 | - | |
| 179 | 189 | const result = boxList.reduce((acc, { sCode, value }) => ({ ...acc, [sCode]: value }), {}); |
| 180 | 190 | |
| 181 | 191 | // 计算表达式结果 |
| ... | ... | @@ -188,18 +198,29 @@ const Typesetting = props => { |
| 188 | 198 | ...props.slaveRowData, |
| 189 | 199 | ...result, |
| 190 | 200 | }; |
| 201 | + const keys = ["dSFHS", "dHDC", "dXFHS", "dZSCW", "dZTBW", "dZXCW", "dYSCW", "dYTBW", "dYXCW"]; | |
| 202 | + for (let key of keys) { | |
| 203 | + let num = Number(variabless[key]); // 将变量值转换为数字 | |
| 204 | + result[key] = Number.isNaN(num) ? 0 : num; // 如果是 NaN,则设置为 0,否则保留原值 | |
| 205 | + } | |
| 206 | + let { dSFHS, dHDC, dXFHS, dZSCW, dZTBW, dZXCW, dYSCW, dYTBW, dYXCW } = result; | |
| 191 | 207 | |
| 192 | 208 | let DisableMateriallIcon = L ? sPackDetailPath : null; |
| 193 | 209 | // 盒子展长展开公式计算 |
| 194 | - const innerWidth = slaveRowData.sTypes === "6" ? evaluateFormula(sWidthFormula, variabless) : evaluateFormula(sLengthFormula, variabless); | |
| 195 | - const innerHeight = slaveRowData.sTypes === "6" ? evaluateFormula(sLengthFormula, variabless) : evaluateFormula(sWidthFormula, variabless); | |
| 210 | + | |
| 211 | + let innerWidth = slaveRowData.sTypes === "6" ? eval(sWidthFormula) : eval(sLengthFormula); | |
| 212 | + let innerHeight = slaveRowData.sTypes === "6" ? eval(sLengthFormula) : eval(sWidthFormula); | |
| 213 | + if (isNaN(innerHeight) || isNaN(innerHeight)) { | |
| 214 | + innerWidth = 0; | |
| 215 | + innerHeight = 0; | |
| 216 | + } | |
| 196 | 217 | const { sSettingMethod, sSGroupOffset, iFAngle, iSAngle, sSecondorizontalOffset, sSecondLongitudinalOffset } = radioValue ? radioValue : {}; |
| 197 | - const dFWidthOffset = evaluateFormula(radioValue?.sFWidthOffset, variabless); // 首盒纵向偏移 | |
| 198 | - const dFLengthOffset = evaluateFormula(radioValue?.sFLengthOffset, variabless); // 首盒横向偏移 | |
| 199 | - const dSWidthOffset = evaluateFormula(radioValue?.sSWidthOffset, variabless); // 次盒纵向偏移 | |
| 200 | - const dSLengthOffset = evaluateFormula(radioValue?.sSLengthOffset, variabless); // 次盒横向偏移 | |
| 201 | - const boxLengthOffset = evaluateFormula(sSecondorizontalOffset, variabless); // 第二列横向偏移 | |
| 202 | - const boxWidthOffset = evaluateFormula(sSecondLongitudinalOffset, variabless); // 第二列纵向偏移 | |
| 218 | + const dFWidthOffset = eval(radioValue?.sFWidthOffset); // 首盒纵向偏移 | |
| 219 | + const dFLengthOffset = eval(radioValue?.sFLengthOffset); // 首盒横向偏移 | |
| 220 | + const dSWidthOffset = eval(radioValue?.sSWidthOffset); // 次盒纵向偏移 | |
| 221 | + const dSLengthOffset = eval(radioValue?.sSLengthOffset); // 次盒横向偏移 | |
| 222 | + const boxLengthOffset = eval(sSecondorizontalOffset); // 第二列横向偏移 | |
| 223 | + const boxWidthOffset = eval(sSecondLongitudinalOffset); // 第二列纵向偏移 | |
| 203 | 224 | const isVertical = sSettingMethod === "从上到下"; // true 表示竖向排列,false 表示横向排列 sSettingMethod === '从上到下' |
| 204 | 225 | const reference = sSGroupOffset === "首盒"; // 第三列参考 |
| 205 | 226 | |
| ... | ... | @@ -296,7 +317,7 @@ const Typesetting = props => { |
| 296 | 317 | dSvgBoxHeight, |
| 297 | 318 | showNew: 2, |
| 298 | 319 | }; |
| 299 | - const { dZTBW } = variabless; | |
| 320 | + // const { dZTBW } = variabless; | |
| 300 | 321 | const createDiv = (col, row, index, leftPosition, topPosition, offsetZ, icon) => ( |
| 301 | 322 | <div |
| 302 | 323 | key={`${col}-${row}-${index}`} |
| ... | ... | @@ -467,15 +488,14 @@ const Typesetting = props => { |
| 467 | 488 | }, [radioValue, slaveRowData, masterData, selectedNode, slaveData]); |
| 468 | 489 | // 生成里层 div 的数组 |
| 469 | 490 | const innerDivs = []; |
| 470 | - // 如果第一列 | |
| 491 | + // 如果第一列 | |
| 471 | 492 | // if (rows === 0) { |
| 472 | 493 | // const maxWidth = Number(slaveDataDetail?.dMaxWidth) |
| 473 | 494 | // if (maxWidth > innerHeight) { |
| 474 | 495 | // rows = 1 |
| 475 | 496 | // } |
| 476 | 497 | // } |
| 477 | - console.log(cols,rows,'rows'); | |
| 478 | - | |
| 498 | + | |
| 479 | 499 | for (let col = 0; col < cols; col++) { |
| 480 | 500 | for (let row = 0; row < rows; row++) { |
| 481 | 501 | const leftPosition = col * innerWidthCombined; |
| ... | ... | @@ -523,8 +543,7 @@ const Typesetting = props => { |
| 523 | 543 | innerDivs.push(createBoxOne(0, rows, 3, leftPosition + dZBLB, topPosition + dSBLB, iFAngle, DisableMateriallIcon)); |
| 524 | 544 | } |
| 525 | 545 | } |
| 526 | - | |
| 527 | - | |
| 546 | + | |
| 528 | 547 | // 判断展开长展开宽是否变化 |
| 529 | 548 | if (dPartsLength !== innerWidth && !innerDivs.length) { |
| 530 | 549 | setDPartsLength(innerWidth); |
| ... | ... | @@ -542,7 +561,6 @@ const Typesetting = props => { |
| 542 | 561 | // 判断列是否是单独的 |
| 543 | 562 | const newMaterialLength = propsDataLeft + (remaining ? jInnerWidth : innerWidthCombined) - dYBJJ; // 原纸长 |
| 544 | 563 | const newMaterialWidth = propsDataTop + propsDataHeight - dSBLB; |
| 545 | - console.log("🚀 ~ newMaterialWidth:",propsData,propsDataTop,propsDataHeight, newMaterialWidth,newMaterialLength) | |
| 546 | 564 | |
| 547 | 565 | // 计算开数 |
| 548 | 566 | const dSinglePQty = isVertical |
| ... | ... | @@ -634,8 +652,16 @@ const Typesetting = props => { |
| 634 | 652 | Number(slaveDataDetail?.dMaxLength) >= Number(slaveRowData?.dMachineLength) && |
| 635 | 653 | Number(slaveDataDetail?.dMaxWidth) >= Number(slaveRowData?.dMachineWidth); |
| 636 | 654 | |
| 637 | - const isShow =slaveRowData && slaveRowData.dMachineLength && slaveRowData.dMaxWidth && slaveRowData.dMaxLength && isMax && innerDivs.length; | |
| 638 | -console.log( slaveDataDetail?.dMaxLength,slaveDataDetail?.dMaxWidth,slaveRowData?.dMachineLength,slaveRowData?.dMachineWidth,isMax,isShow,'isMax'); | |
| 655 | + const isShow = slaveRowData && slaveRowData.dMachineLength && slaveRowData.dMaxWidth && slaveRowData.dMaxLength && isMax && innerDivs.length; | |
| 656 | + console.log( | |
| 657 | + slaveDataDetail?.dMaxLength, | |
| 658 | + slaveDataDetail?.dMaxWidth, | |
| 659 | + slaveRowData?.dMachineLength, | |
| 660 | + slaveRowData?.dMachineWidth, | |
| 661 | + isMax, | |
| 662 | + isShow, | |
| 663 | + "isMax" | |
| 664 | + ); | |
| 639 | 665 | |
| 640 | 666 | if (isCustomized && !isShow) { |
| 641 | 667 | if (isMobile) return; | ... | ... |
src/components/QuickQuote/index.jsx
| ... | ... | @@ -1762,9 +1762,8 @@ const BoxComponent = props => { |
| 1762 | 1762 | dPortraitType: dPortraitType, |
| 1763 | 1763 | }; |
| 1764 | 1764 | let juantongConfig = {}; |
| 1765 | - | |
| 1765 | + | |
| 1766 | 1766 | if (selectedNode.sTypeKey === "juantong") { |
| 1767 | - console.log(selectedNode.sTypeKey,'sTypeKey'); | |
| 1768 | 1767 | |
| 1769 | 1768 | const { dYBJJ, dXBJJ, dZBLB } = slaveData[index]; |
| 1770 | 1769 | juantongConfig = { |
| ... | ... | @@ -1881,10 +1880,17 @@ const BoxComponent = props => { |
| 1881 | 1880 | ...slaveRowData, |
| 1882 | 1881 | }; |
| 1883 | 1882 | |
| 1883 | + const results = slaveNewData.reduce((acc, { sName, sDefault }) => ({ ...acc, [sName]: sDefault }), {}); | |
| 1884 | + let { dSFHS, dHDC, dXFHS, dZSCW, dZTBW, dZXCW, dYSCW, dYTBW, dYXCW } = results; | |
| 1884 | 1885 | slaveNewData.forEach(x => { |
| 1885 | 1886 | let key = 0; |
| 1886 | 1887 | if (x.sAssignFormula) { |
| 1887 | - key = evaluateFormula(x.sAssignFormula, variables); | |
| 1888 | + const i = titleList1.findIndex(item => item.value === x.sAssignFormula); | |
| 1889 | + if (i !== -1) { | |
| 1890 | + key = results[x.sAssignFormula]; | |
| 1891 | + } else { | |
| 1892 | + key = eval(x.sAssignFormula); | |
| 1893 | + } | |
| 1888 | 1894 | } else { |
| 1889 | 1895 | key = slaveRowData[x.sName]; |
| 1890 | 1896 | } | ... | ... |