mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-07-09 23:42:48 +08:00
fix: 修复phone-image截图循环idx参数传递bug导致无限循环
capturePageViaHtml2Canvas函数将idx作为参数传入,.then回调中idx++只修改参数副本而非闭包变量, 导致runCaptureLoop中idx永远为0,截图循环无限重复处理第一页。 改为传递onDone回调函数,在回调中正确修改闭包变量idx。
This commit is contained in:
@@ -955,7 +955,7 @@ var PhoneImageEngine = (function () {
|
|||||||
captureNext();
|
captureNext();
|
||||||
}).catch(function () {
|
}).catch(function () {
|
||||||
// 加载失败,回退到html2canvas
|
// 加载失败,回退到html2canvas
|
||||||
capturePageViaHtml2Canvas($elem, $staging, opts, results, idx, total, deferred, captureNext);
|
capturePageViaHtml2Canvas($elem, $staging, opts, results, deferred, function () { idx++; captureNext(); });
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@@ -968,7 +968,7 @@ var PhoneImageEngine = (function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
capturePageViaHtml2Canvas($elem, $staging, opts, results, idx, total, deferred, captureNext);
|
capturePageViaHtml2Canvas($elem, $staging, opts, results, deferred, function () { idx++; captureNext(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
captureNext();
|
captureNext();
|
||||||
@@ -977,7 +977,7 @@ var PhoneImageEngine = (function () {
|
|||||||
/**
|
/**
|
||||||
* 用html2canvas截图单页
|
* 用html2canvas截图单页
|
||||||
*/
|
*/
|
||||||
function capturePageViaHtml2Canvas($elem, $staging, opts, results, idx, total, deferred, captureNext) {
|
function capturePageViaHtml2Canvas($elem, $staging, opts, results, deferred, onDone) {
|
||||||
html2canvas($elem[0], {
|
html2canvas($elem[0], {
|
||||||
scale: opts.scale,
|
scale: opts.scale,
|
||||||
useCORS: true,
|
useCORS: true,
|
||||||
@@ -991,11 +991,10 @@ var PhoneImageEngine = (function () {
|
|||||||
} else {
|
} else {
|
||||||
results.push(canvas.toDataURL('image/jpeg', opts.quality));
|
results.push(canvas.toDataURL('image/jpeg', opts.quality));
|
||||||
}
|
}
|
||||||
idx++;
|
onDone();
|
||||||
captureNext();
|
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
$staging.css({ visibility: 'hidden' });
|
$staging.css({ visibility: 'hidden' });
|
||||||
deferred.reject('截图失败(第' + (idx + 1) + '页): ' + err);
|
deferred.reject('截图失败: ' + err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user