// 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 = `
` $('.search > .nav').append(html); }); $('.search > .nav').append(` `); } 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 = ` ` // // $('.search > .nav').append(html); // }); // $('.search > .nav').append(` `); // }); //} 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 += `