Browse Source

预览页面修改

sunyj 9 years ago
parent
commit
9a37416a6d

+ 2 - 2
src/main/webapp/WEB-INF/views/preview.html

@@ -244,7 +244,7 @@ See https://github.com/adobe-type-tools/cmap-resources
 								tabindex="34">
 								<i class="fa fa-file-excel-o fa-lg"></i>
 							</button>
-							<a href="#" id="viewBookmark"
+							<a href="#" id="viewBookmark" hidden='true'
 								class="toolbarButton bookmark hiddenSmallView"
 								title="Current view (copy or open in new window)" tabindex="35"
 								data-l10n-id="bookmark"> <span data-l10n-id="bookmark_label">Current
@@ -525,7 +525,7 @@ See https://github.com/adobe-type-tools/cmap-resources
 <script src="static/lib/pdf.js/web/l10n.js"></script>
 <script src="static/lib/pdf.js/build/pdf.js"></script>
 <script src="static/lib/jquery/jquery.min.js"></script>
-<script src="static/js/preview.js"></script>
+<script src="static/js/preview/app.js"></script>
 <script src="static/lib/pdf.js/web/debugger.js"></script>
 <script src="static/lib/pdf.js/web/viewer.js"></script>
 <script src="static/js/endview.js"></script>

+ 0 - 156
src/main/webapp/resources/js/preview.js

@@ -1,156 +0,0 @@
-$("#download_pdf").click(function() {
-	downloadReport("pdf");
-});
-
-$("#download_excel").click(function() {
-	downloadReport("xls");
-});
-
-var downloadReport = function(exportFileType) {
-	var userName = getParameter("userName");
-	var reportName = getParameter("reportName");
-	var whereCondition = getParameter("whereCondition");
-	var otherParameters = getParameter("otherParameters");
-	exportFileType = exportFileType || "pdf";
-
-	var downloadUrl = "print/export?";
-	if (userName) {
-		downloadUrl += "userName=" + userName;
-	}
-	if (reportName) {
-		downloadUrl += "&reportName=" + reportName;
-	}
-	if (whereCondition) {
-		downloadUrl += "&whereCondition=" + whereCondition;
-	}
-	if (otherParameters) {
-		downloadUrl += "&otherParameters=" + otherParameters;
-	}
-	if (pageIndex) {
-		downloadUrl += "&pageIndex=" + pageIndex;
-	}
-	downloadUrl += "&exportFileType=" + exportFileType;
-
-	window.location = downloadUrl;
-}
-
-var PDFData, DEFAULT_URL;
-
-var pageIndex = 1, pageSize = 1;// 当前页码,页码总数
-
-// 获取链接参数
-var getParameter = function(key) {
-	var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
-	var r = window.location.search.substr(1).match(reg);
-	if (r != null)
-		return unescape(r[2]);
-	return null;
-};
-
-// 获取url
-var getUrl = function(page) {
-	var userName = getParameter("userName");
-	var reportName = getParameter("reportName");
-	var whereCondition = getParameter("whereCondition");
-	var otherParameters = getParameter("otherParameters");
-	pageIndex = page || getParameter("pageIndex") || 1;
-
-	var previewUrl = "print/loadPdfData?";
-	if (userName) {
-		previewUrl += "userName=" + userName;
-	}
-	if (reportName) {
-		previewUrl += "&reportName=" + reportName;
-	}
-	if (whereCondition) {
-		previewUrl += "&whereCondition=" + whereCondition;
-	}
-	if (otherParameters) {
-		previewUrl += "&otherParameters=" + otherParameters;
-	}
-	if (pageIndex) {
-		previewUrl += "&pageIndex=" + pageIndex;
-	}
-	return previewUrl;
-}
-
-// 获取数据
-function loadData(page, callback) {
-	$.ajax({
-		type : "get",
-		async : false,
-		url : page ? getUrl(page) : getUrl(),
-		success : function(data) {
-			pageSize = data.pageSize;
-			PDFData = base64_decode(data.data);
-			var rawLength = PDFData.length;
-			// 转换成pdf.js能直接解析的Uint8Array类型,见pdf.js-4068
-			var array = new Uint8Array(new ArrayBuffer(rawLength));
-			for (var i = 0; i < rawLength; i++) {
-				array[i] = PDFData.charCodeAt(i) & 0xff;
-			}
-			DEFAULT_URL = array;
-			callback && callback.call();
-		}
-	});
-};
-
-loadData();
-
-// base64 解码
-function base64_decode(str) {
-	var c1, c2, c3, c4;
-	var base64DecodeChars = new Array(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-			-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-			-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62,
-			-1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1,
-			-1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
-			15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1,
-			26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
-			43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
-	var i = 0, len = str.length, string = '';
-
-	while (i < len) {
-		do {
-			c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff]
-		} while (i < len && c1 == -1);
-
-		if (c1 == -1)
-			break;
-
-		do {
-			c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff]
-		} while (i < len && c2 == -1);
-
-		if (c2 == -1)
-			break;
-
-		string += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
-
-		do {
-			c3 = str.charCodeAt(i++) & 0xff;
-			if (c3 == 61)
-				return string;
-
-			c3 = base64DecodeChars[c3]
-		} while (i < len && c3 == -1);
-
-		if (c3 == -1)
-			break;
-
-		string += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
-
-		do {
-			c4 = str.charCodeAt(i++) & 0xff;
-			if (c4 == 61)
-				return string;
-			c4 = base64DecodeChars[c4]
-		} while (i < len && c4 == -1);
-
-		if (c4 == -1)
-			break;
-
-		string += String.fromCharCode(((c3 & 0x03) << 6) | c4)
-	}
-	return string;
-}

