Forráskód Böngészése

对文件上传等操作结果增加提示

sunyj 9 éve
szülő
commit
4df8ab6c40

+ 42 - 0
src/main/webapp/resources/css/alert.css

@@ -0,0 +1,42 @@
+#prompt {
+	position: fixed;
+	left: 50%;
+	top: 30%;
+	z-index: 999999;
+	width: 200px;
+	height: auto;
+	margin-left: -100px;
+	padding: 20px;
+	overflow: hidden;
+	text-align: center;
+	color: #fff;
+	-webkit-transition: all .3s ease 0s;
+	-moz-transition: all .3s ease 0s;
+	-ms-transition: all .3s ease 0s;
+	transition: all .3s ease 0s;
+	-webkit-transform: scale(0);
+	-moz-transform: scale(0);
+	-ms-transform: scale(0);
+	transform: scale(0);
+	border-radius: 10px;
+}
+
+#prompt.show {
+	-webkit-transform: scale(1);
+	-moz-transform: scale(1);
+	-ms-transform: scale(1);
+	transform: scale(1);
+}
+
+#prompt span {
+	position: absolute;
+	top: 0;
+	right: 0;
+	bottom: 0;
+	left: 0;
+	z-index: -1;
+	background: #000;
+	opacity: .8;
+	filter: alpha(opacity = 50);
+	border-radius: 10px;
+}

+ 4 - 2
src/main/webapp/resources/js/files/app.js

