Commit 4412932ffcf177138c3dbf545cec81c87b161146
1 parent
6da83708
排版
Showing
2 changed files
with
76 additions
and
79 deletions
src/components/Common/Typesetting/typesetting.js
| ... | ... | @@ -86,10 +86,10 @@ const Typesetting = props => { |
| 86 | 86 | // 如果需要自定义排版数 |
| 87 | 87 | |
| 88 | 88 | // 确认是竖向排列还是横向排列 |
| 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; | |
| 89 | + const L = masterData?.dLength; | |
| 90 | + const W = masterData?.dWidth; | |
| 91 | + const H = masterData?.dWidth; | |
| 92 | + const D = masterData?.dHeight; | |
| 93 | 93 | |
| 94 | 94 | // 动态计算公式值 |
| 95 | 95 | const evaluateFormula = (formula, variables) => { |
| ... | ... | @@ -109,14 +109,12 @@ const Typesetting = props => { |
| 109 | 109 | return 0; |
| 110 | 110 | } |
| 111 | 111 | }; |
| 112 | - | |
| 113 | 112 | // 计算公式值 |
| 114 | 113 | const variables = { |
| 115 | 114 | L, |
| 116 | 115 | W, |
| 117 | 116 | H, |
| 118 | 117 | D, |
| 119 | - | |
| 120 | 118 | ...props.slaveRowData, |
| 121 | 119 | }; |
| 122 | 120 | let boxList = []; |
| ... | ... | @@ -140,52 +138,43 @@ const Typesetting = props => { |
| 140 | 138 | { name: "右贴边位", value: "dYTBW" }, |
| 141 | 139 | { name: "右(下)插位组件", value: "dYXCW" }, |
| 142 | 140 | ]; |
| 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 | - }); | |
| 141 | + slaveNewData.forEach(x => { | |
| 142 | + let key = 0; | |
| 143 | + if (x.sAssignFormula) { | |
| 144 | + key = evaluateFormula(x.sAssignFormula, variables); | |
| 145 | + } else { | |
| 146 | + key = slaveRowData[x.sName]; | |
| 147 | + } | |
| 148 | + boxList.push({ | |
| 149 | + value: key, | |
| 150 | + sName: titleList1.find(item => item.value === x.sName)?.name || "", | |
| 151 | + isEditable: true, | |
| 152 | + isSelect: false, | |
| 153 | + selectValue: null, | |
| 154 | + selectLabel: "", | |
| 155 | + selectImage: null, | |
| 156 | + type: x.sTypes || null, | |
| 157 | + show: true, | |
| 158 | + sCode: titleList1.find(item => item.value === x.sName)?.value || "", | |
| 159 | + showName: x.showName, // 参数名称 | |
| 172 | 160 | }); |
| 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 | - }); | |
| 161 | + }); | |
| 162 | + tables.forEach(x => { | |
| 163 | + boxList.push({ | |
| 164 | + value: x.value, | |
| 165 | + sName: x.name, | |
| 166 | + isEditable: true, | |
| 167 | + isSelect: false, | |
| 168 | + selectValue: null, | |
| 169 | + selectLabel: "", | |
| 170 | + selectImage: null, | |
| 171 | + type: x.type || null, | |
| 172 | + show: true, | |
| 173 | + showName: x.name, // 参数名称 | |
| 186 | 174 | }); |
| 187 | - } | |
| 175 | + }); | |
| 188 | 176 | } |
| 177 | + | |
| 189 | 178 | const result = boxList.reduce((acc, { sCode, value }) => ({ ...acc, [sCode]: value }), {}); |
| 190 | 179 | |
| 191 | 180 | // 计算表达式结果 |
| ... | ... | @@ -194,33 +183,42 @@ const Typesetting = props => { |
| 194 | 183 | W, |
| 195 | 184 | H, |
| 196 | 185 | D, |
| 197 | - | |
| 198 | 186 | ...props.slaveRowData, |
| 199 | 187 | ...result, |
| 200 | 188 | }; |
| 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; | |
| 189 | + console.log(variabless, "variabless"); | |
| 190 | + const evaluateFormulas = (formula, variables) => { | |
| 191 | + if (!formula) return ""; // 如果公式为空,返回空字符串 | |
| 207 | 192 | |
| 193 | + 提; //取公式中的变量名 | |
| 194 | + const variableNames = formula.match(/\b[a-zA-Z_][a-zA-Z0-9_]*\b/g) || []; | |
| 195 | + | |
| 196 | + // 替换公式中的变量为实际值 | |
| 197 | + let modifiedFormula = formula; | |
| 198 | + variableNames.forEach(name => { | |
| 199 | + if (variables[name] !== undefined) { | |
| 200 | + modifiedFormula = modifiedFormula.replace(new RegExp(`\\b${name}\\b`, "g"), variables[name]); | |
| 201 | + } | |
| 202 | + }); | |
| 203 | + | |
| 204 | + return modifiedFormula; | |
| 205 | + }; | |
| 206 | + // const s = `((dYXCW + D) >= dSFHS) && ((dYXCW + D) >= dZSCW) | |
| 207 | + // ? (dSFHS >= dZSCW ? -(dYXCW + D - dSFHS) * 2 : -((dYXCW + D) - dZSCW)) * 2 | |
| 208 | + // : dSFHS >= dZSCW ? (dYXCW + D >= dZSCW) ? -(dSFHS - (dYXCW + D)) * 2 : -(dSFHS - dZXCW) * 2 : (dYXCW + D >= dSFHS) ? -(dZSCW - (dYXCW + D)) * 2 : -(dZXCW - dSFHS) * 2` | |
| 209 | + // const ddd = evaluateFormula(s, variabless); | |
| 210 | + // console.log("🚀 ~ ddd:", ddd); | |
| 208 | 211 | let DisableMateriallIcon = L ? sPackDetailPath : null; |
| 209 | 212 | // 盒子展长展开公式计算 |
| 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 | - } | |
| 213 | + const innerWidth = slaveRowData.sTypes === "6" ? evaluateFormula(sWidthFormula, variabless) : evaluateFormula(sLengthFormula, variabless); | |
| 214 | + const innerHeight = slaveRowData.sTypes === "6" ? evaluateFormula(sLengthFormula, variabless) : evaluateFormula(sWidthFormula, variabless); | |
| 217 | 215 | const { sSettingMethod, sSGroupOffset, iFAngle, iSAngle, sSecondorizontalOffset, sSecondLongitudinalOffset } = radioValue ? radioValue : {}; |
| 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); // 第二列纵向偏移 | |
| 216 | + const dFWidthOffset = evaluateFormula(radioValue?.sFWidthOffset, variabless); // 首盒纵向偏移 | |
| 217 | + const dFLengthOffset = evaluateFormula(radioValue?.sFLengthOffset, variabless); // 首盒横向偏移 | |
| 218 | + const dSWidthOffset = evaluateFormula(radioValue?.sSWidthOffset, variabless); // 次盒纵向偏移 | |
| 219 | + const dSLengthOffset = evaluateFormula(radioValue?.sSLengthOffset, variabless); // 次盒横向偏移 | |
| 220 | + const boxLengthOffset = evaluateFormula(sSecondorizontalOffset, variabless); // 第二列横向偏移 | |
| 221 | + const boxWidthOffset = evaluateFormula(sSecondLongitudinalOffset, variabless); // 第二列纵向偏移 | |
| 224 | 222 | const isVertical = sSettingMethod === "从上到下"; // true 表示竖向排列,false 表示横向排列 sSettingMethod === '从上到下' |
| 225 | 223 | const reference = sSGroupOffset === "首盒"; // 第三列参考 |
| 226 | 224 | |
| ... | ... | @@ -317,7 +315,7 @@ const Typesetting = props => { |
| 317 | 315 | dSvgBoxHeight, |
| 318 | 316 | showNew: 2, |
| 319 | 317 | }; |
| 320 | - // const { dZTBW } = variabless; | |
| 318 | + const { dZTBW } = variabless; | |
| 321 | 319 | const createDiv = (col, row, index, leftPosition, topPosition, offsetZ, icon) => ( |
| 322 | 320 | <div |
| 323 | 321 | key={`${col}-${row}-${index}`} |
| ... | ... | @@ -495,6 +493,7 @@ const Typesetting = props => { |
| 495 | 493 | // rows = 1 |
| 496 | 494 | // } |
| 497 | 495 | // } |
| 496 | + console.log(cols, rows, "rows"); | |
| 498 | 497 | |
| 499 | 498 | for (let col = 0; col < cols; col++) { |
| 500 | 499 | for (let row = 0; row < rows; row++) { |
| ... | ... | @@ -561,6 +560,7 @@ const Typesetting = props => { |
| 561 | 560 | // 判断列是否是单独的 |
| 562 | 561 | const newMaterialLength = propsDataLeft + (remaining ? jInnerWidth : innerWidthCombined) - dYBJJ; // 原纸长 |
| 563 | 562 | const newMaterialWidth = propsDataTop + propsDataHeight - dSBLB; |
| 563 | + console.log("🚀 ~ newMaterialWidth:", propsData, propsDataTop, propsDataHeight, newMaterialWidth, newMaterialLength); | |
| 564 | 564 | |
| 565 | 565 | // 计算开数 |
| 566 | 566 | const dSinglePQty = isVertical | ... | ... |
src/components/QuickQuote/index.jsx
| ... | ... | @@ -1764,6 +1764,7 @@ const BoxComponent = props => { |
| 1764 | 1764 | let juantongConfig = {}; |
| 1765 | 1765 | |
| 1766 | 1766 | if (selectedNode.sTypeKey === "juantong") { |
| 1767 | + console.log(selectedNode.sTypeKey, "sTypeKey"); | |
| 1767 | 1768 | |
| 1768 | 1769 | const { dYBJJ, dXBJJ, dZBLB } = slaveData[index]; |
| 1769 | 1770 | juantongConfig = { |
| ... | ... | @@ -1880,17 +1881,10 @@ const BoxComponent = props => { |
| 1880 | 1881 | ...slaveRowData, |
| 1881 | 1882 | }; |
| 1882 | 1883 | |
| 1883 | - const results = slaveNewData.reduce((acc, { sName, sDefault }) => ({ ...acc, [sName]: sDefault }), {}); | |
| 1884 | - let { dSFHS, dHDC, dXFHS, dZSCW, dZTBW, dZXCW, dYSCW, dYTBW, dYXCW } = results; | |
| 1885 | 1884 | slaveNewData.forEach(x => { |
| 1886 | 1885 | let key = 0; |
| 1887 | 1886 | if (x.sAssignFormula) { |
| 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 | - } | |
| 1887 | + key = evaluateFormula(x.sAssignFormula, variables); | |
| 1894 | 1888 | } else { |
| 1895 | 1889 | key = slaveRowData[x.sName]; |
| 1896 | 1890 | } |
| ... | ... | @@ -1932,7 +1926,10 @@ const BoxComponent = props => { |
| 1932 | 1926 | }; |
| 1933 | 1927 | const isShowImg = boxList.find(x => x.sName === "盒身")?.type !== "" || false; |
| 1934 | 1928 | const PrintingParameters = props.getI18nName("PrintingParameters", "印刷参数"); |
| 1935 | - | |
| 1929 | + // props.setState(prevState => ({ | |
| 1930 | + // ...prevState, | |
| 1931 | + // svgBoxList: boxList, | |
| 1932 | + // })); | |
| 1936 | 1933 | return ( |
| 1937 | 1934 | <Tabs |
| 1938 | 1935 | key={boxModel} | ... | ... |