From 356eea459f8a8ee838e3760413f5677c102dcca4 Mon Sep 17 00:00:00 2001 From: dev01 Date: Fri, 23 Dec 2022 16:17:22 +0800 Subject: [PATCH] =?UTF-8?q?[Frontend][=E7=B3=BB=E7=B5=B1=E7=9B=A3=E6=8E=A7?= =?UTF-8?q?]=20=E5=B7=A6=E5=8F=B3=E9=82=8A=E5=8D=80=E5=A1=8A=E5=8B=95?= =?UTF-8?q?=E6=85=8B=E5=91=88=E7=8F=BE=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/_sysMonAll.html | 121 ++++++++++++++---- Frontend/js/forge/forgemodel.js | 13 +- .../ApiControllers/DeviceManageController.cs | 45 +++++++ FrontendWebApi/Models/Build.cs | 38 ++++++ 4 files changed, 183 insertions(+), 34 deletions(-) diff --git a/Frontend/_sysMonAll.html b/Frontend/_sysMonAll.html index 1b72987..fee24f1 100644 --- a/Frontend/_sysMonAll.html +++ b/Frontend/_sysMonAll.html @@ -2,29 +2,11 @@
-
-
-
- - -
-
- - -
-
- - -
-
- -
- - -
+
+
-
-
+
+
@@ -32,11 +14,56 @@ var allDevList = []; //全設備清單 $(function () { - getFloDevList(); - setLightColor(); - show3DModel(); + getBuildMenu((arr,data) => { + if (arr.indexOf(4) != -1) { + getFloDevList(); + setLightColor(); + } + if (arr.indexOf(5) != -1) { + show3DModel(data.urn_3D); + } + }); + + }) + // 從資料庫取得 drawing type 決定呈現畫面 + function getHtmlByType(type = 4, data = {}) { + let strHtml = ``; + switch (type) { + case 2: + strHtml = `
+ +
`; + break; + case 4: + strHtml = `
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
`; + break; + case 5: + strHtml = `
`; + break; + } + + return strHtml; + } + //baja 訂閱設備 function subDevice() { if (myBaja == null) { @@ -162,9 +189,47 @@ return strHtml; } - function show3DModel() { - launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dnNjb2RlX2ZvcmdlX3Rlc3QvJUUzJTgwJTkwQVJDJUUzJTgwJTkxQjFGXzIwMjJfMTJfMDQubndj", (viewer, nodeIds) => { + function getBuildMenu(callback = null) { + let url = baseApiUrl + "/api/Device/GetBuildMenu"; + let sendData = { + main_system_tag: pageAct.sysMainTag, + sub_system_tag: pageAct.sysSubTag, + building_tag: pageAct.buiTag, + }; + objSendData.Data = sendData; + ytAjax = new YourTeam.Ajax(url, objSendData, function (res) { + if (!res || res.code != "0000" || !res.data) { - }); + } else { + let leftData = {}, rightData = {}; + debugger + for (var key in res.data) { + if (key.startsWith("left")) { + leftData[key.split("left_")[1]] = res.data[key]; + } else if (key.startsWith("right")) { + rightData[key.split("right_")[1]] = res.data[key]; + } + } + + if (res.data.left_drawing != null) { + $("#leftDiv").html(getHtmlByType(res.data.left_drawing, leftData)); + } else { + $("#leftDiv").html(getHtmlByType(4, leftData)); + } + if (res.data.right_drawing != null) { + $("#rightDiv").html(getHtmlByType(res.data.right_drawing), rightData); + } else { + $("#rightDiv").html(getHtmlByType(4, rightData)); + } + + callback ? callback([res.data.left_drawing, res.data.right_drawing],res.data) : ""; + } + }, null, "POST").send(); + } + + function show3DModel(urn) { + launchViewer(urn, (viewer, nodeIds) => { + + },"[name=forgeViewer]"); } \ No newline at end of file diff --git a/Frontend/js/forge/forgemodel.js b/Frontend/js/forge/forgemodel.js index 1e226b7..dd52a24 100644 --- a/Frontend/js/forge/forgemodel.js +++ b/Frontend/js/forge/forgemodel.js @@ -45,25 +45,26 @@ let fragProxy; var targetFloorZ; var elevatorSpeed; +var selector = "#forgeViewer"; // for (let i = 0; i < devices.length; i++) { // sensorVals[i] = Math.random(); // } -function launchViewer(urn, callback) { +function launchViewer(urn, callback,selector = "#forgeViewer") { var options = { env: 'AutodeskProduction', getAccessToken: getForgeToken }; Autodesk.Viewing.Initializer(options, () => { - viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('forgeViewer')); + viewer = new Autodesk.Viewing.GuiViewer3D($(selector)[0]); //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) { + $(selector).on("autodesk:loaded", function (e,nodeIds) { callback ? callback(viewer, nodeIds) : ""; }) @@ -103,13 +104,13 @@ function launchViewerNoTools(urn, callback) { Autodesk.Viewing.Initializer(options, () => { //viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('forgeViewer')); - viewer = new Autodesk.Viewing.Viewer3D(document.getElementById('forgeViewer')); + viewer = new Autodesk.Viewing.Viewer3D($('forgeViewer')[0]); viewer.start(); var documentId = 'urn:' + urn; Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure); - $("#forgeViewer").on("autodesk:loaded", function (e, nodeIds) { + $(selector).on("autodesk:loaded", function (e, nodeIds) { callback ? callback(viewer, nodeIds) : ""; }) }); @@ -314,7 +315,7 @@ function onDocumentLoadSuccess(doc, eleOption) { console.log(instanceTree.nodeAccess) allDbIdsStr = Object.keys(instanceTree.nodeAccess.dbIdToIndex); getNodeIdByDbIds(allDbIdsStr, (nodeIds) => { - $("#forgeViewer").trigger("autodesk:loaded", nodeIds ); + $(selector).trigger("autodesk:loaded", nodeIds ); }); diff --git a/FrontendWebApi/ApiControllers/DeviceManageController.cs b/FrontendWebApi/ApiControllers/DeviceManageController.cs index 7675fbe..82c105b 100644 --- a/FrontendWebApi/ApiControllers/DeviceManageController.cs +++ b/FrontendWebApi/ApiControllers/DeviceManageController.cs @@ -119,6 +119,51 @@ namespace FrontendWebApi.ApiControllers return Ok(apiResult); } + /// + /// 系統監控電錶左右區塊呈現 + /// + /// + /// + [HttpPost] + [Route("api/Device/GetBuildMenu")] + public async Task>> GetBuildMenu([FromBody] FindDevice fd) + { + ApiResult apiResult = new ApiResult(jwt_str); + if (!jwtlife) + { + apiResult.Code = "5000"; + return BadRequest(apiResult); + } + else if (string.IsNullOrEmpty(fd.building_tag) || string.IsNullOrEmpty(fd.main_system_tag) || string.IsNullOrEmpty(fd.sub_system_tag)) + { + apiResult.Code = "0002"; + apiResult.Msg = "傳入參數不完整"; + return apiResult; + } + + try + { + var buiMenu = await frontendRepository.GetOneAsync( + @$"SELECT b.urn_3D,bm.* FROM building_menu bm + JOIN building b on b.building_tag = bm.building_tag + WHERE bm.building_tag = @building_tag AND bm.main_system_tag = @main_system_tag AND bm.sub_system_tag = @sub_system_tag", + new { @sub_system_tag = fd.sub_system_tag, @main_system_tag = fd.main_system_tag, @building_tag = fd.building_tag }); + + apiResult.Data = buiMenu; + + apiResult.Code = "0000"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + return Ok(apiResult); + } + return Ok(apiResult); + } + + /// /// 東別列表 /// diff --git a/FrontendWebApi/Models/Build.cs b/FrontendWebApi/Models/Build.cs index f4d85dc..16fe41b 100644 --- a/FrontendWebApi/Models/Build.cs +++ b/FrontendWebApi/Models/Build.cs @@ -228,4 +228,42 @@ namespace FrontendWebApi.Models public string Ip_address { get; set; } //監控主機 IP public byte FloorNum { get; set; } //樓層數量 } + + public class BuildBuildingMenu : BuildingMenu + { + public string urn_3D { get; set; } + } + + public class BuildingMenu + { + public string building_tag { get; set; } + public string main_system_tag { get; set; } + public string sub_system_tag { get; set; } + public short? left_drawing { get; set; } + public short? left_icon_click { get; set; } + public string left_icon_click_url { get; set; } + public int? left_icon_click_url_width { get; set; } + public int? left_icon_click_url_height { get; set; } + public short? left_planimetric_click { get; set; } + public string left_planimetric_floor_guid { get; set; } + public string left_system_url { get; set; } + public string left_riser_diagram_url { get; set; } + public short? right_drawing { get; set; } + public short? right_icon_click { get; set; } + public string right_icon_click_url { get; set; } + public int? right_icon_click_url_width { get; set; } + public int? right_icon_click_url_height { get; set; } + public short right_planimetric_click { get; set; } + public string right_planimetric_floor_guid { get; set; } + public string right_system_url { get; set; } + public string right_riser_diagram_url { get; set; } + public string device_building_tag { get; set; } + public string device_system_tag { get; set; } + public short? OpenTab { get; set; } + public short? is_link { get; set; } + public string created_by { get; set; } + public string created_at { get; set; } + public string updated_by { get; set; } + public string updated_at { get; set; } + } }