@@ -38,11 +38,12 @@ $("#uploadButton").click(function() {
 		success : function(data) {
 			console.log(data);
 			spinner = hideLoading(spinner);
+			alert(spinnerContainer, "上传成功");
 			listFiles(currentPath.value);
 		},
 		error : function(xhr) {
 			console.log(xhr);
-			alert("上传失败");
+			alert(spinnerContainer, "上传失败");
 			spinner = hideLoading(spinner);
 		},
 		showLoading : function() {
@@ -218,10 +219,11 @@ function deleteFile(path, listItemDiv) {
 		success : function(data) {
 			listItemDiv.remove();
 			spinner = hideLoading(spinner);
+			alert(spinnerContainer,"删除成功");
 		},
 		error : function(XMLHttpRequest) {
 			if (XMLHttpRequest.status == 403) {
-				alert(JSON.parse(XMLHttpRequest.responseText).message);
+				alert(spinnerContainer,JSON.parse(XMLHttpRequest.responseText).message);
 			} else {
 				showErrorMessageByXMLHttpRequest(XMLHttpRequest);
 			}

+ 7 - 7
src/main/webapp/resources/js/preview/app.js

@@ -92,7 +92,7 @@ $("#pageIndex").keypress(function(event) {
 				return;
 			}
 			if (pageSize > PRINT_MAX_PAGE_SIZE) {
-				alert(ALERT_FILE_TOO_LARGE);
+				alert(spinnerContainer, ALERT_FILE_TOO_LARGE);
 				return;
 			}
 			pageIndex = value;
@@ -200,7 +200,7 @@ function getWindowWidth() {
 function printPdf() {
 	spinner = hideLoading(spinner);
 	if (pageSize > PRINT_MAX_PAGE_SIZE) {
-		alert(ALERT_FILE_TOO_LARGE);
+		alert(spinnerContainer, ALERT_FILE_TOO_LARGE);
 		return;
 	}
 	if (!pdfDoc) {
@@ -251,7 +251,7 @@ function loadPagedPdf(pagedPdfPath, ifPreloadWholePdf) {
 						if (ifPreloadWholePdf) {
 							if (printType == 'PRINT'
 									&& pageSize > PRINT_MAX_PAGE_SIZE) {
-								alert(ALERT_FILE_TOO_LARGE);
+								alert(spinnerContainer, ALERT_FILE_TOO_LARGE);
 								spinner = hideLoading(spinner);
 							} else {
 								console
@@ -345,7 +345,7 @@ function loadWholePdf() {
 function waitWholePdfGenerated() {
 	waitWholePdfGeneratedCount++;
 	if (waitWholePdfGeneratedCount >= MAX_WAIT_WHOLE_PDF_GENERATED) {
-		alert(ALERT_WAIT_WHOLE_PDF_GENERATED_TOO_LARGE);
+		alert(spinnerContainer, ALERT_WAIT_WHOLE_PDF_GENERATED_TOO_LARGE);
 		window.location.reload();
 		return;
 	}
@@ -478,7 +478,7 @@ function nextPage() {
 		return;
 	}
 	if (pageSize > PRINT_MAX_PAGE_SIZE) {
-		alert(ALERT_FILE_TOO_LARGE);
+		alert(spinnerContainer, ALERT_FILE_TOO_LARGE);
 		return;
 	}
 	if (timeout()) {
@@ -521,7 +521,7 @@ function checkBrowser() {
 	var userAgent = navigator.userAgent;
 	console.log(userAgent);
 	if (userAgent.indexOf("Chrome") == -1 || userAgent.indexOf("Edge") !== -1) {
-		alert("建议使用最新版Chrome浏览器进行打印");
+		alert(spinnerContainer, "建议使用最新版Chrome浏览器进行打印");
 	}
 }
 
@@ -533,7 +533,7 @@ function checkBrowser() {
 function timeout() {
 	var now = new Date();
 	if (now - startTime >= MAX_TIME) {
-		alert(ALERT_TIMEOUT);
+		alert(spinnerContainer, ALERT_TIMEOUT);
 		window.location.reload();
 		return true;
 	}

+ 52 - 2
src/main/webapp/resources/js/util/utils.js

@@ -1,4 +1,5 @@
 document.write("<script src='static/lib/spin/spin.min.js'></script>");
+document.write("<link rel='stylesheet' href='static/css/alert.css'>");
 
 /**
  * 获取链接参数
@@ -83,7 +84,7 @@ function upload(option) {
 			var file = input.files[i];
 			console.log("selected... " + file.name);
 			if (option.maxSize && file.size > option.maxSize * 1024 * 1024) {
-				alert("单个文件大小不能超过" + option.maxSize + "MB");
+				alert(null, "单个文件大小不能超过" + option.maxSize + "MB");
 				return;
 			}
 		}
@@ -126,6 +127,7 @@ function upload(option) {
 		}
 		xhr.send(formData);
 	}
+	document.body.removeChild(input);
 }
 
 /**
@@ -181,7 +183,7 @@ function showLoading(spinner, container) {
 		,
 		hwaccel : false // Whether to use hardware acceleration
 		,
-		position : 'absolute' // Element positioning
+		position : 'fixed' // Element positioning
 	}
 	return new Spinner(opts).spin(container);
 }
@@ -198,4 +200,52 @@ function hideLoading(spinner) {
 		spinner.stop();
 	}
 	return null;
+}
+
+/**
+ * 通知提示
+ * 
+ * @param container
+ *            通知所在的容器
+ * @param text
+ *            通知的内容
+ * @param time
+ *            通知存在的时间
+ */
+function alert(container, text, time) {
+	var div = document.getElementById('prompt');
+	if (div) {
+		div.remove();
+	}
+	time = time || 3000;
+	container = container || document.body;
+	div = document.createElement('div'), // 创建div对象
+	span = document.createElement('span'); // 创建span对象
+	div.id = 'prompt'; // div设置ID
+	div.innerHTML = text; // 写入内容
+	div.appendChild(span);
+	container.appendChild(div);
+
+	var timerShow = null, timerHide = null, timerRemove = null;
+
+	// 显示提示窗口
+	timerShow = setTimeout(function() {
+		div.className = 'show'; // 添加show样式,使用CSS3属性显示弹窗
+		clearTimeout(timerShow); // 清除定时器
+
+		// 2秒钟后隐藏弹窗
+		timerHide = setTimeout(function() {
+			div.className = ''; // 清除show样式,使用CSS3属性隐藏弹窗
+			clearTimeout(timerHide); // 清除定时器
+
+			// 隐藏后删除对象
+			timerRemove = setTimeout(function() {
+				div.remove(); // 删除对象
+				clearTimeout(timerRemove); // 清除定时器
+			}, 400);
+
+		}, time);
+
+	}, 100);
+
 }