|
|
@@ -5,6 +5,8 @@ var canvas = document.getElementById('theCanvas');
|
|
|
var ctx = canvas.getContext('2d');
|
|
|
// 隐藏的iframe,用于加载pdf,以便打印(pdf.js自带的打印有问题)
|
|
|
var hiddenFrame = document.getElementById("hiddenFrame");
|
|
|
+// 用于显示正在加载的提示
|
|
|
+var spinner;
|
|
|
|
|
|
// 能打印的最大页数(页数超过,需要先下载pdf,再打印)
|
|
|
var PRINT_MAX_PAGE_SIZE = 500;
|
|
|
@@ -105,6 +107,7 @@ $("#downloadPdf").click(
|
|
|
if (!pdfDoc) {
|
|
|
return;
|
|
|
}
|
|
|
+ showLoading();
|
|
|
// 检查文件状态,直到其可用
|
|
|
var valid = getGeneratedPdfOrXlsInformation('pdf').valid;
|
|
|
// 文件除了要保证有效(存在并且未过有效期),还要确保hiddenFrameLoaded不能为真,因为存在下列情况
|
|
|
@@ -124,6 +127,7 @@ $("#downloadPdf").click(
|
|
|
// valid = getGeneratedPdfOrXlsInformation("pdf").valid;
|
|
|
// sleep(1000);
|
|
|
} else {
|
|
|
+ hideLoading();
|
|
|
window.location = downloadUrl("pdf");
|
|
|
}
|
|
|
});
|
|
|
@@ -132,6 +136,7 @@ $("#downloadPdf").click(
|
|
|
* 下载文件
|
|
|
*/
|
|
|
function downloadPdf() {
|
|
|
+ hideLoading();
|
|
|
console.log(new Date().format()
|
|
|
+ " ---- received and unsubscribe wholePdfGenerated");
|
|
|
$.unsubscribe("wholePdfGenerated", downloadPdf);
|
|
|
@@ -160,11 +165,13 @@ $("#downloadExcelWithOnlyData").click(function() {
|
|
|
if (!pdfDoc) {
|
|
|
return;
|
|
|
}
|
|
|
+ showLoading();
|
|
|
var size;
|
|
|
while (!size) {
|
|
|
size = getGeneratedPdfOrXlsInformation("xls").size;
|
|
|
sleep(1000);
|
|
|
}
|
|
|
+ hideLoading();
|
|
|
window.location = downloadUrl("xls_with_only_data");
|
|
|
});
|
|
|
|
|
|
@@ -218,12 +225,13 @@ function printPdf() {
|
|
|
// sleep(1000);
|
|
|
// }
|
|
|
if (!hiddenFrameLoaded) {
|
|
|
- alert("正在生成文档");
|
|
|
+ showLoading();
|
|
|
console.log(new Date().format() + " ---- 需打印的文档未生成,正在生成文档");
|
|
|
// 订阅信号 "hiddenFrameLoaded",等待整个pdf加载完成
|
|
|
console.log(new Date().format() + " ---- subscribed hiddenFrameLoaded");
|
|
|
$.subscribe("hiddenFrameLoaded", print);
|
|
|
} else {
|
|
|
+ hideLoading();
|
|
|
alert("正在加载文档");
|
|
|
console.log(new Date().format() + " ---- start print...");
|
|
|
hiddenFrame.contentWindow.print();
|
|
|
@@ -280,6 +288,7 @@ function loadData() {
|
|
|
if (!printType || printType == "PREVIEW") {
|
|
|
loadPdfDataUrl = loadPdfDataUrl + "&pageIndex=" + 1;
|
|
|
}
|
|
|
+
|
|
|
$.ajax({
|
|
|
type : "get",
|
|
|
async : false,
|
|
|
@@ -377,6 +386,7 @@ function loadWholePdf() {
|
|
|
* Get page info from document, resize canvas accordingly, and render page
|
|
|
*/
|
|
|
function renderPage() {
|
|
|
+ hideLoading();
|
|
|
if (!pdfDoc) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -438,6 +448,7 @@ function prevPage() {
|
|
|
if (!pdfDoc || pageIndex <= 1) {
|
|
|
return;
|
|
|
}
|
|
|
+ showLoading();
|
|
|
// 获取前一页的pdf
|
|
|
pagedPdfPath = pagedPdfPath.replace(pageIndex + ".pdf", (--pageIndex)
|
|
|
+ ".pdf");
|
|
|
@@ -451,6 +462,7 @@ function nextPage() {
|
|
|
if (!pdfDoc || pageIndex >= pageSize) {
|
|
|
return;
|
|
|
}
|
|
|
+ showLoading();
|
|
|
pagedPdfPath = pagedPdfPath.replace(pageIndex + ".pdf", (++pageIndex)
|
|
|
+ ".pdf");
|
|
|
loadPagedPdf(pagedPdfPath);
|
|
|
@@ -491,12 +503,63 @@ function getGeneratedPdfOrXlsInformation(pdfOrXls) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 休眠一段时间
|
|
|
- *
|
|
|
- * @param millsecond
|
|
|
- * 休眠时长(毫秒)
|
|
|
+ * 显示正在载入的动画
|
|
|
+ */
|
|
|
+function showLoading() {
|
|
|
+ if (spinner) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var opts = {
|
|
|
+ lines : 9 // The number of lines to draw
|
|
|
+ ,
|
|
|
+ length : 17 // The length of each line
|
|
|
+ ,
|
|
|
+ width : 10 // The line thickness
|
|
|
+ ,
|
|
|
+ radius : 26 // The radius of the inner circle
|
|
|
+ ,
|
|
|
+ scale : 1 // Scales overall size of the spinner
|
|
|
+ ,
|
|
|
+ corners : 1 // Corner roundness (0..1)
|
|
|
+ ,
|
|
|
+ color : '#000' // #rgb or #rrggbb or array of colors
|
|
|
+ ,
|
|
|
+ opacity : 0.5 // Opacity of the lines
|
|
|
+ ,
|
|
|
+ rotate : 0 // The rotation offset
|
|
|
+ ,
|
|
|
+ direction : 1 // 1: clockwise, -1: counterclockwise
|
|
|
+ ,
|
|
|
+ speed : 1 // Rounds per second
|
|
|
+ ,
|
|
|
+ trail : 60 // Afterglow percentage
|
|
|
+ ,
|
|
|
+ fps : 20 // Frames per second when using setTimeout() as a fallback
|
|
|
+ // for CSS
|
|
|
+ ,
|
|
|
+ zIndex : 2e9 // The z-index (defaults to 2000000000)
|
|
|
+ ,
|
|
|
+ className : 'spinner' // The CSS class to assign to the spinner
|
|
|
+ ,
|
|
|
+ top : '50%' // Top position relative to parent
|
|
|
+ ,
|
|
|
+ left : '50%' // Left position relative to parent
|
|
|
+ ,
|
|
|
+ shadow : false // Whether to render a shadow
|
|
|
+ ,
|
|
|
+ hwaccel : false // Whether to use hardware acceleration
|
|
|
+ ,
|
|
|
+ position : 'absolute' // Element positioning
|
|
|
+ }
|
|
|
+ var target = document.getElementById('viewerContainer');
|
|
|
+ spinner = new Spinner(opts).spin(target);
|
|
|
+}
|
|
|
+/**
|
|
|
+ * 关闭正在载入的动画
|
|
|
*/
|
|
|
-function sleep(millsecond) {
|
|
|
- for (var d = Date.now(); Date.now() - d <= millsecond;)
|
|
|
- ;
|
|
|
+function hideLoading() {
|
|
|
+ if (spinner) {
|
|
|
+ spinner.stop();
|
|
|
+ spinner = null;
|
|
|
+ }
|
|
|
}
|