From bc0d397108efad4e7517d9a1c8786fad565af864 Mon Sep 17 00:00:00 2001 From: dev01 Date: Fri, 9 Dec 2022 18:20:41 +0800 Subject: [PATCH] =?UTF-8?q?[Frontend][=E7=B3=BB=E7=B5=B1=E7=9B=A3=E6=8E=A7?= =?UTF-8?q?]=20=E9=9B=BB=E6=A2=AF=E9=A0=81=E9=9D=A2=20=E5=8F=B3=E5=81=B4?= =?UTF-8?q?=E9=BB=9E=E4=BD=8D=E6=8E=A7=E5=88=B6=E7=A8=8B=E5=BA=8F=E8=AA=BF?= =?UTF-8?q?=E6=95=B4=20|=20=E5=8F=B3=E5=81=B4=E7=B7=8A=E6=80=A5=E8=BF=B4?= =?UTF-8?q?=E8=BD=89=E4=BB=8B=E9=9D=A2=E8=AA=BF=E6=95=B4=20|=20[=E5=84=80?= =?UTF-8?q?=E9=8C=B6=E6=9D=BF]=20=E8=A8=88=E6=99=82=E5=99=A8=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E5=BB=BA=E7=BD=AE=20|=20[=E8=83=BD=E6=BA=90=E7=AE=A1?= =?UTF-8?q?=E7=90=86]=20=E4=BB=8B=E9=9D=A2=E4=B8=B2=E6=8E=A5=20|=20?= =?UTF-8?q?=E4=BB=8B=E9=9D=A2=E8=AA=BF=E6=95=B4=20=EF=BD=9C=E7=B3=BB?= =?UTF-8?q?=E7=B5=B1=E5=B0=8F=E9=A1=9E=20Card=20=E5=BB=BA=E7=BD=AE=20|=20?= =?UTF-8?q?=E4=B8=8B=E6=96=B9=E5=9C=96=E8=A1=A8=20=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=BB=BA=E7=BD=AE=20|=20loading=20=E7=A8=8B=E5=BA=8F=E5=BB=BA?= =?UTF-8?q?=E7=BD=AE=20|=20=E5=86=8D=E7=94=9F=E8=83=BD=E6=BA=90=E9=9D=9C?= =?UTF-8?q?=E6=85=8B=E7=A8=8B=E5=BA=8F=E5=BB=BA=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/_dashboard.html | 136 ++--- Frontend/_energyManagement.html | 347 ++++++++++--- Frontend/_sysElevator.html | 179 ++++--- Frontend/_sysMonFloor.html | 20 +- Frontend/index.html | 8 +- Frontend/js/forge/forgemodel.js | 20 + Frontend/js/n4js/alarmbaja.js | 464 ++++++++++++------ Frontend/js/n4js/bajatest.js | 172 +++++++ Frontend/js/site.js | 38 ++ Frontend/js/style.js | 6 + Frontend/js/yourteam/plugins/yt-tab/yt-tab.js | 28 +- .../js/yourteam/yourteam.ajax.class_bak.js | 267 ++++++++++ .../js/yourteam/yourteam.utility.class.js | 129 ++++- 13 files changed, 1434 insertions(+), 380 deletions(-) create mode 100644 Frontend/js/yourteam/yourteam.ajax.class_bak.js diff --git a/Frontend/_dashboard.html b/Frontend/_dashboard.html index 36faa47..b8a9231 100644 --- a/Frontend/_dashboard.html +++ b/Frontend/_dashboard.html @@ -247,7 +247,12 @@ var elev3DBind = {}; var elev3DOption = {}; var elev3DObj = []; - var timeOutor = null; //刷新 baja 資料 定時器 + var timeOuters = []; + var eveDayElecChart = null; + var eveWeekElecChart = null; + var errRecChart = null; + var errChkChart = null; + var sysIconList = [ { mainSys: "EE", subSys: "E1", iconClass: "fal fa-grip-vertical" }, { mainSys: "EE", subSys: "E2", iconClass: "fal fa-grip-horizontal" }, @@ -268,39 +273,6 @@ timeOutGetData(); }); - // 從數字週數轉為中文週數 - function dayToChiDay(num) { - let chiDay = ["週日", "週一", "週二", "週三", "週四", "週五", "週六"]; - return chiDay[num]; - } - - // 取得現在或前後時間,輸出單位依據 type - function getTimeByType(type = null, cal = 0) { - let now = new Date(); - return strToDate(now, type, cal); - } - - // 取得某當下時間或前後時間,輸出單位依據 type - function strToDate(text, type = null,cal = 0) { - let calDay = function (_d, _cal) { - return new Date(_d.getTime() + (cal * 24 * 60 * 60 * 1000)); - } - let tarDate = new Date(text); - let result = 0; - if (type == "year") { - result = calDay(tarDate, cal).getFullYear(); - } else if (type == "month") { - result = calDay(tarDate, cal).getMonth(); - } else if (type == "date") { - result = calDay(tarDate, cal).getDate(); - } else if (type == "day") { - result = calDay(tarDate, cal).getDay(); - } else { - result = calDay(tarDate, cal); - } - return result; - } - //取得 左下方 各系統小類 function getSubList() { let url = baseApiUrl + "/api/Device/GetMainSub"; @@ -444,7 +416,7 @@ } } - // 圖表 - 今天與昨天用電量 (折線圖) + // 圖表 - 今天與昨天用電量 (長條圖) function chartEveDaysElec(todayData, yesData) { let eveDayElecChartCanvas = $('#eveDayElecChart').get(0).getContext('2d'); @@ -519,14 +491,25 @@ }, } - // This will get the first returned node in the jQuery collection. - eveDayElecChart = new Chart(eveDayElecChartCanvas, { - data: eveDayElecChartData, - options: eveDayElecChartOptions - }) + if (eveDayElecChart == null) { + eveDayElecChart = new Chart(eveDayElecChartCanvas, { + data: eveDayElecChartData, + options: eveDayElecChartOptions + }) + } else { + eveDayElecChart.data.datasets.forEach((dataset) => { + if (dataset.order == 1) { + dataset.data = todayData?.data.map(x => x.sum); + } else { + dataset.data = yesData?.data.map(x => x.sum); + } + }); + } + + } - // 圖表 - 這週與上週用電量 (折線圖) + // 圖表 - 這週與上週用電量 (長條圖) function chartEveWeeksElec(curWeekData, prevWeekData) { let eveWeekElecChartCanvas = $('#eveWeekElecChart').get(0).getContext('2d'); @@ -598,11 +581,20 @@ }, } - // This will get the first returned node in the jQuery collection. - eveWeekElecChart = new Chart(eveWeekElecChartCanvas, { - data: eveWeekElecChartData, - options: eveWeekElecChartOptions - }) + if (eveWeekElecChart == null) { + eveWeekElecChart = new Chart(eveWeekElecChartCanvas, { + data: eveWeekElecChartData, + options: eveWeekElecChartOptions + }) + } else { + eveWeekElecChart.data.datasets.forEach((dataset) => { + if (dataset.order == 1) { + dataset.data = curWeekData.map(x => x.sum); + } else { + dataset.data = prevWeekData.map(x => x.sum); + } + }); + } } // 圖表 - 異常與賦歸圖表 (圓餅圖) @@ -638,11 +630,17 @@ } // This will get the first returned node in the jQuery collection. - let errRecChart = new Chart(errRecChartCanvas, { - type: "pie", - data: errRecChartData, - options: errRecChartOptions - }) + if (errRecChart == null) { + errRecChart = new Chart(errRecChartCanvas, { + type: "pie", + data: errRecChartData, + options: errRecChartOptions + }) + } else { + errRecChart.data.datasets.forEach((dataset) => { + dataset.data = datas; + }); + } } // 圖表 - 異常確認與未確認圖表 (圓餅圖) @@ -677,12 +675,18 @@ } - // This will get the first returned node in the jQuery collection. - let errChkChart = new Chart(errChkChartCanvas, { - type: "pie", - data: errChkChartData, - options: errChkChartOptions - }) + if (errChkChart == null) { + errChkChart = new Chart(errChkChartCanvas, { + type: "pie", + data: errChkChartData, + options: errChkChartOptions + }) + } else { + errChkChart.data.datasets.forEach((dataset) => { + dataset.data = datas; + }); + } + } // 從 baja 訂閱 左下角各系統小類異常狀態 @@ -694,7 +698,7 @@ /*$(`.dev-group i.fa-lightbulb-on`)*/ getSystemAlarmByBaja((data) => { - + console.log(data) $.each(data.data, (idx, alaObj) => { if (alaObj.alarmClass.indexOf("_") != -1) { let mainSubSys = alaObj.alarmClass.split("_").slice(0, 2).join("/"); @@ -740,13 +744,17 @@ } function timeOutGetData() { - timeOutor = setInterval(() => { + let timeOut3s = setInterval(() => { getAlarmSub(); - },3000) + }, 3000) + let timeOut5m = setInterval(() => { + getElectricBaja(); + }, 5 * 60 * 1000) + timeOuters = timeOuters.concat([timeOut3s, timeOut5m]); } function show3DModel() { - launchViewer(pageAct.urn, (viewer, nodeIds) => { + launchViewerNoTools(pageAct.urn, (viewer, nodeIds) => { nodeIds = Array.from(nodeIds); $.each(nodeIds, (idx, item) => { elev3DBind[item[0]] = item[1]; @@ -807,7 +815,11 @@ } data.device_number = data.device_number_full; let matchDevice = allEleDevList.filter(x => x.device_number == data.device_number)[0]; - let master = matchDevice.device_number.split("_")[5]; + let master = matchDevice?.device_number.split("_")[5]; + + if (!matchDevice) { + return; + } if (data.point_name == "CP") { if (elev3DObj.length != 0) { diff --git a/Frontend/_energyManagement.html b/Frontend/_energyManagement.html index f9edd82..8f66e17 100644 --- a/Frontend/_energyManagement.html +++ b/Frontend/_energyManagement.html @@ -2,83 +2,43 @@
- - - - + + + +
-
+

