diff --git a/FrontendWebApi/ApiControllers/EmergencyDeviceController.cs b/FrontendWebApi/ApiControllers/EmergencyDeviceController.cs index 839648c..c294721 100644 --- a/FrontendWebApi/ApiControllers/EmergencyDeviceController.cs +++ b/FrontendWebApi/ApiControllers/EmergencyDeviceController.cs @@ -267,7 +267,7 @@ namespace FrontendWebApi.ApiControllers try { Emergency_Setting_tables = await backendRepository.GetAllAsync($@" - select v.system_key big_setting_name,* from emergency_setting es left join variable v on es.big_setting = v.id + select v.system_key big_setting_name,es.* from emergency_setting es left join variable v on es.big_setting = v.id where es.big_setting = {selectsetting} and es.deleted = 0 order by es.priority"); apiResult.Code = "0000"; apiResult.Data = Emergency_Setting_tables; @@ -296,7 +296,7 @@ namespace FrontendWebApi.ApiControllers try { var Emergency_Setting_tables = await backendRepository.GetOneAsync($@" - select v.system_key big_setting_name,* from emergency_setting es left join variable v on es.big_setting = v.id + select v.system_key big_setting_name,es.* from emergency_setting es left join variable v on es.big_setting = v.id where es.emergency_guid = '{post.emergency_guid}'"); if (post.make_item == 1) diff --git a/FrontendWebApi/ApiControllers/RescueDeviceController.cs b/FrontendWebApi/ApiControllers/RescueDeviceController.cs index ac58c9f..2e9b04c 100644 --- a/FrontendWebApi/ApiControllers/RescueDeviceController.cs +++ b/FrontendWebApi/ApiControllers/RescueDeviceController.cs @@ -88,7 +88,7 @@ namespace FrontendWebApi.ApiControllers try { - var sqlString = @$"select building_tag as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0 ORDER BY A.priority ASC, A.created_at DESC"; + var sqlString = @$"select building_tag as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0 ORDER BY a.priority ASC, a.created_at DESC"; KeyValue = await backendRepository.GetAllAsync(sqlString); apiResult.Code = "0000"; diff --git a/FrontendWebApi/Views/EmergencyContact/Index.cshtml b/FrontendWebApi/Views/EmergencyContact/Index.cshtml index ccef77e..c7e06aa 100644 --- a/FrontendWebApi/Views/EmergencyContact/Index.cshtml +++ b/FrontendWebApi/Views/EmergencyContact/Index.cshtml @@ -106,7 +106,7 @@ $(row).attr('guid', data.emergency_guid); }, "ajax": { - "url": "/EmergencyContact/EmergencyContactTable", + "url": "/api/EmergencyContact/EmergencyContactTable", "type": "POST", "data": function (d) { d.selectgroupidlist = selectgroupidlist @@ -116,7 +116,7 @@ toast_error(rel.msg); return; } - data = rel.data.data; + data = rel.data; if (data == null || data.length == 0) { this.data = []; diff --git a/FrontendWebApi/Views/EmergencyDeviceMenu/Index.cshtml b/FrontendWebApi/Views/EmergencyDeviceMenu/Index.cshtml index 677339f..ac07ab6 100644 --- a/FrontendWebApi/Views/EmergencyDeviceMenu/Index.cshtml +++ b/FrontendWebApi/Views/EmergencyDeviceMenu/Index.cshtml @@ -767,10 +767,10 @@ device_amount: layer3.device_amount } - var temp_building_index = backfill_building_device_amount.findIndex(x => x.building_tag == building.guid); + var temp_building_index = backfill_building_device_amount.findIndex(x => x.building_tag == building.tag); if (temp_building_index < 0) { var building_obj = { - building_tag: building.guid, + building_tag: building.tag, device_amount: new_layer3.device_amount } @@ -779,10 +779,10 @@ backfill_building_device_amount[temp_building_index].device_amount += new_layer3.device_amount; } - var temp_layer2_index = backfill_layer2_device_amount.findIndex(x => x.value == layer2.value && x.building_tag == building.guid) + var temp_layer2_index = backfill_layer2_device_amount.findIndex(x => x.value == layer2.value && x.building_tag == building.tag) if (temp_layer2_index < 0) { var layer2_obj = { - building_tag: building.guid, + building_tag: building.tag, value: layer2.value, device_amount: new_layer3.device_amount } @@ -792,10 +792,10 @@ backfill_layer2_device_amount[temp_layer2_index].device_amount += new_layer3.device_amount; } - var temp_layer3_index = backfill_layer3_device_amount.findIndex(x => x.layer3 == layer3.value && x.layer2 == layer2.value && x.building_tag == building.guid) + var temp_layer3_index = backfill_layer3_device_amount.findIndex(x => x.layer3 == layer3.value && x.layer2 == layer2.value && x.building_tag == building.tag) if (temp_layer3_index < 0) { var layer3_obj = { - building_tag: building.guid, + building_tag: building.tag, layer2: layer2.value, layer3: layer3.value, device_amount: new_layer3.device_amount @@ -900,7 +900,7 @@ all_device_group.forEach(function (disaster, disaster_index) { if (SelectedFilter.disasters.findIndex(x => x == disaster.value) > -1) { //表示已選擇該防災類型 disaster.groupBuildings.forEach(function (building, building_index) { - if (temp_all_building.findIndex(x => x.guid == building.guid) < 0) { //表示未加入,需加入 + if (temp_all_building.findIndex(x => x.tag == building.tag) < 0) { //表示未加入,需加入 temp_all_building.push(building); } }); @@ -912,16 +912,16 @@ var html = ""; temp_all_building.forEach(function (building, building_index) { - var building_device_amount = backfill_building_device_amount.filter(x => x.building_tag == building.guid)[0]; + var building_device_amount = backfill_building_device_amount.filter(x => x.building_tag == building.tag)[0]; - @*html += `
+ @*html += `
- +
`;*@ - html += `
+ html += `
- +
`; }); @@ -932,7 +932,7 @@ else { var html = ""; temp_all_building.forEach(function (building, building_index) { - html += ''; + html += ''; }); $('#building').append(html); @@ -966,7 +966,7 @@ all_device_group.forEach(function (disaster, disaster_index) { if (SelectedFilter.disasters.findIndex(x => x == disaster.value) > -1) { //抓取已選擇的防災類型的棟別內容 disaster.groupBuildings.forEach(function (building, building_index) { - if (building.guid == SelectedFilter.building_tag) { //抓取選擇棟別的底下樓層 + if (building.tag == SelectedFilter.building_tag) { //抓取選擇棟別的底下樓層 building.groupFloors.forEach(function (floor, floor_index) { if (temp_all_floor.findIndex(x => x.guid == floor.guid) < 0) { //表示未加入,需加入 temp_all_floor.push(floor); @@ -1037,7 +1037,7 @@ all_device_group.forEach(function (disaster, disaster_index) { if (SelectedFilter.disasters.findIndex(x => x == disaster.value) > -1) { //抓取選擇防災類型的底下棟別 disaster.groupBuildings.forEach(function (building, building_index) { - if (building.guid == SelectedFilter.building_tag) { //抓取選擇棟別的底下樓層 + if (building.tag == SelectedFilter.building_tag) { //抓取選擇棟別的底下樓層 building.groupFloors.forEach(function (floor, floor_index) { if (SelectedFilter.floor_guids.findIndex(x => x == floor.guid) > -1) { //抓取選擇樓層的底下大類 floor.groupLayer2s.forEach(function (layer2, layer2_index) { @@ -1128,7 +1128,7 @@ all_device_group.forEach(function (disaster, disaster_index) { if (SelectedFilter.disasters.findIndex(x => x == disaster.value) > -1) { //抓取選擇防災類型的底下棟別 disaster.groupBuildings.forEach(function (building, building_index) { - if (building.guid == SelectedFilter.building_tag) { //抓取選擇棟別的底下樓層 + if (building.tag == SelectedFilter.building_tag) { //抓取選擇棟別的底下樓層 building.groupFloors.forEach(function (floor, floor_index) { if (SelectedFilter.floor_guids.findIndex(x => x == floor.guid) > -1) { //抓取選擇樓層的底下大類 floor.groupLayer2s.forEach(function (layer2, layer2_index) { diff --git a/FrontendWebApi/Views/EmergencyRecord/Index.cshtml b/FrontendWebApi/Views/EmergencyRecord/Index.cshtml index c22edb2..da8cc75 100644 --- a/FrontendWebApi/Views/EmergencyRecord/Index.cshtml +++ b/FrontendWebApi/Views/EmergencyRecord/Index.cshtml @@ -192,7 +192,7 @@ $(row).attr('device', data.device_name); }, "ajax": { - "url": "/EmergencyRecord/EmergencyRecordTable", + "url": "/api/EmergencyRecord/EmergencyRecordTable", "type": "POST", "data": function (d) { d.selectaDisaster = SelectaDisaster, @@ -205,7 +205,7 @@ toast_error(rel.msg); return; } - data = rel.data.data; + data = rel.data; if (data == null || data.length == 0) { this.data = []; @@ -252,7 +252,7 @@ $(row).attr('guid', data.emergency_item_guid); }, "ajax": { - "url": "/EmergencyRecord/EmergencyItemTable", + "url": "/api/EmergencyRecord/EmergencyItemTable", "type": "POST", "data": function (d) { d.event_guid = SelectEvent @@ -262,7 +262,7 @@ toast_error(rel.msg); return; } - data = rel.data.data; + data = rel.data; if (data == null || data.length == 0) { this.data = []; @@ -320,7 +320,7 @@ //取得所有棟別 function GetBuild() { - var url = "/EmergencyRecord/BuildInfoList"; + var url = "/api/EmergencyRecord/BuildInfoList"; var send_data = {}; $.post(url, send_data, function (rel) { if (rel.code != "0000") { diff --git a/FrontendWebApi/Views/RescueDevice/AED.cshtml b/FrontendWebApi/Views/RescueDevice/AED.cshtml index 38b5643..7b5da75 100644 --- a/FrontendWebApi/Views/RescueDevice/AED.cshtml +++ b/FrontendWebApi/Views/RescueDevice/AED.cshtml @@ -253,7 +253,17 @@ kind: 1 }; var url = "/RescueDevice/ExportExcel"; - window.location = "/RescueDevice/ExportExcel?post=" + JSON.stringify(send_data); + $.ajax({ + method: "POST", + xhrFields: { responseType: "blob" }, + headers: { "Authorization": "Bearer " + localStorage.getItem('JWT-Authorization') }, + url: "/RescueDevice/ExportExcel", + data: { "post": JSON.stringify(send_data) }, + success: (res, text, xhr) => { + download(xhr, res); + } + }) + //window.location = "/RescueDevice/ExportExcel?post=" + JSON.stringify(send_data); return; } diff --git a/FrontendWebApi/Views/RescueDevice/FireExtinguisher.cshtml b/FrontendWebApi/Views/RescueDevice/FireExtinguisher.cshtml index 90220eb..0522ce3 100644 --- a/FrontendWebApi/Views/RescueDevice/FireExtinguisher.cshtml +++ b/FrontendWebApi/Views/RescueDevice/FireExtinguisher.cshtml @@ -253,8 +253,20 @@ kind: 0 }; var url = "/RescueDevice/ExportExcel"; - window.location = "/RescueDevice/ExportExcel?post=" + JSON.stringify(send_data); + $.ajax({ + method:"POST", + xhrFields:{responseType:"blob"}, + headers:{"Authorization":"Bearer " + localStorage.getItem('JWT-Authorization')}, + url: "/RescueDevice/ExportExcel", + data:{"post":JSON.stringify(send_data)}, + success:(res,text,xhr) => { + download(xhr,res); + } + }) return; } + + + } \ No newline at end of file diff --git a/FrontendWebApi/wwwroot/js/site.js b/FrontendWebApi/wwwroot/js/site.js index 5d6e6b5..180bcd2 100644 --- a/FrontendWebApi/wwwroot/js/site.js +++ b/FrontendWebApi/wwwroot/js/site.js @@ -54,7 +54,7 @@ $(function () { "Please check your input." ); - + }) //#region 個人資訊表單驗證 @@ -228,6 +228,36 @@ function SaveSpinner(status) { //1:Spinner 0:還原儲存 } } +/** + * 下載檔案 + */ +function download(res, blob, filename, fetchOption, callback = null) { + // 擷取回傳 header > content-disposition (後端定義檔案名稱) + let disposition = res.getResponseHeader("Content-Disposition"); + let sDowName = ""; + if (disposition) { + // 解析出名稱 + sDowName = disposition.split(/filename\*=(?:utf-8'')?(.*)/gi)[1]; + if (sDowName.toLowerCase().startsWith("utf-8''")) + sDowName = decodeURIComponent(sDowName.replace(/utf-8''/i, "")); + else sDowName = sDowName.replace(/['"]/g, ""); + sDowName = decodeURIComponent(sDowName); + } + // 隱形a標籤 + const a = document.createElement("a"); + let href = URL.createObjectURL(blob); + if (href) { + a.href = href; + a.download = filename || sDowName || ""; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + callback ? callback() : ""; + return true; + } else { + return false; + } +} $(document).ready(function () { - + });