Commit 7c52ca8afa3f39128d0abf00c8ed6332a3db7e47
1 parent
ccba4bb7
盒型设计
Showing
2 changed files
with
54 additions
and
11 deletions
src/components/Common/BoxDesignCompontent/index.js
| @@ -311,6 +311,17 @@ const BoxDesignCompontent = baseProps => { | @@ -311,6 +311,17 @@ const BoxDesignCompontent = baseProps => { | ||
| 311 | setTopBoxList(box.filter(topBoxFilter)); | 311 | setTopBoxList(box.filter(topBoxFilter)); |
| 312 | setLeftBoxList(box.filter(leftBoxFilter)); | 312 | setLeftBoxList(box.filter(leftBoxFilter)); |
| 313 | setRightBoxList(box.filter(rightBoxFilter)); | 313 | setRightBoxList(box.filter(rightBoxFilter)); |
| 314 | + } else if (type === "8" || type === 8) { | ||
| 315 | + const box = [...boxList]; | ||
| 316 | + box.forEach(x => { | ||
| 317 | + x.show = true; | ||
| 318 | + }); | ||
| 319 | + const topBoxFilter = item => item.sName === "左上插位组件" || item.sName === "上插位组件" || item.sName === "右上插位组件"; | ||
| 320 | + const leftBoxFilter = item => item.sName === "左偏移" || item.sName === "左插位组件" || item.sName === "左下插位组件"; | ||
| 321 | + const rightBoxFilter = item => item.sName === "右偏移" || item.sName === "右插位组件" || item.sName === "右下插位组件"; | ||
| 322 | + setTopDoubleBoxList(box.filter(topBoxFilter)); | ||
| 323 | + setLeftDoubleBoxList(box.filter(leftBoxFilter)); | ||
| 324 | + setRightDoubleBoxList(box.filter(rightBoxFilter)); | ||
| 314 | } else { | 325 | } else { |
| 315 | const box = [...boxList]; | 326 | const box = [...boxList]; |
| 316 | box.forEach(x => { | 327 | box.forEach(x => { |
| @@ -350,6 +361,7 @@ const BoxDesignCompontent = baseProps => { | @@ -350,6 +361,7 @@ const BoxDesignCompontent = baseProps => { | ||
| 350 | } else { | 361 | } else { |
| 351 | } | 362 | } |
| 352 | }, [boxType]); | 363 | }, [boxType]); |
| 364 | + | ||
| 353 | const handleFocus = (e, index) => { | 365 | const handleFocus = (e, index) => { |
| 354 | if (boxList && boxList.length) { | 366 | if (boxList && boxList.length) { |
| 355 | const updatedBoxList = [...boxList]; | 367 | const updatedBoxList = [...boxList]; |
| @@ -367,6 +379,7 @@ const BoxDesignCompontent = baseProps => { | @@ -367,6 +379,7 @@ const BoxDesignCompontent = baseProps => { | ||
| 367 | }; | 379 | }; |
| 368 | 380 | ||
| 369 | const handleChange = (e, index) => { | 381 | const handleChange = (e, index) => { |
| 382 | + console.log(e.target.value, index, "handleChange"); | ||
| 370 | const updatedBoxList = [...boxList]; | 383 | const updatedBoxList = [...boxList]; |
| 371 | updatedBoxList[index].value = e.target.value; | 384 | updatedBoxList[index].value = e.target.value; |
| 372 | setBoxList(updatedBoxList); | 385 | setBoxList(updatedBoxList); |
| @@ -409,7 +422,6 @@ const BoxDesignCompontent = baseProps => { | @@ -409,7 +422,6 @@ const BoxDesignCompontent = baseProps => { | ||
| 409 | const imageUrl = `${commonConfig.file_host}file/download?savePathStr=${fileName}&scale=0.1&sModelsId=100&token=${props.token}`; | 422 | const imageUrl = `${commonConfig.file_host}file/download?savePathStr=${fileName}&scale=0.1&sModelsId=100&token=${props.token}`; |
| 410 | return imageUrl; | 423 | return imageUrl; |
| 411 | }; | 424 | }; |
| 412 | - console.log(boxList, "boxList"); | ||
| 413 | 425 | ||
| 414 | // 下来框 | 426 | // 下来框 |
| 415 | const renderOptionWithImage = option => { | 427 | const renderOptionWithImage = option => { |
| @@ -817,10 +829,6 @@ const BoxDesignCompontent = baseProps => { | @@ -817,10 +829,6 @@ const BoxDesignCompontent = baseProps => { | ||
| 817 | return i || 0; | 829 | return i || 0; |
| 818 | }; | 830 | }; |
| 819 | 831 | ||
| 820 | - // 单独处理双层盒型 | ||
| 821 | - if (boxType === "8") { | ||
| 822 | - console.log(newBoxList, boxList, "topBoxList"); | ||
| 823 | - } | ||
| 824 | return ( | 832 | return ( |
| 825 | <AntdDraggableModal | 833 | <AntdDraggableModal |
| 826 | width="1000px" | 834 | width="1000px" |
src/components/Common/BoxDesignCompontent/svg.js
| @@ -50,8 +50,8 @@ import { | @@ -50,8 +50,8 @@ import { | ||
| 50 | createBoxComponentNewFul5, | 50 | createBoxComponentNewFul5, |
| 51 | createBoxComponentNewFul6, | 51 | createBoxComponentNewFul6, |
| 52 | } from "../BoxDesign/createAirplaneBox"; | 52 | } from "../BoxDesign/createAirplaneBox"; |
| 53 | -import { log } from "lodash-decorators/utils"; | ||
| 54 | const SvgBox = props => { | 53 | const SvgBox = props => { |
| 54 | + console.log("🚀 ~ SvgBox:", props); | ||
| 55 | const svgContainerRef = useRef(null); | 55 | const svgContainerRef = useRef(null); |
| 56 | const svgRef = useRef(null); | 56 | const svgRef = useRef(null); |
| 57 | const [boxKey, setBoxKey] = useState(new Date().getTime()); | 57 | const [boxKey, setBoxKey] = useState(new Date().getTime()); |
| @@ -90,6 +90,17 @@ const SvgBox = props => { | @@ -90,6 +90,17 @@ const SvgBox = props => { | ||
| 90 | setWidth(boxLength); | 90 | setWidth(boxLength); |
| 91 | setHeight(boxWidth); | 91 | setHeight(boxWidth); |
| 92 | setDeep(boxHeight); | 92 | setDeep(boxHeight); |
| 93 | + let headLength = 0; | ||
| 94 | + let headWidth = 0; | ||
| 95 | + let orderLength = 0; | ||
| 96 | + let orderWidth = 0; | ||
| 97 | + if (svgTypes === "8") { | ||
| 98 | + headLength = Number(boxList.find(x => x.sName === "首盒长")?.value) || 0; | ||
| 99 | + headWidth = Number(boxList.find(x => x.sName === "首盒宽")?.value) || 0; | ||
| 100 | + orderLength = Number(boxList.find(x => x.sName === "次盒长")?.value) || 0; | ||
| 101 | + orderWidth = Number(boxList.find(x => x.sName === "次盒宽")?.value) || 0; | ||
| 102 | + } | ||
| 103 | + console.log(headLength, headWidth, orderLength, orderWidth, props.showNew, "orderWidth"); | ||
| 93 | 104 | ||
| 94 | // 计算视口宽度和高度 | 105 | // 计算视口宽度和高度 |
| 95 | const zbtb = boxList.find(x => x.sName === "左贴边位"); | 106 | const zbtb = boxList.find(x => x.sName === "左贴边位"); |
| @@ -194,9 +205,8 @@ const SvgBox = props => { | @@ -194,9 +205,8 @@ const SvgBox = props => { | ||
| 194 | } else if (Number(svgType) === 6) { | 205 | } else if (Number(svgType) === 6) { |
| 195 | viewBoxWidth = boxWidth + 2; | 206 | viewBoxWidth = boxWidth + 2; |
| 196 | viewBoxHeight = boxLength + 2; | 207 | viewBoxHeight = boxLength + 2; |
| 197 | - | ||
| 198 | } else if (Number(svgType) === 7) { | 208 | } else if (Number(svgType) === 7) { |
| 199 | - boxHeight = boxWidth | 209 | + boxHeight = boxWidth; |
| 200 | const zxcw = boxList.find(x => x.sName === "左(下)插位组件"); | 210 | const zxcw = boxList.find(x => x.sName === "左(下)插位组件"); |
| 201 | const zscw = boxList.find(x => x.sName === "左(上)插位组件"); | 211 | const zscw = boxList.find(x => x.sName === "左(上)插位组件"); |
| 202 | const yscw = boxList.find(x => x.sName === "右(上)插位组件"); | 212 | const yscw = boxList.find(x => x.sName === "右(上)插位组件"); |
| @@ -250,10 +260,13 @@ const SvgBox = props => { | @@ -250,10 +260,13 @@ const SvgBox = props => { | ||
| 250 | bottomValue = boxHeight * 3; | 260 | bottomValue = boxHeight * 3; |
| 251 | } | 261 | } |
| 252 | viewBoxWidth = Number(boxLength) + leftValue + rightValue; | 262 | viewBoxWidth = Number(boxLength) + leftValue + rightValue; |
| 253 | - console.log("🚀 ~ initSVG ~ leftValue:", leftValue,rightValue) | ||
| 254 | viewBoxHeight = Number(boxWidth) + topValue + bottomValue; | 263 | viewBoxHeight = Number(boxWidth) + topValue + bottomValue; |
| 255 | // viewBoxWidth = boxWidth + leftValue + rightValue; | 264 | // viewBoxWidth = boxWidth + leftValue + rightValue; |
| 256 | // viewBoxHeight = boxLength + dZSCW + dYXCW; | 265 | // viewBoxHeight = boxLength + dZSCW + dYXCW; |
| 266 | + } else if (Number(svgType) === 8) { | ||
| 267 | + | ||
| 268 | + viewBoxWidth = Number(headLength); | ||
| 269 | + viewBoxHeight = Number(headWidth) + Number(orderWidth); | ||
| 257 | } | 270 | } |
| 258 | // 计算缩放比例 | 271 | // 计算缩放比例 |
| 259 | let scale = 1; | 272 | let scale = 1; |
| @@ -299,8 +312,8 @@ const SvgBox = props => { | @@ -299,8 +312,8 @@ const SvgBox = props => { | ||
| 299 | } else { | 312 | } else { |
| 300 | xSvg = zbtb?.value; | 313 | xSvg = zbtb?.value; |
| 301 | } | 314 | } |
| 302 | - console.log(xSvg,viewBoxWidth / 2,viewBoxWidth,'viewBoxWidth / 2'); | ||
| 303 | - | 315 | + console.log(xSvg, viewBoxWidth / 2, viewBoxWidth, "viewBoxWidth / 2"); |
| 316 | + | ||
| 304 | svg.setAttribute( | 317 | svg.setAttribute( |
| 305 | "viewBox", | 318 | "viewBox", |
| 306 | `${-(dSvgBoxWidth ? xSvg : viewBoxWidth / 2)} ${dSvgBoxWidth ? -0 : -ySvg} ${dSvgBoxWidth ? dSvgBoxWidth : 500} ${ | 319 | `${-(dSvgBoxWidth ? xSvg : viewBoxWidth / 2)} ${dSvgBoxWidth ? -0 : -ySvg} ${dSvgBoxWidth ? dSvgBoxWidth : 500} ${ |
| @@ -1185,6 +1198,28 @@ const SvgBox = props => { | @@ -1185,6 +1198,28 @@ const SvgBox = props => { | ||
| 1185 | g.appendChild(x); | 1198 | g.appendChild(x); |
| 1186 | }); | 1199 | }); |
| 1187 | svg.appendChild(g); | 1200 | svg.appendChild(g); |
| 1201 | + } else if (Number(svgType) === 8) { | ||
| 1202 | + const scaleHeadLength = headLength * scale | ||
| 1203 | + const scaleHeadWidth = headWidth * scale | ||
| 1204 | + const scaleOrderLength = orderLength * scale | ||
| 1205 | + const scaleOrderWidth = orderWidth * scale | ||
| 1206 | + // 获取他的偏移距离 | ||
| 1207 | + const leftOffect = boxList.find(x=>x.sName === "左偏移")?.value || 0 | ||
| 1208 | + const rightOffect = boxList.find(x=>x.sName === "右偏移")?.value || 0 | ||
| 1209 | + console.log("🚀 ~ initSVG ~ rightOffect:", leftOffect,rightOffect) | ||
| 1210 | + const rectangles = [{ x: 0, y: 0, width: scaleHeadLength, height: scaleHeadWidth }]; | ||
| 1211 | + rectangles.forEach(rect => { | ||
| 1212 | + g.appendChild(createPathElement(rect.x, rect.y, rect.width, rect.height)); | ||
| 1213 | + }); | ||
| 1214 | + const rectanglesLeft = [{ x: scaleHeadLength / 2 - scaleOrderLength - Number(leftOffect), y: scaleHeadWidth, width: scaleOrderLength, height: scaleOrderWidth }]; | ||
| 1215 | + rectanglesLeft.forEach(rect => { | ||
| 1216 | + g.appendChild(createPathElement(rect.x, rect.y, rect.width, rect.height)); | ||
| 1217 | + }); | ||
| 1218 | + const rectanglesRight = [{ x: scaleHeadLength / 2 + Number(rightOffect), y: scaleHeadWidth, width: scaleOrderLength, height: scaleOrderWidth }]; | ||
| 1219 | + rectanglesRight.forEach(rect => { | ||
| 1220 | + g.appendChild(createPathElement(rect.x, rect.y, rect.width, rect.height)); | ||
| 1221 | + }); | ||
| 1222 | + svg.appendChild(g); | ||
| 1188 | } | 1223 | } |
| 1189 | }; | 1224 | }; |
| 1190 | // 计算头部偏移 | 1225 | // 计算头部偏移 |