diff --git a/Frontend/_alert.html b/Frontend/_alert.html index a3cae03..45414fa 100644 --- a/Frontend/_alert.html +++ b/Frontend/_alert.html @@ -92,7 +92,7 @@
-
@@ -143,9 +143,14 @@
-
+
-
+
+
+
+
+ +
backup @@ -158,11 +163,6 @@
- -
- -
@@ -181,10 +181,11 @@ pageAct.selSysSub = null; pageAct.alr_startdate = null; pageAct.alr_enddate = null; + pageAct.imageFile = []; first = true; $(function () { - $(loadEle).Loading("close"); + initDropzone(); setReturn(false); setConfirm(false); event(); @@ -287,10 +288,15 @@ + alr_tableData.alarmClass.toString().split('_')[1] + "_" + alr_tableData.buildingFloorName_zh.toString().split('-')[1] + "_" + alr_tableData.sourceName_zh.toString().split('-')[0] + "_" + alr_tableData.sourceName_zh.toString().split('-')[1]; - $('#inpFixDoCode').val($(`option[value*=${deviceNumber}]`).val() !== undefined ? $(`option[value*=${deviceNumber}]`).val() : ""); selUser(); selDevice(); selOpeFir(); + + $('#inpFixDoCode option[data-sub=' + alr_tableData.alarmClass.toString().split('_')[1] + '][data-main=' + alr_tableData.alarmClass.toString().split('_')[0] + ']').attr('hidden', false); + $('#inpFixDoCode option[data-sub!=' + alr_tableData.alarmClass.toString().split('_')[1] + '][data-main!=' + alr_tableData.alarmClass.toString().split('_')[0] + ']').attr('hidden', true); + + let alr_fixDoCode = $($('#inpFixDoCode option[data-sub=' + alr_tableData.alarmClass.toString().split('_')[1] + '][data-main=' + alr_tableData.alarmClass.toString().split('_')[0] + ']')[0]).val(); + $('#inpFixDoCode').val(alr_fixDoCode); }); } @@ -486,7 +492,7 @@ "title": "異常類別", "data": "alarmClass", "render": function (data) { - return data.split('_')[1]; + return data.split('_')[0] + "-" + data.split('_')[1]; } }, { @@ -550,7 +556,7 @@ strHtml = ``; $("#inpFixDoCode").html(); $.each(res.data, (index, roleObj) => { - strHtml += ``; + strHtml += ``; if (index == 0) { pageAct.sysMain = roleObj.device_system_tag; @@ -598,4 +604,49 @@ } }, null, "POST").send(); } + + //上傳檔案 dropzone + function initDropzone() { + uploader = $("#alr_dropZone").dropzone({ + url: baseApiUrl + '/api/Upload', + previewsContainer: false, + addRemoveLinks: false, + dictRemoveFile: `delete`, + dictInvalidFileType: `上傳格式錯誤`, + dictCancelUploadConfirmation: `確定要取消上傳此檔案嗎?`, + dictCancelUpload: `cancel`, + maxFilesize: 3, + filesizeBase: 1024, + maxFiles: 50, + acceptedFiles: ".pdf, .docx, .doc, .xls, .xlsm, .xlsx, .ppt, .pptx, .gif, .png, .jpg, .jpeg", + headers: { "Authorization": 'Bearer ' + localStorage.getItem("JWT-Authorization") }, + accept: function (file, done) { + let fileHelper = new YourTeam.Utility.File(); + tmpGuidArr = []; + + if (/\.(jpe?g|png|gif)$/i.test(file.name)) { + fileHelper.readAndPreviewImages(file, 'alr_forImage', 70, 70, '', ''); + + pageAct.imageFile.map(function (v, i) { tmpGuidArr.push(v.file.guid) }); + if (jQuery.inArray(file.guid, tmpGuidArr) == -1) { //not in array + let fd = new FormData(); + let f = file; + fd.append('file', f); + pageAct.imageFile.push({ "ori_file_name": f.name, "save_file_name": f.guid, "file": fd.get("file") }); + } + } + else if (/\.(xls?x|doc?x|ptt?x|pdf|zip|rar|7zip|txt|odt|xml|rtf|ods|odp|pps?x)$/i.test(file.name)) { + fileHelper.readAndPreviewFiles(file, 'alr_forFile', 70, 70, "
", "
"); + + pageAct.imageFile.map(function (v, i) { tmpGuidArr.push(v.file.guid) }); + if (jQuery.inArray(file.guid, tmpGuidArr) == -1) { //not in array + let fd = new FormData(); + let f = file; + fd.append('file', f); + pageAct.imageFile.push({ "ori_file_name": f.name, "save_file_name": f.guid, "file": fd.get("file") }); + } + } + } + }); + } \ No newline at end of file diff --git a/Frontend/_operation.html b/Frontend/_operation.html index a05db5f..7b6e747 100644 --- a/Frontend/_operation.html +++ b/Frontend/_operation.html @@ -7,7 +7,7 @@
- +
@@ -246,9 +246,14 @@
-
+
-
+
+
+
+
+ +
backup @@ -261,11 +266,6 @@
- -
- -
@@ -301,10 +301,13 @@ \ No newline at end of file diff --git a/Frontend/js/yourteam/yourteam.utility.class.js b/Frontend/js/yourteam/yourteam.utility.class.js index afdcccb..5a8d547 100644 --- a/Frontend/js/yourteam/yourteam.utility.class.js +++ b/Frontend/js/yourteam/yourteam.utility.class.js @@ -491,9 +491,56 @@ class File { let myMath = new YourTeam.Utility.Math(); let myFile = new YourTeam.Utility.File(); let strExtName = "", strOrgName = ""; - - for (let i = 0; i < files.length; i++) { - let file = files[i]; + + if (files.length > 0) { + for (let i = 0; i < files.length; i++) { + let file = files[i]; + if (limitMaxSize != null) { + if (file.size / 1024 < limitMinSize || file.size / 1024 > limitMaxSize) { + limitFun ? limitFun() : ""; + return false + } + } + htmlImg = ""; + let guid = myMath.guid().replace(' ', ''); + file.guid = guid; + if (/\.(jpe?g|png|gif)$/i.test(file.name)) { + let reader = new FileReader(); + reader.addEventListener("load", function () { + let image = new Image(); + let src = this.result; + image.src = this.result; + image.onload = function () { + strExtName = myFile.getFileExtension(file.name); + strOrgName = (strExtName === null || strExtName === "") ? file.name : file.name.replace('.' + strExtName, ''); + htmlImg = frontHtml + '' + + backHtml; + + container.insertAdjacentHTML("afterBegin", htmlImg); + //$("[name=" + removeClickTagName + "]").on("click", function (e) { + // e.preventDefault(); + // $(this).closest(removeTag).remove(); + //}); + if (i === files.length - 1 && funDoSomeThing) { + funDoSomeThing(); + } + } + }); + reader.readAsDataURL(file); + } else { + if (showAlert) { + showAlert("danger", "只支援圖片格式"); + } + else { + alert("只支援圖片格式"); + } + } + } + + } + else { + let file = files; if (limitMaxSize != null) { if (file.size / 1024 < limitMinSize || file.size / 1024 > limitMaxSize) { limitFun ? limitFun() : ""; @@ -504,7 +551,6 @@ class File { let guid = myMath.guid().replace(' ', ''); file.guid = guid; if (/\.(jpe?g|png|gif)$/i.test(file.name)) { - let reader = new FileReader(); reader.addEventListener("load", function () { let image = new Image(); @@ -522,21 +568,21 @@ class File { // e.preventDefault(); // $(this).closest(removeTag).remove(); //}); - if (i === files.length - 1 && funDoSomeThing) { + if (funDoSomeThing) { funDoSomeThing(); } } }); reader.readAsDataURL(file); } else { - if (showAlert) { + if (showAlert) { showAlert("danger", "只支援圖片格式"); } else { alert("只支援圖片格式"); } } - } + } } readAndPreviewFiles(files, containerId, imgWidth = null, imgHeight = null, frontHtml = null, backHtml = null, funDoSomeThing = null) { @@ -547,37 +593,82 @@ class File { let myMath = new YourTeam.Utility.Math(); let myFile = new YourTeam.Utility.File(); let strExtName = "", strOrgName = "", strSaveName = ""; - - for (let i = 0; i < files.length; i++) { - let file = files[i]; + + if (files.length) { + for (let i = 0; i < files.length; i++) { + let file = files[i]; + htmlImg = ""; + + let guid = myMath.guid().replace(' ', ''); + file.guid = guid; + //alert(/\.(xls?x|doc?x|ptt?x|pdf|zip|rar|7zip|txt|odt|xml|rtf|ods|odp|pps?x)$/i.test(file.name)); + if (/\.(xls?x|doc?x|ptt?x|pdf|zip|rar|7zip|txt|odt|xml|rtf|ods|odp|pps?x)$/i.test(file.name)) { + + if (file.size == 0) { //檔案大小為0時不會產生base64,需防呆 + showAlert("danger", "無法上傳大小為0的檔案"); + return false; + } + + //先新增a標籤 在套上src 可能解決多檔案上傳時無法讀取到最後上傳檔案的問題 + strSaveName = guid; + strExtName = myFile.getFileExtension(file.name); + strOrgName = (strExtName === null || strExtName === "") ? file.name : file.name.replace('.' + strExtName, ''); + + htmlImg = frontHtml + '' + strOrgName + '.' + strExtName + '' + + backHtml; + container.insertAdjacentHTML("afterBegin", htmlImg); + let reader = new FileReader(); + + reader.addEventListener("load", function (event) { + $($(container).find("a")[i]).attr("href", this.result); + if (i === files.length - 1 && funDoSomeThing) { + funDoSomeThing(); + } + }); + reader.readAsDataURL(file); + + } else { + if (showAlert) { + showAlert("danger", "只支援文件格式"); + } else { + alert("只支援文件格式"); + } + } + } + } + else { + let file = files; htmlImg = ""; + + let guid = myMath.guid().replace(' ', ''); + file.guid = guid; //alert(/\.(xls?x|doc?x|ptt?x|pdf|zip|rar|7zip|txt|odt|xml|rtf|ods|odp|pps?x)$/i.test(file.name)); if (/\.(xls?x|doc?x|ptt?x|pdf|zip|rar|7zip|txt|odt|xml|rtf|ods|odp|pps?x)$/i.test(file.name)) { - if (file.size == 0) { //檔案大小為0時不會產生base64,需防呆 showAlert("danger", "無法上傳大小為0的檔案"); return false; } //先新增a標籤 在套上src 可能解決多檔案上傳時無法讀取到最後上傳檔案的問題 - strSaveName = myMath.guid().replace(' ', ''); + strSaveName = guid; strExtName = myFile.getFileExtension(file.name); strOrgName = (strExtName === null || strExtName === "") ? file.name : file.name.replace('.' + strExtName, ''); - - htmlImg = frontHtml + '' + strOrgName + '.' + strExtName + '' + + htmlImg = frontHtml + '' + strOrgName + '.' + strExtName + '' + backHtml; container.insertAdjacentHTML("afterBegin", htmlImg); let reader = new FileReader(); reader.addEventListener("load", function (event) { - $($(container).find("a")[i]).attr("href", this.result); - if (i === files.length - 1 && funDoSomeThing) { + $($(container).find("a")).attr("href", this.result); + if (funDoSomeThing) { funDoSomeThing(); } }); reader.readAsDataURL(file); - + } else { if (showAlert) { showAlert("danger", "只支援文件格式"); @@ -585,7 +676,7 @@ class File { alert("只支援文件格式"); } } - } + } } async getBase64Image(path, callback) { //生成canvas diff --git a/FrontendWebApi/ApiControllers/FileController.cs b/FrontendWebApi/ApiControllers/FileController.cs index 53be5c5..7e257b5 100644 --- a/FrontendWebApi/ApiControllers/FileController.cs +++ b/FrontendWebApi/ApiControllers/FileController.cs @@ -1,8 +1,10 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using NPOI.SS.Formula.Functions; using Repository.BackendRepository.Interface; using Repository.FrontendRepository.Interface; using System; +using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; using System.IO; using System.Net; @@ -76,5 +78,17 @@ namespace FrontendWebApi.ApiControllers var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", path); return File(System.IO.File.ReadAllBytes(Path.Combine(filePath, fileName)), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName); } + + [HttpPost] + [Route("api/Upload")] + public ActionResult DroZonUplFile() + { + var a = HttpContext.Request.Form.Files; + return Json(new + { + code = "0000", + data = HttpContext.Request.Form.Files + }); + } } }