From a074dcd89a12175b4eb3f788ae33b66c6dc55491 Mon Sep 17 00:00:00 2001 From: dev02 Date: Thu, 24 Nov 2022 10:43:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=99=82=E9=96=93=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/_historyData.html | 156 +++++++++++++++++++++++++++++-------- 1 file changed, 124 insertions(+), 32 deletions(-) diff --git a/Frontend/_historyData.html b/Frontend/_historyData.html index 5aa86ac..779c37c 100644 --- a/Frontend/_historyData.html +++ b/Frontend/_historyData.html @@ -18,24 +18,31 @@
- - - + + +
- - + +
- + + +
+
+
- 查詢  + 查詢 + 匯出 @@ -86,6 +93,7 @@ }); function initList() { + pageAct.mainStatus = false; let sendData = { building_tag: pageAct.buiTag } @@ -95,15 +103,16 @@ let strHtml = ``; let i1 = null, i2 = null, first = true; - $.each(res.data.history_Main_Systems, function (index, val) { - strHtml += `
  • - - ${val.full_name} - -
      `; + if (pageAct.mainStatus) { + strHtml += `
    • + + ${val.full_name} + +
        `; - i1 = (val.history_Sub_systems != null && i1 == null) ? index : null; + i1 = (val.history_Sub_systems != null && i1 == null) ? index : null; + } $.each(val.history_Sub_systems, function (index2, val2) { i2 = (val2.device != null && i2 == null) ? index2 : null; @@ -114,7 +123,7 @@ ${val2.full_name} ${val2.sub_system_tag} -
          `; +
            `; $.each(val2.device, function (index3, val3) { strHtml += `
          • @@ -125,16 +134,29 @@
          • `; - if (index == i1 && index2 == i2 && first) { - first = false; - pageAct.deviceNumber = val3.device_number; - pageAct.deviceName = val3.full_name; - devPointsList(); + if (pageAct.mainStatus) { + if (index == i1 && index2 == i2 && first) { + first = false; + pageAct.deviceNumber = val3.device_number; + pageAct.deviceName = val3.full_name; + devPointsList(); + } } + else { + if (index2 == i2 && first) { + first = false; + pageAct.deviceNumber = val3.device_number; + pageAct.deviceName = val3.full_name; + devPointsList(); + } + } }); strHtml += `
          `; }); - strHtml += `
        `; + + if (pageAct.mainStatus) { + strHtml += `
    • `; + } }); $('#js_nested_list').html(strHtml); @@ -169,10 +191,10 @@ var sdt = new Date(); var edt = new Date(new Date().setDate(sdt.getDate() + 1)); start = start ?? sdt.toLocaleDateString(); - end = end ?? edt.toLocaleDateString(); + end = end ?? edt.toLocaleDateString(); getHistoryDataByBaja(pageAct.deviceNumber + "_" + pageAct.deviceItem, - new Date(start).getTime(), - new Date(end).getTime(), + new Date(start).getTime(), + new Date(end).getTime(), pageAct.deviceName, "Mitsubishi_Sup", callBackFromHistory); @@ -181,14 +203,18 @@ function callBackFromHistory(res) { let strHtml = ``; res = JSON.parse(res); - console.log(res); - $.each(res.data, function (index, val) { - strHtml += ` - ${val.deviceName} - ${val.value} - ${displayDate(val.timestamp)} - `; - }); + if (res.data.length > 0) { + $.each(res.data, function (index, val) { + strHtml += ` + ${val.deviceName} + ${val.value} + ${displayDate(val.timestamp)} + `; + }); + } + else + strHtml += `查無資料`; + $('#tableData tbody').html(strHtml); } @@ -202,5 +228,71 @@ pageAct.deviceItem = deviceItem; getData(); } + } + + function setDateType(type) { + pageAct.dateType = type; + let now = formatDate(new Date(Date.now()), "date"); + let ytd = formatDate(new Date(new Date().setDate(new Date().getDate() - 1)), "date"); + let tmr = formatDate(new Date(new Date().setDate(new Date().getDate() + 1)), "date"); + if (type == "day" || type == "today" || type == "ytd") { + let date = type == "ytd" ? ytd : now; + $('#startdate').css('display', 'block'); + $('#enddate').css('display', 'none'); + $('#getmonth').css('display', 'none'); + $('#startdate').val(date); + + if (type == "today") + getData(formatDate(now, "date", true), formatDate(tmr, "date", true)); + else if (type == "ytd") + getData(formatDate(ytd, "date", true), formatDate(now, "date", true)); + } + else if (type == "range") { + $('#startdate').css('display', 'block'); + $('#enddate').css('display', 'block'); + $('#getmonth').css('display', 'none'); + $('#startdate').val(now); + $('#enddate input').val(tmr); + } + else if (type == "month") { + $('#startdate').css('display', 'none'); + $('#enddate').css('display', 'none'); + $('#getmonth').css('display', 'block'); + $('#getmonth').val(now.substr(0, 7)); + } + else if (type == "ytd") { + $('#startdate').css('display', 'block'); + $('#enddate').css('display', 'none'); + $('#getmonth').css('display', 'none'); + $('#startdate').val(ytd); + } + } + + function searchDate() { + let start = new Date($('#startdate').val()); + let end = new Date(new Date().setDate(new Date($('#enddate input').val()).getDate() + 1)); + + if (pageAct.dateType == "day") + end = new Date(new Date().setDate(start.getDate() + 1)); + else if (pageAct.dateType == "month") { + start = new Date($('#getmonth').val()); + end = new Date(new Date().setDate(start.getDate() + 30)); + } + else if (pageAct.dateType != "range") + return; + + getData(formatDate(start, "date", true), formatDate(end, "date", true)); + } + + function formatDate(date, type, send = false) { + if (!send) + return displayDate(date, type).replaceAll("/", "-"); + else { + date = displayDate(date, type); + let month = date.split('/')[1]; + let year = date.split('/')[0]; + let day= date.split('/')[2]; + return month + "/" + day + "/" + year; + } } \ No newline at end of file