mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-07-01 16:22:49 +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();
|
||||
}).catch(function () {
|
||||
// 加载失败,回退到html2canvas
|
||||
capturePageViaHtml2Canvas($elem, $staging, opts, results, idx, total, deferred, captureNext);
|
||||
capturePageViaHtml2Canvas($elem, $staging, opts, results, deferred, function () { idx++; captureNext(); });
|
||||
});
|
||||
return;
|
||||
} 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();
|
||||
@@ -977,7 +977,7 @@ var PhoneImageEngine = (function () {
|
||||
/**
|
||||
* 用html2canvas截图单页
|
||||
*/
|
||||
function capturePageViaHtml2Canvas($elem, $staging, opts, results, idx, total, deferred, captureNext) {
|
||||
function capturePageViaHtml2Canvas($elem, $staging, opts, results, deferred, onDone) {
|
||||
html2canvas($elem[0], {
|
||||
scale: opts.scale,
|
||||
useCORS: true,
|
||||
@@ -991,11 +991,10 @@ var PhoneImageEngine = (function () {
|
||||
} else {
|
||||
results.push(canvas.toDataURL('image/jpeg', opts.quality));
|
||||
}
|
||||
idx++;
|
||||
captureNext();
|
||||
onDone();
|
||||
}).catch(function (err) {
|
||||
$staging.css({ visibility: 'hidden' });
|
||||
deferred.reject('截图失败(第' + (idx + 1) + '页): ' + err);
|
||||
deferred.reject('截图失败: ' + err);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user