var loadNodesListMan = function(event) { console.log("loadNodesListMan"); listNodes(); listTrustUnits(); }; var listNodes = function(event) { console.log("listNodes"); setTimeout(function() { var param = {}; param.action = "listNodes"; param.pubKey = global.sm2Key.publicKey; global.wssocket.send(JSON.stringify(param)); }, 300); }; var listTrustUnits = function(event) { console.log("listTrustUnits"); setTimeout(function() { var param = {}; param.action = "listTrustUnits"; param.pubKey = global.sm2Key.publicKey; global.wssocket.send(JSON.stringify(param)); }, 300); }; var submitTrustUnitNodes = function(event) { const options = document.querySelector('#selectTrustUnitNodes').options; var list = []; for (let i = 0; i < options.length; i++) { // 如果该option被选中,则将它的value存入数组 if (options[i].selected) { var item = {}; item.nodeName = options[i].text; item.peerID = options[i].value; list.push(item); } } var param = {}; param.action = "createTrustUnit"; param.data = list; var name = $("#newUnitName")[0].value; if (name == undefined || name =="" ){ myToast("失败","请输入集群名称"); } param.msg = name; // console.log(JSON.stringify(param)); global.wssocket.send(JSON.stringify(param)); }; var onCreateTrustUnit = function(event) { myToast("Success", "创建可信集群成功") listTrustUnits(); }; // if ($("#nodesStatusPieDiv").css("height") == "0px") { var drawNodesStatusPie = function(id, obj) { // if ($("#nodesStatusPieDiv").css("height") == "0px") { if ($("#" + id).css("height") == "0px") { console.log("drawNodesStatusPie: ignore"); return; } $("#" + id) .html( "
"); var result = {}; if (obj.offline.length > obj.online.length) { result["Offline"] = obj.offline.length - obj.online.length; result["Online"] = obj.online.length; } else { result["Offline"] = 0; result["Online"] = obj.online.length; } global.result = result; var dataList = []; var valDataList = []; for ( var key in result) { dataList.push(key); var l = {}; l.name = key l.value = result[key]; valDataList.push(l); } var myChart = echarts.init($("#" + id + "Canv")[0], 'walden'); var option222 = { tooltip : { trigger : 'item', formatter : '{a}
{b}: {c} ({d}%)' }, legend : { orient : 'vertical', left : 10, data : dataList }, series : [ { name : '节点数目', type : 'pie', radius : [ '50%', '70%' ], avoidLabelOverlap : false, label : { normal : { show : false, position : 'center' }, emphasis : { show : true, textStyle : { fontSize : '15', fontWeight : 'bold' } } }, labelLine : { normal : { show : false } }, data : valDataList } ] }; myChart.setOption(option222); }; var onListNodes = function(obj) { // mainVue var len = 0; if (obj.offline != undefined) { mainVue.nodeCount = obj.offline.length; } if (obj.offline == undefined && obj.online != undefined && obj.online.length != undefined) { mainVue.nodeCount = obj.online.length; } var count = 0; if (obj.online != undefined) { for (var i = 0; i < obj.online.length; i++) { count += obj.online[i].contracts.length; } } mainVue.contractCount = count; // nodesStatusPieDiv // dashNodesStatusPieDiv drawNodesStatusPie("nodesStatusPieDiv", obj); drawNodesStatusPie("dashNodesStatusPieDiv", obj); // console.log(obj); if ($("#nodesTabDiv").css("height") == "0px") { console.log("nodesTabDiv: ignore"); return; } var dtLang = { "sProcessing" : "处理中...", "lengthMenu" : '显示 项结果', "sZeroRecords" : "没有匹配结果", "sInfo" : "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项", "sInfoEmpty" : "显示第 0 至 0 项结果,共 0 项", "sInfoFiltered" : "(由 _MAX_ 项结果过滤)", "sInfoPostFix" : "", "sSearch" : "搜索:", "sUrl" : "", "sEmptyTable" : "表中数据为空", "sLoadingRecords" : "载入中...", "sInfoThousands" : ",", "oPaginate" : { "sFirst" : "首页", "sPrevious" : "上页", "sNext" : "下页", "sLast" : "末页" }, "oAria" : { "sSortAscending" : ": 以升序排列此列", "sSortDescending" : ": 以降序排列此列" } }; var tableHead = ""; var tableTail = "
序号Name状态合约数目事件数目PeerIDUDPID公钥
"; var html = tableHead; var contractCount = 0; var eventCount = 0; $("#selectTrustUnitNodes").html(""); var x = document.getElementById("selectTrustUnitNodes"); x.options.length = 0; var i; for (i = 0; i < obj.online.length; i++) { html += ""; html += (i + 1); html += " "; html += obj.online[i].nodeName; html += " "; html += "Online"; html += " "; html += obj.online[i].contracts.length; html += " "; html += obj.online[i].events.length; html += " "; html += obj.online[i].peerID; html += " "; html += obj.online[i].udpID; html += " "; html += obj.online[i].pubKey; html += " "; if (obj.online[i].contracts!=undefined) contractCount += obj.online[i].contracts.length; eventCount += 0; var option = document.createElement("option"); option.text = obj.online[i].nodeName; option.value = obj.online[i].peerID; x.add(option);// new // Option(obj.online[i].pubKey,obj.online[i].pubKey),0); // option += ''; } // console.log("offline: ",obj.offline); for (i; i < obj.offline.length; i++) { html += ""; html += (i + 1); html += " "; html += obj.offline[i]; html += " "; html += "Offline"; html += " "; html += "-"; html += " "; html += "-"; html += " "; html += "-"; html += " "; html += "-"; html += " "; html += "-"; html += " "; } $("#selectTrustUnitNodes").selectpicker('refresh'); mainVue.contractCount = contractCount; mainVue.eventCount = eventCount; html += tableTail; $("#nodesTabDiv").html(html); $("#nodesTabDivTab").DataTable( { "language" : dtLang, "rowCallback" : function(row, data, displayNum, displayIndex, dataIndex) { }, "headerCallback" : function(thead, data, start, end, display) { $(thead).css("background", primaryColor); $(thead).css("color", "white"); $(thead).children().css("background", primaryColor); $(thead).children().css("color", "white"); }, scrollCollapse : false, paging : true, pageLength : 10, order : [ [ 0, 'desc' ] ], "columnDefs" : [ { "targets" : 1, "render" : function(data, type, row, meta) { if (data.length > 15) return "" + data.substring(0, 15) + " ..."; else return data; } }, { "targets" : 5, "render" : function(data, type, row, meta) { if (data.length > 10) return "" + data.substring(0, 10) + " ..."; else return data; } }, { "targets" : 7, "render" : function(data, type, row, meta) { if (data.length > 15) return "" + data.substring(0, 15) + " ..."; else return data; } } ] }); }; var onListTrustUnits = function(obj) { // mainVue mainVue.unitCount = obj.data.length; // console.log(obj); if ($("#trustNodesUnitTabDiv").css("height") == "0px") { console.log("trustNodesUnitTabDiv: ignore"); return; } var dtLang = { "sProcessing" : "处理中...", "lengthMenu" : '显示 项结果', "sZeroRecords" : "没有匹配结果", "sInfo" : "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项", "sInfoEmpty" : "显示第 0 至 0 项结果,共 0 项", "sInfoFiltered" : "(由 _MAX_ 项结果过滤)", "sInfoPostFix" : "", "sSearch" : "搜索:", "sUrl" : "", "sEmptyTable" : "表中数据为空", "sLoadingRecords" : "载入中...", "sInfoThousands" : ",", "oPaginate" : { "sFirst" : "首页", "sPrevious" : "上页", "sNext" : "下页", "sLast" : "末页" }, "oAria" : { "sSortAscending" : ": 以升序排列此列", "sSortDescending" : ": 以降序排列此列" } }; var tableHead = ""; var tableTail = "
序号ID创建者节点数目节点公钥
"; var html = tableHead; for (var i = 0; i < obj.data.length; i++) { var at_ = obj.data[i].key.indexOf("_"); var nodes = JSON.parse(obj.data[i].value); html += ""; html += (i + 1); html += " "; html += obj.data[i].key.substring(at_ + 1); html += " "; html += obj.data[i].key.substring(0, at_ - 1); html += " "; html += nodes.length; html += " "; html += JSON.stringify(nodes); html += " "; html += ""; html += " "; } html += tableTail; $("#trustNodesUnitTabDiv").html(html); $("#trustNodesUnitTabDivTab").DataTable( { "language" : dtLang, "rowCallback" : function(row, data, displayNum, displayIndex, dataIndex) { }, "headerCallback" : function(thead, data, start, end, display) { $(thead).css("background", primaryColor); $(thead).css("color", "white"); $(thead).children().css("background", primaryColor); $(thead).children().css("color", "white"); }, scrollCollapse : false, paging : true, pageLength : 10, order : [ [ 0, 'desc' ] ], "columnDefs" : [ { "targets" : 2, "render" : function(data, type, row, meta) { if (data.length > 15) return "" + data.substring(0, 15) + " ..."; else return data; } }, { "targets" : 4, "render" : function(data, type, row, meta) { if (data.length > 40) return "" + data.substring(0, 40) + " ..."; else return data; } } ] }); }; var deleteTrustUnit = function(data) { var param = {}; param.action = "deleteTrustUnit"; param.data = data; // console.log(JSON.stringify(param)); global.wssocket.send(JSON.stringify(param)); }; var onDeleteTrustUnit = function(event) { myToast("Success", "删除可信集群成功") listTrustUnits(); };