From 38e6f2d9bb37c0dd9dbc7ee86ba95371cd062997 Mon Sep 17 00:00:00 2001 From: wangzemei Date: Sun, 29 Sep 2024 16:48:37 +0800 Subject: [PATCH] * [task#128767] modify the calculation logic for position. --- lib/zin/wg/think3c/js/v1.js | 61 ++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/lib/zin/wg/think3c/js/v1.js b/lib/zin/wg/think3c/js/v1.js index 6957d2ae13..17561ef33a 100644 --- a/lib/zin/wg/think3c/js/v1.js +++ b/lib/zin/wg/think3c/js/v1.js @@ -109,14 +109,15 @@ function afterFinish() * @access public * @return void */ -function calculateCardPosition(region) +function calculateCardPosition(region, index) { - const h = 300; // 卡片高度 - const minW = 256; // 最小宽度 - const maxW = 400; // 最大宽度 + const h = 200; // 卡片高度 + const minW = 200; // 最小宽度 + const maxW = 280; // 最大宽度 const d = 10; // 间距 - const rows = flattenData(region.rows); + const rows = Object.values(region.rows); const rowsCount = rows.length; + const positions = []; let r = 0; while (r < rowsCount) @@ -126,30 +127,30 @@ function calculateCardPosition(region) for(let i = r; i < r + h && i < rowsCount; i++) { - if(rows[i]?.right) totalWidth += rows[i].right - rows[i].left; - if(totalWidth >= minW) + const rowsData = rows[i]; + for(let j = 0; j < rowsData.length; j++) { - validStartRow = r; - break; + if(rowsData[j][0]) totalWidth += rowsData[j][1] - rowsData[j][0]; + if(totalWidth >= minW) + { + validStartRow = r; + break; + } } } - if(validStartRow !== -1) + if(validStartRow != -1) { - let left = rows[validStartRow]?.left || 0; - let right = rows[Math.min(validStartRow + h - 1, rowsCount - 1)]?.right || 0; - let rowN = Math.floor((right - left + d) / (minW + d)); - let w = (right - left + d) / rowN; + const {left, right} = getMaxLeftAndMinRight(rows, validStartRow, h); + let rowN = Math.floor((right - left + d) / (minW + d)); + let w = (right - left + d) / rowN; for(let i = 0; i < rowN; i++) { - let blockLeft = left + i * (w + d); - let blockTop = rows[validStartRow].top; - let blockWidth = Math.min(w, maxW); - let blockHeight = h; - - // TODO: 绘制卡片 - console.log(`Block ${i + 1}: Left: ${blockLeft}, Top: ${blockTop}, Width: ${blockWidth}, Height: ${blockHeight}`); + let blockLeft = left + i * (w + d); + let blockTop = rows[validStartRow][0][2]; + let blockWidth = Math.min(w, maxW); + positions.push({left: blockLeft, top: blockTop, width: blockWidth}); } r += h; } @@ -158,6 +159,24 @@ function calculateCardPosition(region) r++; } } + + const cards = $(`#runResult .card.in_area-${index}`); + if(cards.length <= positions.length) + { + cards.each((i, card) => { + $(card).css({ + left: `${positions[i].left}px`, + top: `${positions[i].top}px`, + width: `${positions[i].width}px`, + height: `${h}px`, + }); + }); + $('.card').removeClass('hidden'); + } + else + { + // TODO: 处理卡片数量超过位置数量的情况 + } } /**