- 空調系統 - 用電狀況 + - 用電狀況

-
+

今日耗電量 kWh

-
-
-
-
-
- - - -
- $44.34 / GE -
- Increased Profit as per redux margins and estimates -
-
-
-
-
78%
-
-
+ +
+
-
-
+

用電比較

-
-
-
-
- 3,4,5,8,2 -
-
- -

37.56%

-
-
-
-
- 5,3,1,7,9 -
-
- -

759

-
-
-
-
- 3,4,3,5,5 -
-
- -

12.17%

-
-
-
+ +
+ +
-
@@ -238,13 +198,18 @@ \ No newline at end of file diff --git a/Frontend/_sysElevator.html b/Frontend/_sysElevator.html index cff40a8..651b043 100644 --- a/Frontend/_sysElevator.html +++ b/Frontend/_sysElevator.html @@ -43,6 +43,21 @@ border-top: 0; z-index: 2; } + + .table-compact td{ + padding:0.2rem 0.3rem; + } + + #emerTurn tr td:nth-child(2) { + width: 50%; + text-align: center; + justify-content: center; + } + + #emerTurn tr td:nth-child(1) { + width:35%; + } +
@@ -86,7 +101,7 @@
-
+
@@ -111,16 +126,49 @@

緊急回轉

-
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
@@ -928,6 +952,27 @@ myBaja.setSubscribeDevicesByBql(subOrdPath); myBaja.setSubscribeDevicesCallBack(function (data) { try { + if (allDevList.length == 0) { + return false; + } + + data.device_number = data.device_number_full; + let matchDevice = allDevList.filter(x => x.device_number == data.device_number)[0]; + let master = matchDevice.device_number.split("_")[5]; + + //將訂閱值塞入 subSeviceData + if (subSeviceData.findIndex(x => x.device_number == matchDevice.device_number) == -1) { + let obj = {}; + obj.device_number = matchDevice.device_number; + subSeviceData.push(obj) + } + + let subData = subSeviceData.filter(x => x.device_number == matchDevice.device_number)[0]; + + if (subData) { + subData[data.point_name] = data.value; + } + function getValueByName(pointName) { return data.point_name == pointName ? data.value : null; } @@ -943,26 +988,23 @@ } function actLightByPoiEx(pointName1, selector, pointName2, exCond) { - $(selector).removeClass("bg-orange").removeClass("bg-red"); - if (getValueByName(pointName2) == exCond) { - if (pointName1 == "falseText") { + $(selector).removeClass("bg-orange").removeClass("bg-danger").removeClass("bg-secondary").removeClass("bg-success"); + $(selector).parent("td").prev().find("label").text("未動作"); + if (subData[pointName2] == exCond) { + if (subData[pointName1] == "falseText") { $(selector).addClass("bg-secondary"); - $(selector).parent("div").prev().find("label").text("取消控制"); + $(selector).parent("td").prev().find("label").text("取消控制"); } else { - $(selector).addClass("bg-red"); - $(selector).parent("div").prev().find("label").text("控制"); + $(selector).addClass("bg-danger"); + $(selector).parent("td").prev().find("label").text("控制"); } } else { + $(selector).parent("td").prev().find("label").text("休止"); $(selector).addClass("bg-success"); } } - if (allDevList.length == 0) { - return false; - } - data.device_number = data.device_number_full; - let matchDevice = allDevList.filter(x => x.device_number == data.device_number)[0]; - let master = matchDevice.device_number.split("_")[5]; + //狀態 if (data.point_name == "ST") { $(`#${matchDevice.device_number}_card [name=devStatus]`).text(data.value); @@ -1002,6 +1044,7 @@ //地震管制 actLightByPoi("EER", "#earQuaCon"); if (data.point_name == "DNO" || data.point_name == "SP_RCS") { + debugger //遠端休止 actLightByPoiEx("SP_RCS", "#disRes", "DNO", "trueText"); } @@ -1011,18 +1054,7 @@ } } - //將訂閱值塞入 subSeviceData - if (subSeviceData.findIndex(x => x.device_number == matchDevice.device_number) == -1) { - let obj = {}; - obj.device_number = matchDevice.device_number; - subSeviceData.push(obj) - } - - let subData = subSeviceData.filter(x => x.device_number == matchDevice.device_number)[0]; - - if (subData) { - subData[data.point_name] = data.value; - } + // 設置燈色、卡片閃爍 setLightColor(); // Card table 更新 @@ -1038,7 +1070,6 @@ } }); myBaja.setSubscribeDeviceEndCallBack(function (data) { - let devNumArr = data.map(x => { return { devNum: x.device_number_full, priority: allDevList.filter(y => y.device_number == x.device_number_full)[0]?.priority } }).DistinctBy("devNum"); devNumArr = devNumArr.oSort("priority"); $.each(devNumArr, (idx, devObj) => { @@ -1142,9 +1173,7 @@ // Card - 設置列表中訂閱內容 function subDeviceSetTable(devNum) { - if (allDevList.filter(x => !x.device_number).length > 0) { - - } + let subData = subSeviceData.filter(x => x.device_number == devNum)[0] let matchDevice = allDevList.filter(x => x.device_number == devNum)[0]; if (!subData) { @@ -1171,8 +1200,6 @@ elevObj.setElevFloor(matchDevice.device_number, subData["CP"]); } - - if (elev3DObj.length != 0) { let elevObj = elev3DObj.filter(x => x.nodeId == elev3DBind[devNum])[0]; if (elevObj && elevObj.id) { diff --git a/Frontend/_sysMonFloor.html b/Frontend/_sysMonFloor.html index fb1f7f0..c6ac13b 100644 --- a/Frontend/_sysMonFloor.html +++ b/Frontend/_sysMonFloor.html @@ -7,8 +7,19 @@
-
+ + +
+
+
+
+
+
+
@@ -20,6 +31,7 @@ var global_emergency_alarm_device_number = []; var zoomToggle = 3; $(function () { + show3DModel(); initChart(); getFloData(); }) @@ -813,4 +825,10 @@ }); } } + + function show3DModel() { + launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dnNjb2RlX2ZvcmdlX3Rlc3QvJUUzJTgwJTkwQVJDJUUzJTgwJTkxQjFGXzIwMjJfMTJfMDQubndj", (viewer, nodeIds) => { + + }); + } \ No newline at end of file diff --git a/Frontend/index.html b/Frontend/index.html index 2705a6a..19ffc27 100644 --- a/Frontend/index.html +++ b/Frontend/index.html @@ -2281,7 +2281,13 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li }) endPageLoading(); - typeof timeOutor != "undefined" ? clearInterval(timeOutor) : ""; // dashboard 定時更新 baja 資料定時器關閉 + + if (typeof timeOuters != "undefined") { + $.each(timeOuters, (idx, timeOut) => { + clearInterval(timeOut); + }) + timeOuters = []; + } $("#app").load(`_${page}.html`, loadCallback); }) diff --git a/Frontend/js/forge/forgemodel.js b/Frontend/js/forge/forgemodel.js index f45d0fa..1e226b7 100644 --- a/Frontend/js/forge/forgemodel.js +++ b/Frontend/js/forge/forgemodel.js @@ -95,6 +95,26 @@ function launchViewer(urn, callback) { }); } +function launchViewerNoTools(urn, callback) { + var options = { + env: 'AutodeskProduction', + getAccessToken: getForgeToken + }; + + Autodesk.Viewing.Initializer(options, () => { + //viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('forgeViewer')); + viewer = new Autodesk.Viewing.Viewer3D(document.getElementById('forgeViewer')); + viewer.start(); + var documentId = 'urn:' + urn; + + Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure); + + $("#forgeViewer").on("autodesk:loaded", function (e, nodeIds) { + callback ? callback(viewer, nodeIds) : ""; + }) + }); +} + function getAllLeafComponents(viewer, callback) { var cbCount = 0; var tree; diff --git a/Frontend/js/n4js/alarmbaja.js b/Frontend/js/n4js/alarmbaja.js index b64bf1a..9e1a2d2 100644 --- a/Frontend/js/n4js/alarmbaja.js +++ b/Frontend/js/n4js/alarmbaja.js @@ -12,6 +12,78 @@ function addzero(num) { * @param {any} alarmClass * @param {any} callback */ +// function getAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, alarmClass, callback) { +// let _sourceTmp; +// var _result = ""; +// var _ss = ""; +// var _bfName = ""; +// var _sourceName = ""; +// var _index = 0; +// var _recoverState = isRecover ? "!= null" : "= null"; +// var _ackState = isAck ? "= 1" : "!= 1"; + +// require(['baja!'], function (baja) { +// baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmClass = '" + alarmClass + "' and timestamp.millis > " + startDate_millisecond + " and timestamp.millis < " + endDate_millisecond + " and normalTime " + _recoverState + " order by timestamp asc").get() +// .then(function (table) { +// return table.cursor({ +// each: function (record) { +// _sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_'); +// _bfName = _sourceTmp[1] + "-" + _sourceTmp[4]; +// _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8]; +// _ss += ', "' + _index + '": {"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; +// _index++; +// }, +// after: function () { +// _result += '{' + '"count": ' + _index; +// _result += _ss; +// _result += '}'; +// if (typeof callback === 'function') { +// callback(_result); +// } +// } +// }); +// }); +// }); +// } +// function getAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, alarmClass, callback) { +// let _sourceTmp; +// var _result = ""; +// var _ss = ""; +// var _bfName = ""; +// var _sourceName = ""; +// var _index = 0; +// var _recoverState = isRecover ? "!= null" : "= null" +// var _ackState = isAck ? "= 1" : "!= 1"; + +// require(['baja!'], function (baja) { +// baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmClass = '" + alarmClass + "' and timestamp.millis > " + startDate_millisecond + " and timestamp.millis < " + endDate_millisecond + " and normalTime " + _recoverState + " order by timestamp asc").get() +// .then(function (table) { +// return table.cursor({ +// each: function (record) { +// _sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_'); +// _bfName = _sourceTmp[1] + "-" + _sourceTmp[4]; +// _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8]; + +// if (_index == 0) +// _ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; +// else +// _ss += ',{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; +// _index++; +// }, +// after: function () { +// _result += '{' + '"count": ' + _index + ', "data":['; +// _result += _ss; +// _result += ']}'; +// if (typeof callback === 'function') { +// callback(_result); +// } +// }, +// limit: -1, +// offset: 0 +// }); +// }); +// }); +// } function getAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, alarmClass, callback) { let _sourceTmp; var _result = ""; @@ -52,59 +124,40 @@ function getAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, i }); } -/** - * 取得所有異常資料 by baja - * @param {any} startDate_millisecond - * @param {any} endDate_millisecond - * @param {any} isRecover - * @param {any} isAck - * @param {any} callback - */ -function getAllDeviceAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, callback) { - let _sourceTmp; - var _result = ""; - var _ss = ""; - var _bfName = ""; - var _sourceName = ""; - var _index = 0; - var _recoverState = isRecover ? "!= null" : "= null"; - var _ackState = isAck ? "= 'acked'" : "= 'unacked'"; - - require(['baja!'], function (baja) { - console.log("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc"); - baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc").get() - .then(function (table) { - return table.cursor({ - each: function (record) { - _sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_'); - _bfName = _sourceTmp[1] + "-" + _sourceTmp[4]; - _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8]; - if (_index == 0) - _ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; - else - _ss += ',{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; - _index++; - }, - after: function () { - _result += '{' + '"count": ' + _index + ', "data":['; - _result += _ss + ']'; - _result += '}'; - if (typeof callback === 'function') { - callback(_result); - } - }, - limit: -1, - offset: 0 - }); - }); - }); -} - /** * 取得單一設備最新10筆異常資料 by baja * @param {any} devicePath * @param {any} callback */ +// function getOneDeviceAlarmTop10ByBaja(devicePath, callback) { +// var _result = ""; +// var _ss = ""; +// var _index = 0; +// //{ "count":2,"data": [{ "time": "2022/11/14 15:00:00", "errId": "0001", "ackCheck": "未確認", "errReason": "燈泡故障" }, { "time": "2022/11/14 15:00:00", "errId": "0002", "ackCheck": "未確認", "errReason": "燈泡故障" }]} +// require(['baja!'], function (baja) { +// baja.Ord.make("local:|foxs:|alarm:|bql:select top 10 timestamp, ackState, alarmData, alarmData.sourceName, sourceState, uuid, alarmData.msgText, normalTime where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc").get() +// .then(function (table) { +// return table.cursor({ +// each: function (record) { +// if (_index == 0) +// _ss += '{"uuid":"' + record.get('uuid') + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "timestamp":"' + record.get('timestamp') + '"}'; +// else +// _ss += ',{"uuid":"' + record.get('uuid') + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "timestamp":"' + record.get('timestamp') + '"}'; +// _index++; +// }, +// after: function () { +// _result += '{' + '"count": ' + _index +', "data":['; + +// _result += _ss+']'; +// _result += '}'; +// if (typeof callback === 'function') { +// callback(_result); +// } +// } +// }); +// }); +// }); +// } function getOneDeviceAlarmTop10ByBaja(devicePath, callback) { var _result = ""; var _ss = ""; @@ -152,103 +205,36 @@ function getOneDeviceAlarmTop10ByBaja(devicePath, callback) { }); } -/** - * 取得單一設備異常 - * @param {any} devicePath - * @param {any} callback - */ -function getOneDeviceAlarmByBaja(devicePath, callback) { - let _sourceTmp; - var _result = ""; - var _ss = ""; - var _bfName = ""; - var _sourceName = ""; - var _index = 0; - - require(['baja!'], function (baja) { - console.log("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc"); - baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc").get() - .then(function (table) { - return table.cursor({ - each: function (record) { - _sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_'); - _bfName = _sourceTmp[1] + "-" + _sourceTmp[4]; - _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8]; - if (_index == 0) - _ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; - else - _ss += ',{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; - _index++; - }, - after: function () { - _result += '{' + '"count": ' + _index + ', "data":['; - _result += _ss + ']'; - _result += '}'; - if (typeof callback === 'function') { - callback(_result); - } - }, - limit: -1, - offset: 0 - }); - }); - }); -} - -/** - * 取得單一設備異常 有時間、確認、復歸條件 - * @param {any} devicePath - * @param {any} startDate_millisecond - * @param {any} endDate_millisecond - * @param {any} isRecover - * @param {any} isAck - * @param {any} callback - */ -function getOneDeviceAlarmWithTimeByBaja(devicePath, startDate_millisecond, endDate_millisecond, isRecover, isAck, callback) { - let _sourceTmp; - var _result = ""; - var _ss = ""; - var _bfName = ""; - var _sourceName = ""; - var _index = 0; - var _recoverState = isRecover ? "!= null" : "= null"; - var _ackState = isAck ? "= 'acked'" : "= 'unacked'"; - - require(['baja!'], function (baja) { - console.log("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' and timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc"); - baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' and timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc").get() - .then(function (table) { - return table.cursor({ - each: function (record) { - _sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_'); - _bfName = _sourceTmp[1] + "-" + _sourceTmp[4]; - _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8]; - if (_index == 0) - _ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; - else - _ss += ',{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; - _index++; - }, - after: function () { - _result += '{' + '"count": ' + _index + ', "data":['; - _result += _ss + ']'; - _result += '}'; - if (typeof callback === 'function') { - callback(_result); - } - }, - limit: -1, - offset: 0 - }); - }); - }); -} - /** * 在單一系統下,取得各個設備的異常狀態 * @param {any} systemPath * @param {any} callback */ +// function getOneSystemAlarmStateByBaja(systemPath, callback) { +// var _result = ""; +// var _ss = ""; +// var _index = 0; + +// require(['baja!'], function (baja) { +// baja.Ord.make("local:|foxs:|alarm:|bql:select alarmData, alarmData.sourceName, sourceState, uuid where alarmData.sourceName like '%" + systemPath + "%' order by timestamp desc").get() +// .then(function (table) { +// return table.cursor({ +// each: function (record) { +// _ss += ', "' + _index + '": {"uuid":"' + record.get('uuid') + '", "sourceName":"' + record.get('alarmData').get('sourceName') + '", "sourceState":"' + record.get('sourceState') + '"}'; +// _index++; +// }, +// after: function () { +// _result += '{' + '"count": ' + _index; +// _result += _ss; +// _result += '}'; +// if (typeof callback === 'function') { +// callback(_result); +// } +// } +// }); +// }); +// }); +// } function getOneSystemAlarmStateByBaja(systemPath, callback) { var _result = ""; var _ss = ""; @@ -295,6 +281,10 @@ function getOneSystemStateByBaja(systemPath, callback) { .then(function (table) { return table.cursor({ each: function (record) { + //if (_index == 0) + // _ss += '{"sourceState":"' + record.get('sourceState') + '"}'; + //else + // _ss += '{"sourceState":"' + record.get('sourceState') + '"}'; _ss += '{"sourceState":"' + record.get('sourceState') + '"}'; _index++; }, @@ -432,7 +422,7 @@ function getUnCheckedAckedCountByBaja(callback) { function getSystemAlarmByBaja(callback) { var _result = { count: 0, data: [] }; var _index = 0; - + require(['baja!'], function (baja) { //baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime where isAlarm").get() baja.Ord.make("local:|foxs:|alarm:|bql:select alarmClass where isAlarm").get() @@ -441,7 +431,7 @@ function getSystemAlarmByBaja(callback) { each: function (record) { let main = {}; main.alarmClass = record.get('alarmClass'); - + _result.data.push(main); _index++; }, @@ -457,3 +447,193 @@ function getSystemAlarmByBaja(callback) { }); }); } + +// /** +// * 取得單一設備異常 +// * @param {any} callback +// */ +// //(devicePath, callback) +// function getOneDeviceAlarmByBaja(devicePath, startDate_millisecond, endDate_millisecond, isRecover, isAck, callback) { +// // var _result = ""; +// // var _ss = ""; +// // var _occurrenceTime = ""; +// // var _normalTime = ""; +// // var _index = 0; + +// let _sourceTmp; +// var _result = ""; +// var _ss = ""; +// var _bfName = ""; +// var _sourceName = ""; +// var _index = 0; +// var _recoverState = isRecover ? "!= null" : "= null"; +// //local:|foxs:|alarm:|bql:select ackState from openAlarms where ackState ='acked' +// var _ackState = isAck ? "= 'acked'" : "= 'unacked'"; + +// //{ "count":2,"data": [{ "time": "2022/11/14 15:00:00", "errId": "0001", "ackCheck": "未確認", "errReason": "燈泡故障" }, { "time": "2022/11/14 15:00:00", "errId": "0002", "ackCheck": "未確認", "errReason": "燈泡故障" }]} +// require(['baja!'], function (baja) { +// console.log("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' and timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc"); +// baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' and timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc").get() +// // console.log("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' and alarmClass = '" + alarmClass + "' and timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc"); +// // baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' and alarmClass = '" + alarmClass + "' and timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc").get() +// //baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmData, alarmData.sourceName, sourceState, uuid, alarmData.msgText, normalTime where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc").get() +// .then(function (table) { +// return table.cursor({ +// each: function (record) { + +// _sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_'); +// _bfName = _sourceTmp[1] + "-" + _sourceTmp[4]; +// _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8]; +// // _occurrenceTime = ""; +// // _normalTime = ""; +// //var _resultUuid = record.get('uuid').toString().split("-");//43dc7846-bd96-4be2-ab35-f11aec729c60 + +// // var _timestampTemp = new Date(record.get('timestamp').toString()); +// // _occurrenceTime += _timestampTemp.getFullYear().toString() + "-" + addzero(_timestampTemp.getMonth() + 1).toString() + "-" + addzero(_timestampTemp.getDate()).toString() + " " + addzero(_timestampTemp.getHours()).toString() + ":" + addzero(_timestampTemp.getMinutes()).toString() + ":" + addzero(_timestampTemp.getSeconds()).toString(); + +// // var _normaltime = new Date(record.get('normalTime').toString()); +// // _normalTime += _normaltime.getFullYear().toString() + "-" + addzero(_normaltime.getMonth() + 1).toString() + "-" + addzero(_normaltime.getDate()).toString() + " " + addzero(_normaltime.getHours()).toString() + ":" + addzero(_normaltime.getMinutes()).toString() + ":" + addzero(_normaltime.getSeconds()).toString(); + +// // var _msgText = record.get('alarmData').get('msgText');// == 1 ? _occurrenceTime : "未確認"; +// // var _ackText = record.get('ackState') == 1 ? _occurrenceTime : "未確認"; + +// //_ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; +// if (_index == 0) +// _ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; +// //_ss += '{"uuid":"' + record.get('uuid') + '", "msgText":"' + _msgText + '", "ackState":"' + _ackText + '", "timestamp":"' + _occurrenceTime + '", "normalTime":"' + _normalTime + '"}'; +// else +// _ss += ',{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; +// _index++; +// }, +// after: function () { +// _result += '{' + '"count": ' + _index + ', "data":['; +// _result += _ss + ']'; +// _result += '}'; +// if (typeof callback === 'function') { +// callback(_result); +// } +// }, +// limit: -1, +// offset: 0 +// }); +// }); +// }); +// } + +/** + * 取得單一設備異常 + * @param {any} devicePath + * @param {any} callback + */ + function getOneDeviceAlarmByBaja(devicePath, callback) { + let _sourceTmp; + var _result = ""; + var _ss = ""; + var _bfName = ""; + var _sourceName = ""; + var _index = 0; + + require(['baja!'], function (baja) { + console.log("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc"); + baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc").get() + .then(function (table) { + return table.cursor({ + each: function (record) { + _sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_'); + _bfName = _sourceTmp[1] + "-" + _sourceTmp[4]; + _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8]; + if (_index == 0) + _ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; + else + _ss += ',{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss + ']'; + _result += '}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} + +function getAllDeviceAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, callback) { + let _sourceTmp; + var _result = ""; + var _ss = ""; + var _bfName = ""; + var _sourceName = ""; + var _index = 0; + var _recoverState = isRecover ? "!= null" : "= null"; + var _ackState = isAck ? "= 'acked'" : "= 'unacked'"; + + require(['baja!'], function (baja) { + console.log("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc"); + baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where timestamp.millis >= " + startDate_millisecond + " and timestamp.millis <= " + endDate_millisecond + " and normalTime " + _recoverState + " and ackState " + _ackState + " order by timestamp desc").get() + .then(function (table) { + return table.cursor({ + each: function (record) { + _sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_'); + _bfName = _sourceTmp[1] + "-" + _sourceTmp[4]; + _sourceName = _sourceTmp[7] + "-" + _sourceTmp[8]; + if (_index == 0) + _ss += '{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; + else + _ss += ',{"buildingFloorName_zh":"' + _bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + _sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss + ']'; + _result += '}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} + +/** + * [首頁] 圓餅圖資料 - 全部的異常 + * @param {any} callback + */ + function getAlarmForChartDataByBaja(callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) { + baja.Ord.make("local:|foxs:|alarm:|bql:select alarmClass, ackState, normalTime where isAlarm").get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"alarmClass":"' + record.get('alarmClass') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; + else + _ss += ',{"alarmClass":"' + record.get('alarmClass') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} \ No newline at end of file diff --git a/Frontend/js/n4js/bajatest.js b/Frontend/js/n4js/bajatest.js index 94492f0..ceea87c 100644 --- a/Frontend/js/n4js/bajatest.js +++ b/Frontend/js/n4js/bajatest.js @@ -6,6 +6,11 @@ var ordPath; //當前點選選單的tag,用來抓出設備路徑,例如:旅 let baja_subscribe_alarm_callback_func; //設定 alarm BQL訂閱之後要回傳的Function let baja_subscribe_end_alarm_callback_func; //設定 alarm BQL訂閱結束之後要回傳的Function var ordPathForAlarm; //當前點選選單的tag,用來抓出alarm路徑 + +let baja_subscribe_electricmeter_callback_func; +let baja_subscribe_end_electricmeter_callback_func; +var ordPathForElectricmeter; + var startPageLoading; // 開始 loading var endPageLoading; // 開始 loading //window.baja = null; @@ -57,6 +62,25 @@ function subscriptionAlarms() { } +function subscriptionElectricmeter() { + // 用BQL的方式去訂閱 + this.setSubscribeElectricmeterByBql = function (tempOrdPath) { + BajaSubscribeElectricmeterByBql(tempOrdPath); + }; + // BQL去訂閱回傳的Function + this.setSubscribeElectricmeterCallBack = function (callBackFunc) { + if (callBackFunc != undefined && callBackFunc != null) { + baja_subscribe_electricmeter_callback_func = callBackFunc; + } + } + // BQL訂閱結束回傳的Function + this.setSubscribeElectricmeterEndCallBack = function (callBackFunc) { + if (callBackFunc != undefined && callBackFunc != null) { + baja_subscribe_end_electricmeter_callback_func = callBackFunc; + } + } +} + function MyBaja() { // 取得使用者帳號 this.setMyUserAccount = function (callBackFunc = null) { @@ -351,6 +375,154 @@ function BajaSubscribeAlarmsByBql(ordPathForAlarm) { }); } +/** + * 使用者透過BQL指定路徑去訂閱 electricmeter + */ + function BajaSubscribeElectricmeterByBql(ordPathForElectricmeter) { + + + require(['baja!'], function (baja) { + console.log("進入Function 準備執行BQL訂閱"); + startPageLoading ? startPageLoading() : "" + var init_start = new Date(Date.now()); + var sub = new baja.Subscriber(); + + sub.attach('changed', function (prop) { + if (prop.getName() === 'out') { + var out_value = this.getOutDisplay(); + var target_device_number = this.$parent.getDisplayName().split('_').slice(0, 5).join('_'); + var point_name = this.getDisplayName(); + + //依據Facets判斷回傳的內容值為何 + var facets_split = this.getFacets1().$cEncStr.split('|'); + var facets_arr = []; + facets_split.forEach(function (item, index) { + facets_arr.push(item.split('=s:')); + }); + + var facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {}) + + var point_out_split = this.getOutDisplay().split(' '); + + let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]); + + if (key == undefined) { + key = point_out_split[0]; + } + + var modify_target_device = { + "device_number": target_device_number ? target_device_number : null, + //"device_number_full": this.$parent.getSlotPath().$names.join("_"), + "point_name": point_name ? point_name : null, + "value": key + } + + if (baja_subscribe_electricmeter_callback_func != undefined && baja_subscribe_electricmeter_callback_func != null) { + baja_subscribe_electricmeter_callback_func(modify_target_device, true); //第2參數用在平面圖,刷新畫面 + } + } + }, function (err) { + console.log(err) + }); + + //使用bql語法 + console.log(`local:|foxs:|station:|slot:/${ordPathForElectricmeter.devicePath}|bql:select name, out, out.value, slotPath, facets from control:ControlPoint`); + baja.Ord.make(`local:|foxs:|station:|slot:/${ordPathForElectricmeter.devicePath}|bql:select name, out, out.value, slotPath, facets from control:ControlPoint`) + .get( + function (table) { + var tableStart, tableFinish; + var subStart, subFinish; + var component_index = 0; + var total_component_index = 0; + var totalTargetDevice = []; + var readBqlFinish = new Date(Date.now()); + console.log("讀取路徑完成-花費時間", (readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec"); + table.cursor({ + before: function () { + totalTargetDevice = []; + tableStart = new Date(Date.now()); + $("#table-start-timestamp").html(tableStart.toISOString()); + render_start = new Date(Date.now()); + + }, + each: function (item, index) { + if (index < 1) { + subStart = new Date(Date.now()); + $("#sub-start").html(subStart.toISOString()); + } + $("#sub-number").html(index + 1); + total_component_index = index; + + + + var target_device_number_split = this.getDisplay("slotPath").split('/'); + var target_device_number = target_device_number_split[8]; + //console.log(target_device_number); + var point_name = this.getDisplay("name"); + var facets = this.getDisplay("facets"); + + //依據Facets判斷回傳的內容值為何 + var facets_split = facets.split(','); + var facets_arr = []; + facets_split.forEach(function (item, index) { + facets_arr.push(item.split('=')); + }); + + facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {}) + + var point_out_split = this.getDisplay("out").split(' '); + + let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]); + + if (key == undefined) { + key = point_out_split[0]; + } + + var modify_target_device = { + "device_number": target_device_number ? target_device_number : null, + //"device_number_full": this.getDisplay("slotPath").split("slot:")[1].split('/').slice(1, -1).join("_"), + "point_name": point_name ? point_name : null, + "value": key + } + totalTargetDevice.push(modify_target_device); + //取得component當下就更新設備點位 + if (baja_subscribe_electricmeter_callback_func != undefined && baja_subscribe_electricmeter_callback_func != null) { + baja_subscribe_electricmeter_callback_func(modify_target_device); + } + + + baja.Ord.make("local:|foxs:|station:|" + this.getDisplay("slotPath")) + .get() + .then(function (component) { + component_index++; + //var target_device_number = component.$parent.getDisplayName().split('_').slice(0, 5).join('_'); + //var point_name = component.getDisplayName(); + + sub.subscribe({ + comps: component, + }); + tolSubList.push(sub); + subFinish = new Date(Date.now()); + $("#sub-end").html(subFinish.toISOString()); + $("#sub-time").html((subFinish.getTime() - subStart.getTime()) / 1000 + "sec"); + // console.log("訂閱完成時間", (subFinish.getTime() - subStart.getTime()) / 1000 + "sec"); + }); + }, + after: function () { + tableFinish = new Date(Date.now()); + if (baja_subscribe_end_electricmeter_callback_func != undefined && baja_subscribe_end_electricmeter_callback_func != null) { + baja_subscribe_end_electricmeter_callback_func(totalTargetDevice); + } + endPageLoading ? endPageLoading() : "" + console.log("表格完成時間", (tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec"); + }, + limit: -1, + offset: 0 + }); + }); + }) +} + // function getAlarmCountByBaja(callback) { // var _result = ""; // var _index = 0; diff --git a/Frontend/js/site.js b/Frontend/js/site.js index 35149a7..d9d3b38 100644 --- a/Frontend/js/site.js +++ b/Frontend/js/site.js @@ -171,6 +171,11 @@ function creOption(text = null, value = null, data = {}, attr = {}, cls = [], na return creEle("option", text, id, name, cls, data, attr); } +function creImg(ele, text = null, id = null, name = null, cls = [], data = {}, attr = {}) { + let comp = eleBuild(text, id, name, cls, data, attr); + return $(`<${ele} ${comp.attrText}>${comp.text}`); +} + /** * 根據該棟建築底下的'所有'電梯執行緒物件 * */ @@ -348,3 +353,36 @@ class ElevatorHandler { } } + +// 從數字週數轉為中文週數 +function dayToChiDay(num) { + let chiDay = ["週日", "週一", "週二", "週三", "週四", "週五", "週六"]; + return chiDay[num]; +} + +// 取得現在或前後時間,輸出單位依據 type +function getTimeByType(type = null, cal = 0) { + let now = new Date(); + return strToDate(now, type, cal); +} + +// 取得某當下時間或前後時間,輸出單位依據 type +function strToDate(text, type = null, cal = 0) { + let calDay = function (_d, _cal) { + return new Date(_d.getTime() + (cal * 24 * 60 * 60 * 1000)); + } + let tarDate = new Date(text); + let result = 0; + if (type == "year") { + result = calDay(tarDate, cal).getFullYear(); + } else if (type == "month") { + result = calDay(tarDate, cal).getMonth(); + } else if (type == "date") { + result = calDay(tarDate, cal).getDate(); + } else if (type == "day") { + result = calDay(tarDate, cal).getDay(); + } else { + result = calDay(tarDate, cal); + } + return result; +} \ No newline at end of file diff --git a/Frontend/js/style.js b/Frontend/js/style.js index c7218b7..4817d3c 100644 --- a/Frontend/js/style.js +++ b/Frontend/js/style.js @@ -68,6 +68,12 @@ Array.prototype.oSort = function (key) { } return this.sort(compareNumbers); } + +Array.prototype.sum = function () { + return this.reduce(function (a, b) { + return a + b; + }, 0); +} BigInt.prototype.toJSON = function () { return this.toString() } $.fn.classList = function () { return this[0].className.split(/\s+/); }; diff --git a/Frontend/js/yourteam/plugins/yt-tab/yt-tab.js b/Frontend/js/yourteam/plugins/yt-tab/yt-tab.js index e18c733..f51b490 100644 --- a/Frontend/js/yourteam/plugins/yt-tab/yt-tab.js +++ b/Frontend/js/yourteam/plugins/yt-tab/yt-tab.js @@ -20,7 +20,7 @@ $(function () { * */ function initTabsByEle() { /*_ytTabInited = [];*/ - $("[data-tabname][data-target]:not([data-tabrole=child])").each(function (index, value) { + $("[data-tabname]:not([data-tabrole=child])").each(function (index, value) { let tabName = $(value).data("tabname"); if (_ytTabInited.indexOf(tabName) == -1) { var ytTab = new YT.Tab({ tabName: tabName }) @@ -48,7 +48,7 @@ class YourTeamTab { } else { $(`[data-tabname=${this.tabName}][data-target].active`).first().trigger("click"); } - + _ytTabInited.push(this.tabName); } @@ -56,22 +56,24 @@ class YourTeamTab { let clsObj = this; // Tab Item 按鈕 click - $(`[data-tabname=${this.tabName}][data-target]`).off("click").on("click", function (e) { + $(`[data-tabname=${this.tabName}]`).off("click").on("click", function (e) { let target = $(this).data("target"); let obj = this; - $(`[data-tabname=${clsObj.tabName}][data-target]:not([data-tabrole=child])`).removeClass("active"); + $(`[data-tabname=${clsObj.tabName}]:not([data-tabrole=child])`).removeClass("active"); $(obj).addClass("active"); // 觸發 yt:tab:change事件 $(obj).trigger("yt:tab:change"); - let tabName = $(target).data("tabname"); - if (tabName) { - // 找出該觸發對象 block - if ($(target).data("tabrole") == "child") { - $(obj).trigger("yt:tab:show"); - $(`[data-tabname='${tabName}'][data-tabrole='child']`).css("opacity", 0).hide(); - $(target).show().animate({ opacity: 1 }, 200, function () { - $(obj).trigger("yt:tab:shown"); - }); + if (target) { + let tabName = $(target).data("tabname"); + if (tabName) { + // 找出該觸發對象 block + if ($(target).data("tabrole") == "child") { + $(obj).trigger("yt:tab:show"); + $(`[data-tabname='${tabName}'][data-tabrole='child']`).css("opacity", 0).hide(); + $(target).show().animate({ opacity: 1 }, 200, function () { + $(obj).trigger("yt:tab:shown"); + }); + } } } }) diff --git a/Frontend/js/yourteam/yourteam.ajax.class_bak.js b/Frontend/js/yourteam/yourteam.ajax.class_bak.js new file mode 100644 index 0000000..95f70eb --- /dev/null +++ b/Frontend/js/yourteam/yourteam.ajax.class_bak.js @@ -0,0 +1,267 @@ +var YourTeam = YourTeam || {}; +/** + * This is a description of the Ajax constructor function. + * @class Ajax + * @classdesc This is a description of the Ajax class. + * @author Darren Chen @2021/02/06 + * @copyright Darren Chen @Your Team Co., Ltd. 2021 + */ +class Ajax { + /** + * constructor + * @constructor + * @param {String} apiUrl API URL. def="". + * @param {String} sendData the data object which you will be send. def= null. + * @param {Fcnction} successFunction successFunction. def=null.(use def successFunction) + * @param {Fcnction} errorFunction errorFunction. def=null.(use def successFunction) + * @param {String} type HTTP METHOD. def="GET". + * @param {Object} conType content type + * @param {String} dataType data format. def="JSON". + * @param {String} isAsync the api synchronization. def=false. + * @return {Object} this + */ + constructor(apiUrl = "", sendData = null, successFunction = null, errorFunction = null, type = "GET", isAsync = false, conType = this.contentType.Json, dataType = "JSON") { + this.conType = conType; + this.apiUrl = apiUrl; + this.isAsync = isAsync; + this.type = type; + this.dataType = dataType; + this.sendData = sendData; + this.extSuccessFunction = successFunction; + /*if (successFunction) this.successFunction = successFunction;*/ + if (errorFunction) this.errorFunction = errorFunction; + return this; + } + /** + * dataToString + * @description convert the data object to string + * @param {Object} data API URL. def="". + * @return {String} strJsonData + */ + dataToString = function (data) { + let strJsonData = data ? (data.Data ? JSON.stringify(data.Data) : null) : null; + return strJsonData; + } + /** + * beforeSendFunction + * @description beforeSendFunction + */ + beforeSendFunction = function (xhr) { + let token = localStorage.getItem("JWT-Authorization"); + xhr.setRequestHeader('Authorization', "Bearer " + token); + } + /** + * successFunction + * @description successFunction + * @param {Object} data the data object from the api return + * @return {Object} data + */ + successFunction = function (data, callback) { + debugger + if (data && data.unauthorized == 401) { + let href = location.href; + localStorage.removeItem("JWT-Authorization"); + if (href.indexOf("localhost:5966") == -1) { + location.href = "/login"; + } else { + location.href = "login.html"; + } + } + if (callback) { + callback(data); + } + return data; + } + /** + * errorFunction + * @description errorFunction + * @param {Object} xhr HTTP STATUS + * @param {Object} ajaxOptions the ajax option message + * @param {String} thrownError the error message + */ + errorFunction = function (xhr, ajaxOptions, thrownError) { + if (xhr.status != "201" && xhr.status != "204") { + console.log(xhr.status); + console.log(thrownError); + window.alert("執行失敗,請聯絡客服人員。"); + } else if (xhr.status == "401") { + window.alert("登入時間超時,請重新登入!"); + localStorage.removeItem("JWT-Authorization"); + location.href = "~/Login/Login"; + } + } + + /** + * completeFunction + * @description completeFunction + */ + completeFunction = function () { + + } + /** + * content type + * @description content type + */ + contentType = { + Json: 1, + FormData : 2 + } + /** + * enum + * @description enum + * @param {Object} eo object + * @return {Object} enum + */ + enums(eo) { + var enums = function () { }; + for (var key in eo) { + var enumObject = new enums(); + enums[key] = eo[key]; + } + return enums; + } + /** + * send + * @description send + * @param {Object} conType content type + * @param {Object} sendData send data + * @param {Function} successFunction the ajax success function + * @param {Function} errorFunction the ajax error function + * @return {Object} this + */ + send = function (conType = this.contentType.Json, sendData = null, successFunction = null, errorFunction = null) { + + //if (!CheckMultiSend(this.apiUrl, this.type, this.dataToString(this.sendData))) { //連點防呆 + // return false; + //} + if (sendData) { + this.sendData = sendData; + } + if (successFunction) { + this.successFunction = successFunction; + } + if (errorFunction) { + this.errorFunction = errorFunction; + } + if (conType === this.contentType.Json) { + $.ajax({ + url: this.apiUrl, + async: this.isAsync, + type: this.type, + dataType: this.dataType, + traditional: true, + contentType: "application/json; charset=utf-8", + data: this.dataToString(this.sendData), + + //cache: false, + //processData: false, + + beforeSend: this.beforeSendFunction, + success: (data) => this.successFunction(data, this.extSuccessFunction), + error: this.errorFunction, + complete: this.completeFunction, + statusCode: { + 201: (data) => this.successFunction(data, this.extSuccessFunction), + } + }); + } + else if (conType === this.contentType.FormData) { + $.ajax({ + url: this.apiUrl, + async: this.isAsync, + type: this.type, + dataType: this.dataType, + + traditional: true, + + contentType: false, + enctype: 'multipart/form-data', + data: this.sendData, + cache: false, + processData: false, + beforeSend: this.beforeSendFunction, + success: this.successFunction, + error: this.errorFunction, + complete: this.completeFunction + }); + alert(conType); + } + else { + console.error("the content type is null."); + } + return this; + } +} +YourTeam.Ajax = YourTeam.Ajax || Ajax; + +var ckeckMultiSendArr = []; +function CheckMultiSend(url, type, data) { + //根據 url type data + let text = String(url) + String(type); + if (type != "GET") { + if (ckeckMultiSendArr.indexOf(text) == -1) { + ckeckMultiSendArr.unshift(text); + let timer = setInterval(function () { + ckeckMultiSendArr.splice(0); + clearInterval(timer); + }, 500) + } else { + return false + } + } + return true; +} +//var YourTeamAjax = { +// apiUrl: "", +// isAsync: false, +// type: "GET", +// dataType: "JSON", +// sendData: null, +// dataToString: function (data) { +// let strJsonData = data ? (data.Data ? JSON.stringify(data.Data) : null) : null; +// return strJsonData; +// }, +// beforeSendFunction: function () { +// $.blockUI({ message: '

Loding...

' }); +// }, +// successFunction: function (data) { +// return data; +// }, +// errorFunction: function (xhr, ajaxOptions, thrownError) { +// if (xhr.status != "201") { +// console.log(xhr.status); +// console.log(thrownError); +// window.alert("執行失敗,請聯絡YourTeam客服人員。"); +// } +// }, +// completeFunction: function () { +// $.unblockUI(); +// }, +// send: function (sendData = null, successFunction = null, errorFunction = null) { +// if (sendData) { +// this.sendData = sendData; +// } +// if (successFunction) { +// this.successFunction = successFunction; +// } +// if (errorFunction) { +// this.errorFunction = errorFunction; +// } +// $.ajax({ +// url: this.apiUrl, +// async: this.isAsync, +// type: this.type, +// dataType: this.dataType, +// traditional: true, +// contentType: "application/json; charset=utf-8", +// data: this.dataToString(this.sendData), +// beforeSend: this.beforeSendFunction, +// success: this.successFunction, +// error: this.errorFunction, +// complete: this.completeFunction, +// statusCode: { +// 201: this.successFunction +// } +// }); +// } +//}; 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