ibms-dome/Frontend/wwwroot/js/site.js
2022-10-14 16:08:54 +08:00

318 lines
12 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
// for details on configuring this project to bundle and minify static web assets.
// Write your JavaScript code.
//#region dataTable 預設
$(function () {
$.extend(true, $.fn.dataTable.defaults, {
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": true,
"language": {
"emptyTable": "無資料...",
"processing": "處理中...",
"loadingRecords": "載入中...",
"lengthMenu": "顯示 _MENU_ 項結果",
"zeroRecords": "沒有符合的結果",
"info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
"infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
"infoFiltered": "(從 _MAX_ 項結果中過濾)",
"infoPostFix": "",
"search": "搜尋:",
"paginate": {
"first": "第一頁",
"previous": "上一頁",
"next": "下一頁",
"last": "最後一頁"
},
"aria": {
"sortAscending": ": 升冪排列",
"sortDescending": ": 降冪排列"
}
}
});
//驗證是否為空白
jQuery.validator.addMethod("filterspace", function (value, element) {
var str = value;
var result = false;
if (str.length > 0) {
if ($.trim(str) != '') {
result = true;
}
else {
result = false;
}
}
return result;
}, "不可填入空白");
});
//#endregion
$(function () {
$.ajaxSetup({
//headers: {
// Authorization: 'Basic ' + localStorage.getItem('JWT-Authorization'),
// 'Access-Control-Allow-Origin': "*"
//},
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", 'Bearer ' + localStorage.getItem('JWT-Authorization'));
},
xhrFields: {
withCredentials: true
},
//contentType: "application/json; charset=utf-8",
//完成请求后触发。即在success或error触发后触发
complete: function (XMLHttpRequest, status) {
if ('400' == XMLHttpRequest.status) {
window.location.href = "/Login/Index";
}
},
//})
});
var top_menu;
function GetMenu(baseApiUrl) {
var url = baseApiUrl + 'api/GetMenu';
$.ajax({
type: "POST",
url: url,
data: null,
success: function (rel) {
//rel = JSON.stringify(rel);
if (rel.code != "0000") {
if (rel.code == "9999") {
toast_error(rel.msg);
}
else {
toast_warning(rel.msg);
}
return;
}
else {
top_menu = rel;
//console.log(top_menu);
$('.search > .nav').empty();
top_menu.data.forEach(function (building_item) {
var html = `<li class="nav-item hidden-sm-down mx-30">
<a class="nav-link icon wb-order" onclick="ChangeSideMenu('${building_item.building_guid}',this)" role="button">
<i class="fal fa-building"></i>
<span>${building_item.full_name}</span>
</a>
</li>`
$('.search > .nav').append(html);
});
$('.search > .nav').append(`<li class="nav-item hidden-sm-down mx-30">
<a class="nav-link icon wb-order" href="#" role="button">
<i class="fal fa-bell"></i>
<span> 緊急應變</span>
</a>
</li>`);
}
if (rel.str_jwt != null) {
localStorage.setItem('JWT-Authorization', rel.str_jwt);
}
},
error: function (xhr, textStatus, thrownError) {
alert(textStatus);
}
});
}
//var fileReader = new FileReader();
//let json = JSON.stringify();
//const blob = new Blob("response.json", { type: "application/json" });
//fileReader.readAsText(blob);
//fileReader.onload = function () {
// console.log("讀取結果:", this.result);//當讀取完成之後會回撥這個函式然後此時檔案的內容儲存到了result中。直接操作即可。
// console.log("讀取結果轉為JSON");
// let json = JSON.parse(this.result);
// console.log(json.name);
// console.log(json.age);
//}
function readTextFile(file, callback) {
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType("application/json");
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4 && rawFile.status == "200") {
callback(rawFile.responseText);
}
}
rawFile.send(null);
}
//usage:
//readTextFile("/js/response.json", function (text) {
// top_menu = JSON.parse(text);
// console.log(top_menu);
// $('.search > .nav').empty();
// top_menu.data.forEach(function (building_item) {
// var html = `<li class="nav-item hidden-sm-down mx-30">
// <a class="nav-link icon wb-order" onclick="ChangeSideMenu('${building_item.building_guid}')" role="button">
// <i class="fal fa-building"></i>
// <span>${building_item.full_name}</span>
// </a>
// </li>`
// // $('.search > .nav').append(html);
// });
// $('.search > .nav').append(`<li class="nav-item hidden-sm-down mx-30">
// <a class="nav-link icon wb-order" href="#" role="button">
// <i class="fal fa-bell"></i>
// <span> 緊急應變</span>
// </a>
// </li>`);
// });
//}
var selected_building;
function ChangeSideMenu(building_guid,e) {
selected_building = top_menu.data.filter(building => building.building_guid == building_guid)[0];
$('.search > .nav').find('.nav-item').removeClass('active');
$(e).parent('li').addClass("active");
$('#js-nav-menu').navigationDestroy();
$('#js-nav-menu').empty();
selected_building.main_system.forEach(function (main_system_item) {
var sub_html = '';
main_system_item.sub_system.forEach(function (sub_system_item) {
sub_html += `<li onclick="GetsubtoFloor('${sub_system_item.sub_system_guid}',this)">
<a href="javascript:void(0);" title="${sub_system_item.full_name}" data-filter-tags="utilities disabled item" >
<span class="nav-link-text" data-i18n="nav.utilities_disabled_item">${sub_system_item.full_name}</span>
</a>
</li>`;
});
var html = `<li onclick = "GetmaintoSub('${main_system_item.main_system_guid}')">
<a href="javascript:void(0);" title="${main_system_item.full_name}" data-filter-tags="category" style="background: #B28F01;">
<i class="fal fa-bolt"></i>
<span class="nav-link-text" data-i18n="nav.category">${main_system_item.full_name}</span>
</a>
<ul>
${sub_html}
</ul>
</li>`;
$('#js-nav-menu').append(html);
});
$('#js-nav-menu').append(`<li><hr class="mx-4" style="border-bottom: 1px solid #fff;"></li>
<li>
<a href="javascript:void(0);" title="告警記錄" data-filter-tags="blank page">
<i class="fal fa-alarm-snooze"></i>
<span class="nav-link-text" data-i18n="nav.blankpage">告警記錄</span>
</a>
</li>
<li>
<a href="javascript:void(0);" title="歷史數據" data-filter-tags="blank page">
<i class="fal fa-history"></i>
<span class="nav-link-text" data-i18n="nav.blankpage">歷史數據</span>
</a>
</li>
<li>
<a href="javascript:void(0);" title="報表下載" data-filter-tags="blank page">
<i class="fal fa-download"></i>
<span class="nav-link-text" data-i18n="nav.blankpage">報表下載</span>
</a>
</li>
<li>
<a href="javascript:void(0);" title="操作記錄" data-filter-tags="blank page">
<i class="fal fa-record-vinyl"></i>
<span class="nav-link-text" data-i18n="nav.blankpage">操作記錄</span>
</a>
</li>`);
$('#js-nav-menu').navigation({
accordion: myapp_config.navAccordion,
speed: myapp_config.navSpeed,
closedSign: '<em class="' + myapp_config.navClosedSign + '"></em>',
openedSign: '<em class="' + myapp_config.navOpenedSign + '"></em>',
initClass: myapp_config.navInitalized
});
}
var selected_mainsystem;
function GetmaintoSub(main) {
selected_mainsystem = selected_building.main_system.filter(mainsystem => mainsystem.main_system_guid == main)[0];
//console.log(selected_mainsystem);
}
var selected_subsystem;
function GetsubtoFloor(subsystem, e) {
$(e).parent().parent().parent().find('.active').removeClass('active');
$(e).parents('li').addClass('active');
$(e).addClass('active');
selected_subsystem = selected_mainsystem.sub_system.filter(sub_system => sub_system.sub_system_guid == subsystem)[0];
//console.log(selected_subsystem);
var floor_html = '';
$('#navbarColor02').empty();
if (selected_subsystem.drawing != 1) {
floor_html += `<li class="nav-item mr-3 active">
<a class="nav-link" href="#"><i class="fal fa-bookmark"></i> 總覽 <span class="sr-only">(current)</span></a>
</li>`;
}
if (selected_subsystem.floors.length > 0) {
if (selected_subsystem.planimetric_click == 1) {
selected_subsystem.floors.forEach(function (floor_item) {
if (selected_subsystem.drawing == 1) {
if (selected_subsystem.planimetric_floor_guid == floor_item.floor_guid) {
floor_html += `<li class="nav-item mr-3 active" >
<a class="nav-link" href="javascript:void(0);" ><i class="fal fa-bookmark"></i> ${floor_item.full_name}</a>
</li>`;
} else {
floor_html += `<li class="nav-item mr-3">
<a class="nav-link" href="javascript:void(0);"><i class="fal fa-bookmark"></i> ${floor_item.full_name}</a>
</li>`;
}
} else {
floor_html += `<li class="nav-item mr-3">
<a class="nav-link" href="javascript:void(0);" onclick="GetFloortoDrawing()"><i class="fal fa-bookmark"></i> ${floor_item.full_name}</a>
</li>`;
}
})
}
}
var htnl = `
<ul class="navbar-nav mr-auto pl-4" id="navbarColor02_child">
${floor_html}
</ul>`;
$('#navbarColor02').append(htnl);
}
function GetFloortoDrawing(floorguid,e) {
}