Browse Source

support configing which export buttons are showed in preview.html

sunyj 8 years ago
parent
commit
f9db05b3de

+ 17 - 0
src/main/java/com/uas/report/SystemProperties.java

@@ -1,8 +1,11 @@
 package com.uas.report;
 
+import com.uas.report.model.ExportType;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Configuration;
 
+import java.util.List;
+
 /**
  * 系统参数
  * 
@@ -42,6 +45,12 @@ public class SystemProperties {
 	@Value("${use-xlsx}")
 	private boolean useXlsx;
 
+	/**
+	 * 预览页面所显示的导出按钮
+	 */
+	@Value("${page.preview.show-export-buttons}")
+	private List<ExportType> pagePreviewShowExportButtons;
+
 	public int getTaskPeriod() {
 		return taskPeriod;
 	}
@@ -81,4 +90,12 @@ public class SystemProperties {
 	public void setUseXlsx(boolean useXlsx) {
 		this.useXlsx = useXlsx;
 	}
+
+	public List<ExportType> getPagePreviewShowExportButtons() {
+		return pagePreviewShowExportButtons;
+	}
+
+	public void setPagePreviewShowExportButtons(List<ExportType> pagePreviewShowExportButtons) {
+		this.pagePreviewShowExportButtons = pagePreviewShowExportButtons;
+	}
 }

+ 5 - 4
src/main/java/com/uas/report/controller/PrintController.java

@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.IOException;
 import java.sql.SQLException;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -300,15 +301,15 @@ public class PrintController {
 	}
 
 	/**
-	 * 是否使用 xlsx
+	 * 预览页面所显示的导出按钮
 	 *
 	 * @param request
 	 * @param response
 	 * @return
 	 */
-	@RequestMapping(value = "/isUseXlsx")
+	@RequestMapping(value = "/exportButtons")
 	@ResponseBody
-	public boolean isUseXlsx(HttpServletRequest request, HttpServletResponse response) {
-		return systemProperties.isUseXlsx();
+	public List<ExportType> getPagePreviewShowExportButtons(HttpServletRequest request, HttpServletResponse response) {
+		return systemProperties.getPagePreviewShowExportButtons();
 	}
 }

+ 5 - 0
src/main/resources/application.yml

@@ -35,6 +35,11 @@ max-record-size:
 
 use-xlsx: false
 
+page:
+ preview:
+  # support PDF, XLS, XLS_DATA, XLSX, XLSX_DATA, DOC, TXT in com.uas.report.model.ExportType
+  show-export-buttons: PDF, XLS, XLS_DATA
+
 jasperserver:
  rest:
   api:

+ 13 - 5
src/main/webapp/WEB-INF/views/console.html

@@ -55,8 +55,6 @@
 					<li><a target="_blank">file/delete?filePath=C:/test&isAbsolutePath=true</a></li>
 				</ol>
 			</ol>
-		</div>
-		<div id="rightContainer">
 			<h2>3. 标准模板</h2>
 			<ol>
 				<strong><li class="title1">标准模板</li></strong>
@@ -69,14 +67,24 @@
 					<li><a target="_blank">file/autoDeploy?sourceUserName=UAS&destinationUserNames=1,2</a></li>
 				</ol>
 			</ol>
-
+		</div>
+		<div id="rightContainer">
 			<h2>4. 接口</h2>
 			<ol>
 				<strong><li class="title2">打印接口</li></strong>
 				<ol>
-					<li><a target="_blank">print/pdfPath?userName=UAS&reportName=Purchase&whereCondition=where rownum<30&pageIndex=2</a></li>
-					<li><a target="_blank">print/export?userName=UAS&reportName=Purchase&whereCondition=where rownum<16&exportFileType=xls_data</a></li>
+					<li><a target="_blank">print/pdfPath?userName=UAS&reportName=Purchase&whereCondition=where rownum<30</a></li>
+					<li><a target="_blank">print/export?userName=UAS&reportName=Purchase&whereCondition=where rownum<16&exportFileType=xls_data&title=采购单</a></li>
+					<li><a target="_blank">print/pdfData?userName=UAS&reportName=Purchase&whereCondition=where rownum<30</a></li>
 					<li><a target="_blank">print/count?userName=UAS&reportName=Purchase&whereCondition=where rownum<16</a></li>
+					<li><a target="_blank">print/exportButtons</a></li>
+				</ol>
+				<strong><li class="title2">pdf 接口</li></strong>
+				<ol>
+					<li><a target="_blank">pdf/path?u=UAS&r=Purchase&w=where rownum<30&pf=phone</a></li>
+					<li><a target="_blank">pdf/data?u=UAS&r=Purchase&w=where rownum<30&pf=phone</a></li>
+					<li><a target="_blank">pdf/download?u=UAS&r=Purchase&w=where rownum<30&pf=phone</a></li>
+					<li><a target="_blank">pdf/preview?p=salelist_jasper/1923314312.pdf</a></li>
 				</ol>
 				<strong><li class="title2">资源接口</li></strong>
 				<ol>

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

@@ -48,22 +48,29 @@
 			<button id="print" class="toolbarButton" title="打印">
 				<i class="fa fa-print fa-lg" aria-hidden="true"></i>
 			</button>
-			<button id="downloadPdf" class="toolbarButton" title="下载PDF">
+			<button id="export_PDF" hidden="true" class="toolbarButton" title="导出 PDF">
 				<i class="fa fa-file-pdf-o fa-lg" aria-hidden="true"></i>
 			</button>
