* 完成所有截图后处理 - 修改为接受参数 * @param {Array} capturedScreenshots 捕获到的截图数组 * @param {number} finalWidth 最终页面宽度 * @param {number} finalHeight 最终页面高度
(capturedScreenshots, finalWidth, finalHeight)
| 911 | * @param {number} finalHeight 最终页面高度 |
| 912 | */ |
| 913 | function finishCapture(capturedScreenshots, finalWidth, finalHeight) { |
| 914 | if (window._fh_screenshot_canceled) { |
| 915 | return; // 如果在 finishCapture 前取消,则不继续 |
| 916 | } |
| 917 | updateProgressUI(0.95, '正在处理截图...'); |
| 918 | |
| 919 | if (!capturedScreenshots || capturedScreenshots.length === 0) { |
| 920 | updateProgressUI(1, '截图失败: 没有截取到任何内容'); |
| 921 | setTimeout(cleanup, 1000); |
| 922 | return; |
| 923 | } |
| 924 | |
| 925 | console.log(`处理截图,共 ${capturedScreenshots.length} 张,页面尺寸: ${finalWidth}x${finalHeight}`); |
| 926 | |
| 927 | // 基于精确的捕获滚动坐标 (x, y) 进行去重 |
| 928 | const screenshotMap = new Map(); |
| 929 | capturedScreenshots.forEach(ss => { |
| 930 | const key = `${ss.x},${ss.y}`; |
| 931 | if (!screenshotMap.has(key)) { |
| 932 | screenshotMap.set(key, ss); |
| 933 | } else { |
| 934 | console.log(`发现重复精确位置的截图: (${ss.x},${ss.y}),保留第一个`); |
| 935 | } |
| 936 | }); |
| 937 | |
| 938 | // 将 Map 转换回数组,并按 Y 坐标优先,然后 X 坐标排序 |
| 939 | const uniqueScreenshots = Array.from(screenshotMap.values()).sort((a, b) => { |
| 940 | if (a.y !== b.y) return a.y - b.y; |
| 941 | return a.x - b.x; |
| 942 | }); |
| 943 | |
| 944 | console.log(`去重后共 ${uniqueScreenshots.length} 张有效截图(原 ${capturedScreenshots.length} 张)`); |
| 945 | |
| 946 | // 准备发送到后台的数据格式 |
| 947 | let mappedScreenshots = uniqueScreenshots.map((ss, index) => ({ |
| 948 | dataUri: ss.dataUrl, // 确保属性名是 dataUri |
| 949 | x: ss.x, |
| 950 | y: ss.y, |
| 951 | width: ss.width, // 使用捕获时的视窗尺寸 |
| 952 | height: ss.height, |
| 953 | index: index, // 添加索引供后台使用 |
| 954 | // 添加兼容性字段(如果后台拼接逻辑需要) |
| 955 | row: ss.row, |
| 956 | col: ss.col, |
| 957 | left: ss.x, |
| 958 | top: ss.y, |
| 959 | right: ss.x + ss.width, |
| 960 | bottom: ss.y + ss.height |
| 961 | })); |
| 962 | |
| 963 | console.log('准备发送所有截图分片到后台:', { |
| 964 | screenshots: mappedScreenshots.length, |
| 965 | pageWidth: finalWidth, |
| 966 | pageHeight: finalHeight |
| 967 | }); |
| 968 | |
| 969 | const screenshotData = { |
| 970 | filename: buildFilenameFromUrl(), |
no test coverage detected