+ 93 - 59
src/main/webapp/resources/js/preview/app.js

@@ -1,67 +1,101 @@
-var PDFData,DEFAULT_URL;
-
-$(function() {
-	'use strict';
-	var pageIndex;// 当前页码
-
-	// 获取链接参数
-	var getParameter = function(key) {
-		var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
-		var r = window.location.search.substr(1).match(reg);
-		if (r != null)
-			return unescape(r[2]);
-		return null;
-	};
-	
-	// 获取url
-	var getUrl = function() {
-		var userName = getParameter("userName");
-		var reportName = getParameter("reportName");
-		var whereCondition = getParameter("whereCondition");
-		var otherParameters = getParameter("otherParameters");
-		pageIndex = getParameter("pageIndex");
-
-		var previewUrl = "print/loadPdfData?";
-		if (userName) {
-			previewUrl += "userName=" + userName;
-		}
-		if (reportName) {
-			previewUrl += "&reportName=" + reportName;
-		}
-		if (whereCondition) {
-			previewUrl += "&whereCondition=" + whereCondition;
-		}
-		if (otherParameters) {
-			previewUrl += "&otherParameters=" + otherParameters;
-		}
-		if (pageIndex) {
-			previewUrl += "&pageIndex=" + pageIndex;
-		}
-		return previewUrl;
+$("#download_pdf").click(function() {
+	downloadReport("pdf");
+});
+
+$("#download_excel").click(function() {
+	downloadReport("xls");
+});
+
+var downloadReport = function(exportFileType) {
+	var userName = getParameter("userName");
+	var reportName = getParameter("reportName");
+	var whereCondition = getParameter("whereCondition");
+	var otherParameters = getParameter("otherParameters");
+	exportFileType = exportFileType || "pdf";
+
+	var downloadUrl = "print/export?";
+	if (userName) {
+		downloadUrl += "userName=" + userName;
+	}
+	if (reportName) {
+		downloadUrl += "&reportName=" + reportName;
+	}
+	if (whereCondition) {
+		downloadUrl += "&whereCondition=" + whereCondition;
+	}
+	if (otherParameters) {
+		downloadUrl += "&otherParameters=" + otherParameters;
 	}
-	
-	var previewUrl = getUrl();
-	console.log("previewUrl: " + previewUrl);
-	
+	if (pageIndex) {
+		downloadUrl += "&pageIndex=" + pageIndex;
+	}
+	downloadUrl += "&exportFileType=" + exportFileType;
+
+	window.location = downloadUrl;
+}
+
+var PDFData, DEFAULT_URL;
+
+var pageIndex = 1, pageSize = 1;// 当前页码,页码总数
+
+// 获取链接参数
+var getParameter = function(key) {
+	var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
+	var r = window.location.search.substr(1).match(reg);
+	if (r != null)
+		return unescape(r[2]);
+	return null;
+};
+
+// 获取url
+var getUrl = function(page) {
+	var userName = getParameter("userName");
+	var reportName = getParameter("reportName");
+	var whereCondition = getParameter("whereCondition");
+	var otherParameters = getParameter("otherParameters");
+	pageIndex = page || getParameter("pageIndex") || 1;
+
+	var previewUrl = "print/loadPdfData?";
+	if (userName) {
+		previewUrl += "userName=" + userName;
+	}
+	if (reportName) {
+		previewUrl += "&reportName=" + reportName;
+	}
+	if (whereCondition) {
+		previewUrl += "&whereCondition=" + whereCondition;
+	}
+	if (otherParameters) {
+		previewUrl += "&otherParameters=" + otherParameters;
+	}
+	if (pageIndex) {
+		previewUrl += "&pageIndex=" + pageIndex;
+	}
+	return previewUrl;
+}
+
+// 获取数据
+function loadData(page, callback) {
 	$.ajax({
-		type: "get",
-		async: false,
-		url: previewUrl,
-		success: function(data) {
+		type : "get",
+		async : false,
+		url : page ? getUrl(page) : getUrl(),
+		success : function(data) {
+			pageSize = data.pageSize;
 			PDFData = base64_decode(data.data);
-			var pageSize = data.pageSize;
-			console.log(pageIndex + '/' + pageSize);
-			var rawLength = PDFData.length;  
-			//转换成pdf.js能直接解析的Uint8Array类型,见pdf.js-4068  
-			var array = new Uint8Array(new ArrayBuffer(rawLength));    
-			for(var i = 0; i < rawLength; i++) {  
-			  array[i] = PDFData.charCodeAt(i) & 0xff;  
-			}  
-			DEFAULT_URL = array; 
+			var rawLength = PDFData.length;
+			// 转换成pdf.js能直接解析的Uint8Array类型,见pdf.js-4068
+			var array = new Uint8Array(new ArrayBuffer(rawLength));
+			for (var i = 0; i < rawLength; i++) {
+				array[i] = PDFData.charCodeAt(i) & 0xff;
+			}
+			DEFAULT_URL = array;
+			callback && callback.call();
 		}
 	});
-	
-});
+};
+
+loadData();
 
 // base64 解码
 function base64_decode(str) {