-			<button id="downloadWord" hidden="true" class="toolbarButton"
-				title="下载Word">
+			<button id="export_DOC" hidden="true" hidden="true" class="toolbarButton"
+				title="导出 Word">
 				<i class="fa fa-file-word-o fa-lg" aria-hidden="true"></i>
 			</button>
-			<button id="downloadExcel" class="toolbarButton" title="下载Excel">
+			<button id="export_XLS" hidden="true" class="toolbarButton" title="导出 Excel">
 				<i class="fa fa-file-excel-o fa-lg" aria-hidden="true"></i>
 			</button>
-			<button id="downloadExcelData" class="toolbarButton"
-				title="下载Excel(仅数据)">
+			<button id="export_XLSX" hidden="true" class="toolbarButton" title="导出 Excel">
 				<i class="fa fa-file-excel-o fa-lg" aria-hidden="true"></i>
 			</button>
-			<button id="downloadText" hidden="true" class="toolbarButton"
-				title="下载Text">
+			<button id="export_XLS_DATA" hidden="true" class="toolbarButton"
+					title="导出 Excel(仅数据)">
+				<i class="fa fa-file-excel-o fa-lg" aria-hidden="true"></i>
+			</button>
+			<button id="export_XLSX_DATA" hidden="true" class="toolbarButton"
+				title="导出 Excel(仅数据)">
+				<i class="fa fa-file-excel-o fa-lg" aria-hidden="true"></i>
+			</button>
+			<button id="export_TXT" hidden="true" class="toolbarButton"
+				title="导出 Text">
 				<i class="fa fa-file-text-o fa-lg" aria-hidden="true"></i>
 			</button>
 		</div>

+ 31 - 88
src/main/webapp/resources/js/preview/app.js

@@ -29,6 +29,7 @@ var rendering = false;
 var nextRenderingPage;
 
 document.title = getParameter("reportName");
+showExportButtons();
 getWindowWidth();
 loadData();
 
@@ -102,46 +103,6 @@ $("#print").click(function() {
 	printPdf();
 });
 
-// 下载pdf
-$("#downloadPdf").click(function() {
-	if (!pdfDoc) {
-		return;
-	}
-	window.open(downloadUrl("pdf"));
-});
-
-// 下载word
-$("#downloadWord").click(function() {
-	if (!pdfDoc) {
-		return;
-	}
-	window.open(downloadUrl("doc"));
-});
-
-// 下载excel
-$("#downloadExcel").click(function () {
-	if (!pdfDoc) {
-		return;
-	}
-	downloadExcel(false);
-});
-
-// 下载纯数据excel
-$("#downloadExcelData").click(function () {
-	if (!pdfDoc) {
-		return;
-	}
-	downloadExcel(true);
-});
-
-//下载text
-$("#downloadText").click(function() {
-	if (!pdfDoc) {
-		return;
-	}
-	window.open(downloadUrl("txt"));
-});
-
 // 键盘左右键进行翻页
 $("body").keydown(function(event) {
 	// 如果在选中input输入框或select下拉列表时按左右键,不进行翻页
@@ -156,6 +117,36 @@ $("body").keydown(function(event) {
 	}
 });
 
+/**
+ * 显示导出按钮
+ */
+function showExportButtons() {
+	$.ajax({
+		type: "get",
+		async: false,
+		url: "print/exportButtons",
+		success: function (exportButtons) {
+			if(exportButtons.length){
+				for(var i = 0; i < exportButtons.length; i++){
+					var buttonPrefix = "export_";
+					var button = $("#" + buttonPrefix + exportButtons[i]);
+					button.removeAttr("hidden");
+					button.click(function() {
+						if (!pdfDoc) {
+							return;
+						}
+						window.open("print/export" + window.location.search + "&exportFileType=" + this.id.substr(buttonPrefix.length) + "&flush=true");
+					});
+
+				}
+			}
+		},
+		error: function (XMLHttpRequest) {
+			showError(XMLHttpRequest);
+		}
+	});
+}
+
 /**
  * 获取窗口宽度
  */
@@ -317,54 +308,6 @@ function printPdf() {
 			1000);
 }
 
-/**
- * 下载报表
- *
- * @param exportFileType
- *            导出文件的格式
- * @returns {String} 下载链接
- */
-function downloadUrl(exportFileType) {
-	var downloadUrl = "print/export" + window.location.search;
-	exportFileType = exportFileType || "pdf";
-	// 导出文件的格式
-	downloadUrl += "&exportFileType=" + exportFileType + "&flush=true";
-	return downloadUrl;
-}
-
-/**
- * 下载 excel
- * @param onlyData 是否仅下载数据
- */
-function downloadExcel(onlyData) {
-    $.ajax({
-        type: "get",
-        async: true,
-        url: "print/isUseXlsx",
-        success: function (isUseXlsx) {
-            var excelType;
-            // 根据结果决定使用 xls 还是 xlsx
-            if (isUseXlsx) {
-                if (onlyData) {
-                    excelType = "xlsx_data";
-                } else {
-                    excelType = "xlsx";
-                }
-            } else {
-                if (onlyData) {
-                    excelType = "xls_data";
-                } else {
-                    excelType = "xls";
-                }
-            }
-            window.open(downloadUrl(excelType));
-        },
-        error: function (XMLHttpRequest) {
-            showError(XMLHttpRequest);
-        }
-    });
-}
-
 /**
  * 检查浏览器并提示
  */