Browse Source

显示正在加载的提示

sunyj 9 years ago
parent
commit
777ab9a9c4

+ 1 - 1
src/main/resources/dev/sys.properties

@@ -3,4 +3,4 @@ localBaseDir=C:/sunyj/reports/60
 localImagesDir=/Picture
 localJrxmlDir=/jrxml
 standardMaster=STANDARD_MASTER
-standardJrxmlsUrl=http://localhost:8090/report/file/standardJrxmls?onlyData=1
+standardJrxmlsUrl=http://print.ubtob.com/report/file/standardJrxmls?onlyData=1

+ 1 - 0
src/main/webapp/WEB-INF/views/preview2.html

@@ -74,6 +74,7 @@
 <script src="static/lib/pdf.js/build/pdf.js"></script>
 <script src="static/lib/jquery/jquery.min.js"></script>
 <script src="static/lib/jquery/ba-tiny-pubsub.min.js"></script>
+<script src="static/lib/spin/spin.min.js"></script>
 <script src="static/js/util/utils.js"></script>
 <script src="static/js/preview/utils.js"></script>
 <script src="static/js/preview2/app.js"></script>

+ 30 - 3
src/main/webapp/resources/js/preview/utils.js

@@ -1,4 +1,21 @@
-// 下载报表
+/**
+ * 休眠一段时间
+ * 
+ * @param millsecond
+ *            休眠时长(毫秒)
+ */
+function sleep(millsecond) {
+	for (var d = Date.now(); Date.now() - d <= millsecond;)
+		;
+}
+
+/**
+ * 下载报表
+ * 
+ * @param exportFileType
+ *            导出文件的格式
+ * @returns {String} 下载链接
+ */
 function downloadUrl(exportFileType) {
 	var downloadUrl = "print/export" + window.location.search;
 	exportFileType = exportFileType || "pdf";
@@ -7,7 +24,13 @@ function downloadUrl(exportFileType) {
 	return downloadUrl;
 }
 
-// 获取链接参数
+/**
+ * 获取链接参数
+ * 
+ * @param key
+ *            参数的键
+ * @returns 参数的值
+ */
 function getParameter(key) {
 	var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
 	var r = window.location.search.substr(1).match(reg);
@@ -16,7 +39,11 @@ function getParameter(key) {
 	return null;
 };
 
-// 获取所有参数
+/**
+ * 获取所有参数
+ * 
+ * @returns {String}
+ */
 function getParameters() {
 	var userName = getParameter("userName");
 	var reportName = getParameter("reportName");

+ 71 - 8
src/main/webapp/resources/js/preview2/app.js

@@ -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;
+	}
 }

File diff suppressed because it is too large
+ 1 - 0
src/main/webapp/resources/lib/spin/spin.min.js


Some files were not shown because too many files changed in this diff