[後端] 修改 下載檔案問題

[前端] 修改前台修改需求問題
This commit is contained in:
dev02 2023-05-24 12:58:27 +08:00
parent 54c2e9946e
commit f094af892a
8 changed files with 118 additions and 127 deletions

View File

@ -218,6 +218,7 @@
pageAct.alrSelSysSub = [];
pageAct.selAllSysSub = false;
first = true;
let dataAlarm = [];
$(function () {
initDropzone();
@ -247,10 +248,9 @@
// console.log(this);
pageAct.selAllSysSub = true;
$.each($('input[type=checkbox][data-type=sub]:checked'), function (i, v) {
$(v).click();
});
//$.each($('input[type=checkbox][data-type=sub]:checked'), function (i, v) {
// $(v).click();
//});
if (pageAct.SysType == "all") {
if (!$(this).is(':checked')) {
@ -595,7 +595,6 @@
}
function selAllSysVal(elem) {
$(loadEle).Loading("start");
pageAct.selAllSysSub = true;
if ($(elem).html() == '全選類別') {
$('#alr_mainList input').map(function (i, v) {
@ -630,6 +629,8 @@
}
function getData(type = null) {
dataAlarm = [];
$(loadEle).Loading("start");
let enddate = new Date(new Date().setDate(new Date(pageAct.alr_enddate).getDate() + 1)).getTime();
if (pageAct.SysType == "all") {
@ -637,15 +638,28 @@
}
else {
let elem = $('input[type=checkbox][data-type=sub]:checked');
if (elem[0]?.id === "other") {
console.log(elem[0]?.id)
getOtherAlarmByBaja(new Date(pageAct.alr_startdate).getTime(), enddate, pageAct.return, pageAct.confirm, callBackFromAllDeviceAlert);
return
if (elem && elem.length > 0) {
elem.each(function (i, v) {
if (v?.id === "other") {
console.log(v?.id)
getOtherAlarmByBaja(new Date(pageAct.alr_startdate).getTime(), enddate, pageAct.return, pageAct.confirm, stackData);
}
else {
pageAct.selSysMain = $(v).parent().data('main');
pageAct.selSysSub = $(v).prop('id');
getAlarmByBaja(new Date(pageAct.alr_startdate).getTime(), enddate, pageAct.return, pageAct.confirm, pageAct.selSysMain + "_" + pageAct.selSysSub + "_AlarmClass", stackData);
}
});
}
pageAct.selSysMain = $(elem).parent().data('main');
pageAct.selSysSub = $(elem).prop('id');
getAlarmByBaja(new Date(pageAct.alr_startdate).getTime(), enddate, pageAct.return, pageAct.confirm, pageAct.selSysMain + "_" + pageAct.selSysSub + "_AlarmClass", callBackFromOneDeviceAlert);
}
$(loadEle).Loading("close");
}
function stackData(res) {
res.data.forEach(v => {
dataAlarm.push(v);
});
callBackFromOneDeviceAlert(dataAlarm);
}
function callBackFromAllDeviceAlert(res) {
@ -657,20 +671,18 @@
if (res.data.length > 0)
t.fnAddData(res.data);
}
$(loadEle).Loading("close");
}
function callBackFromOneDeviceAlert(res) {
//res = JSON.parse(res);
refTable(res.data);
refTable(res);
if (historyTable != null) {
let t = $('#alertTable').dataTable();
t.fnClearTable();
if (res.data.length > 0)
t.fnAddData(res.data);
if (res.length > 0)
t.fnAddData(res);
}
$(loadEle).Loading("close");
}
function refTable(data) {

View File

@ -337,7 +337,7 @@
})
function getGraCatList(callback) {
let url = baseApiUrl + "/GraphManage/VarList";
let url = baseApiUrl + "/GraphManage/GraphManageTreeList";
ytAjax = new YourTeam.Ajax(url, null, function (res) {
if (!res || res.code != "0000" || !res.data) {

View File

@ -264,9 +264,9 @@
function getData(start = null, end = null) {
var sdt = new Date();
var edt = new Date(new Date().setDate(sdt.getDate() + 1));
$(loadEle).Loading("start");
start = start ?? sdt.toLocaleDateString();
end = end ?? edt.toLocaleDateString();
$(loadEle).Loading("start");
callBackFromHistory()
getHistoryDataByBaja(pageAct.deviceNumber + "_" + pageAct.deviceItem,
new Date(start).getTime(),
@ -394,48 +394,49 @@
v.type = pageAct.devicePoiName.split(" ")[0];
});
let tag = "#historyTable";
let tag = "#historyTable";
let column_defs = [
{ "targets": [0], "width": "20%", "sortable": true },
{ "targets": [1], "width": "20%", "sortable": true },
{ "targets": [2], "width": "20%", "sortable": true }
];
let column_defs = [
{ "targets": [0], "width": "20%", "sortable": true },
{ "targets": [1], "width": "20%", "sortable": true },
{ "targets": [2], "width": "20%", "sortable": true }
];
let columns = [
{
"title": "類別",
"data": "type"
},
{
"title": "設備名稱",
"data": "deviceName",
},
{
"title": "數值",
"data": "value",
"render": function (data) {
if (isNaN(data.toString())) {
return data
}
return data.roundDecimal(2);
}
},
{
"title": "紀錄時間",
"data": "timestamp",
"render": function (data) {
// console.log(data)
return displayDate(data, "datetime");
}
}
];
let columns = [
{
"title": "類別",
"data": "type"
},
{
"title": "設備名稱",
"data": "deviceName",
},
{
"title": "數值",
"data": "value",
"render": function (data) {
if (isNaN(data.toString())) {
return data
}
return data.roundDecimal(2);
}
},
{
"title": "紀錄時間",
"data": "timestamp",
"render": function (data) {
// console.log(data)
return displayDate(data, "datetime");
}
}
];
historyTable = new YourTeam.JqDataTables.getTableByStatic(tag, data, columns, column_defs, null, null, null, null, "tpi");
historyTable = new YourTeam.JqDataTables.getTableByStatic(tag, data, columns, column_defs, null, null, null, null, "tpi");
}
}
function exportExcel() {
$(loadEle).Loading("start");
let url = baseApiUrl + "/History/OpeExportExcel";
objSendData.Data = $('#historyTable').dataTable().fnGetData();
@ -446,8 +447,10 @@
});
ytAjax = new YourTeam.Ajax(url, objSendData, function (rel) {
if (rel.code == "0000")
if (rel.code == "0000") {
location.href = baseApiUrl + "/api/df?path=" + rel.data.split('/')[0] + "&fileName=" + rel.data.split('/')[1] + "&token=" + cookies.get("JWT-Authorization");
}
}, null, "POST").send();
$(loadEle).Loading("close");
}
</script>

View File

@ -8,22 +8,13 @@
<div class="btn-group">
<button type="button" onclick="setType(2)" class="btn btn-secondary waves-effect waves-themed">維修</button>
<button type="button" onclick="setType(1)" class="btn btn-secondary waves-effect waves-themed">保養記錄</button>
<button type="button" onclick="setType(null)"
class="btn btn-secondary waves-effect waves-themed">
廠商資料
</button>
<button type="button" onclick="setType(null)" class="btn btn-secondary waves-effect waves-themed">廠商資料</button>
</div>
</div>
<div id="setDate" class="col-auto">
<div class="btn-group">
<button onclick="setDate('tdy')" type="button"
class="btn btn-secondary waves-effect waves-themed">
今天
</button>
<button onclick="setDate('ytd')" type="button"
class="btn btn-secondary waves-effect waves-themed">
昨天
</button>
<button onclick="setDate('tdy')" type="button" class="btn btn-secondary waves-effect waves-themed">今天</button>
<button onclick="setDate('ytd')" type="button" class="btn btn-secondary waves-effect waves-themed">昨天</button>
</div>
</div>
<div class="col-auto">
@ -69,7 +60,7 @@
<a href="#" id="newForm" class="btn btn-success" data-toggle="modal" data-target="#opeFirmModal">新增</a>
<a href="#" onclick="exportExcel()" class="btn btn-info waves-effect waves-themed">
<span class="fal fa-file-excel mr-1"></span>
<span>匯出</span>
匯出
</a>
</div>
<table id="opeFirmTable" class="table table-bordered table-striped text-center m-0 w-100">
@ -85,8 +76,7 @@
</main>
<!-- Modal center 廠商資料 -->
<div class="modal fade" id="opeFirmModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static"
data-keyboard="false">
<div class="modal fade" id="opeFirmModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
@ -162,8 +152,7 @@
</div>
<!-- Modal center 維修-->
<div class="modal fade" id="opeRecModal_2" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static"
data-keyboard="false">
<div class="modal fade" id="opeRecModal_2" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
@ -233,14 +222,12 @@
<div class="form-control" id="inpStatus_2">
<div class="row container">
<div class="">
<input class="custom-radio-input" type="radio" name="inpSta_2" id="inpSta_2_0" value="0"
data-value="0" checked>
<input class="custom-radio-input" type="radio" name="inpSta_2" id="inpSta_2_0" value="0" data-value="0" checked>
<label class="form-label" for="inpSta_0">未完成</label>
</div>
<div class="px-4">
<input class="custom-radio-input" type="radio" name="inpSta_2" id="inpSta_2_1" value="1"
data-value="1">
<input class="custom-radio-input" type="radio" name="inpSta_2" id="inpSta_2_1" value="1" data-value="1">
<label class="form-label" for="inpSta_1">完成</label>
</div>
</div>
@ -264,8 +251,7 @@
<div class="col-md-12">
<div class="form-group">
<label class="form-label" for="inpDescription_2">結果描述</label>
<textarea class="form-control" type="text" id="inpDescription_2" name="inpDescription_2"
rows="7"></textarea>
<textarea class="form-control" type="text" id="inpDescription_2" name="inpDescription_2" rows="7"></textarea>
</div>
</div>
<div class="col-md-12">
@ -302,8 +288,7 @@
</div>
<!-- Modal center 保養 -->
<div class="modal fade" id="opeRecModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static"
data-keyboard="false">
<div class="modal fade" id="opeRecModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
@ -365,14 +350,12 @@
<div class="form-control" id="inpStatus">
<div class="row container">
<div class="">
<input class="custom-radio-input" type="radio" name="inpSta" id="inpSta_0" data-value="0"
value="0" checked>
<input class="custom-radio-input" type="radio" name="inpSta" id="inpSta_0" data-value="0" value="0" checked>
<label class="form-label" for="inpSta_0">未完成</label>
</div>
<div class="px-4">
<input class="custom-radio-input" type="radio" name="inpSta" id="inpSta_1" data-value="1"
value="1">
<input class="custom-radio-input" type="radio" name="inpSta" id="inpSta_1" data-value="1" value="1">
<label class="form-label" for="inpSta_1">完成</label>
</div>
</div>
@ -396,8 +379,7 @@
<div class="col-md-12">
<div class="form-group">
<label class="form-label" for="inpDescription">結果描述</label>
<textarea class="form-control" type="text" id="inpDescription" name="inpDescription"
rows="7"></textarea>
<textarea class="form-control" type="text" id="inpDescription" name="inpDescription" rows="7"></textarea>
</div>
</div>
<div class="col-md-12">
@ -434,8 +416,7 @@
</div>
<!-- Modal center 刪除 -->
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static"
data-keyboard="false">
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
@ -536,6 +517,7 @@
});
function loadOpeFirmTable() {
$(loadEle).Loading("start");
$('#opeFirmTable_wrapper').css('display', 'block');
$('#opeRecTable_wrapper').css('display', 'none');
$('#opeRecTable_2_wrapper').css('display', 'none');
@ -601,9 +583,11 @@
];
opeFirmTable = new YourTeam.JqDataTables.getTableByAjax(ajaxObj, tag, null, columns, column_defs);
$(loadEle).Loading("close");
}
function loadOpeRecTable() {
$(loadEle).Loading("start");
$('#opeFirmTable_wrapper').css('display', 'none');
$('#serial_number').parent().parent().css('display', 'block');
@ -860,6 +844,7 @@
}
opeRecTable = new YourTeam.JqDataTables.getTableByAjax(ajaxObj, tag, null, columns, column_defs);
$(loadEle).Loading("close");
}
function setType(wt) {
@ -998,8 +983,8 @@
loadOpeRecTable();
}
function exportExcel(e) {
console.log("export", e)
function exportExcel() {
$(loadEle).Loading("start");
let url = baseApiUrl + "/operation/OpeExportExcel";
objSendData.Data = {
@ -1007,11 +992,12 @@
startdate: pageAct.startdate == undefined ? null : pageAct.startdate,
enddate: pageAct.enddate == undefined ? null : pageAct.enddate,
};
console.log("data", objSendData.Data)
ytAjax = new YourTeam.Ajax(url, objSendData, function (rel) {
if (rel.code == "0000")
location.href = baseApiUrl + "/api/df?path=" + rel.data.split('/')[0] + "&fileName=" + rel.data.split('/')[1] + "&token=" + cookies.get("JWT-Authorization");
}, null, "POST").send();
$(loadEle).Loading("close");
}
function selSysMain() {
@ -1100,7 +1086,6 @@
}
function selAllSysVal(elem) {
$(loadEle).Loading("start");
if ($(elem).html() == '全選類別') {
$('#mainList input').map(function (i, v) {
if (!$(v).is(':checked')) {
@ -1127,7 +1112,6 @@
}
refTable();
$(loadEle).Loading("close");
}
function event() {
@ -1375,18 +1359,12 @@
if (!res || res.code != "0000" || !res.data) {
} else {
pageAct.sysMain = res.data.device_system_category_layer2;
pageAct.sysSub = res.data.device_system_category_layer3;
pageAct.number = res.data.fix_do_code;
callbackForErr(JSON.stringify({
count: [res.data].length,
data: [{ uuid: res.data.error_code }]
}));
selOpeFir();
errCodeList();
$(pageAct.work_type == "1" ? '#inpNumber' : '#inpNumber_2').val(res.data.formId);
$(pageAct.work_type == "1" ? '#inpWorTyp' : '#inpWorTyp_2').val(res.data.work_type);
$(pageAct.work_type == "1" ? '#inpErrCode' : '#inpErrCode_2').val(res.data.error_code);
$(pageAct.work_type == "1" ? '#inpFixDo' : '#inpFixDo_2').val(res.data.fix_do);
$(pageAct.work_type == "1" ? '#inpFixDoCode' : '#inpFixDoCode_2').val(res.data.fix_do_code);
$(pageAct.work_type == "1" ? '#inpFixFirm' : '#inpFixFirm_2').val(res.data.fix_firm);
@ -1395,9 +1373,6 @@
$(pageAct.work_type == "1" ? '#inpStaTime' : '#inpStaTime_2').val(displayDate(res.data.start_time, 'date').replaceAll('/', '-'));
$(pageAct.work_type == "1" ? '#inpNotice' : '#inpNotice_2').val(res.data.notice);
$(pageAct.work_type == "1" ? '#inpDescription' : '#inpDescription_2').val(res.data.description);
let elemSel = $(pageAct.work_type == "1" ? '#inpFixDoCode' : '#inpFixDoCode_2').find('option:selected');;
pageAct.number = elemSel.val();
selOpeFir();
ope_imgHtml = null;
$.each(res.data.lorf, function (i, v) {
@ -1493,18 +1468,17 @@
}
function callbackForErr(res) {
res = JSON.parse(res) || res;
console.log(res)
res = JSON.parse(res);
strHtml = ``;
$.each(res.data, function (i, v) {
msg = v.msgText != null ? ($.trim(v.msgText.toString()).length > 0 ? v.msgText.split(':')[0] : '') : '';
strHtml += `<option value=${v.uuid}>${v.uuid.split("-")[0]}</option>`;
strHtml += `<option value=${v.uuid}>${v.uuid}</option>`;
});
if (res.count > 0)
$(pageAct.work_type == '1' ? '#inpErrCode' : '#inpErrCode_2').html(strHtml);
else
$(pageAct.work_type == '1' ? '#inpErrCode' : '#inpErrCode_2').html("");
$(loadEle).Loading("close");
}

View File

@ -70,20 +70,6 @@ namespace FrontendWebApi.ApiControllers
return null;
}
[HttpGet]
[Route("api/df")]
public ActionResult DownloadFile(string path, string fileName, string token)
{
var jwt = new JwtSecurityTokenHandler().ReadJwtToken(token);
if (jwt == null)
return Unauthorized(HttpStatusCode.Unauthorized);
else if (fileName == null)
return NotFound("找不到文件");
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()

View File

@ -118,13 +118,16 @@ namespace FrontendWebApi.ApiControllers
sheet.SetColumnWidth(0, 4 * 160 * 12);
sheet.SetColumnWidth(1, 4 * 160 * 12);
sheet.SetColumnWidth(2, 4 * 160 * 12);
sheet.SetColumnWidth(3, 4 * 160 * 12);
ICell cell = row.CreateCell(0);
cell.SetCellValue("設備名稱");
cell.SetCellValue("類型");
cell.CellStyle = styleLine12;
cell = row.CreateCell(1);
cell.SetCellValue("數值");
cell.SetCellValue("設備名稱");
cell.CellStyle = styleLine12;
cell = row.CreateCell(2);
cell.SetCellValue("數值");
cell = row.CreateCell(3);
cell.SetCellValue("記錄時間");
cell.CellStyle = styleLine12;
#endregion
@ -135,7 +138,7 @@ namespace FrontendWebApi.ApiControllers
{
RowPosition += 1;
row = sheet.CreateRow(RowPosition);
for (var i = 0; i < 3; i++)
for (var i = 0; i < 4; i++)
{
cell = row.CreateCell(i);
if (i == 0)

View File

@ -160,5 +160,18 @@ namespace FrontendWebApi.ApiControllers
return apiResult;
}
[HttpGet]
[Route("api/df")]
public ActionResult DownloadFile(string path, string fileName, string token)
{
if (fileName == null)
return NotFound("找不到文件");
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);
}
}
}