From 43b79ffffca8a5b2e359aba7cc1a5250d843b6a6 Mon Sep 17 00:00:00 2001 From: "Frank.R.Wu" Date: Tue, 15 Jun 2021 21:52:53 +0800 Subject: [PATCH] merge: merge changes in BaaS --- BaaSClient.html | 173 ++++++++++++++++++ js/bdwareclient.js | 87 +++++---- js/commonutil.js | 436 +++++++++++++++++++++++---------------------- 3 files changed, 453 insertions(+), 243 deletions(-) create mode 100644 BaaSClient.html diff --git a/BaaSClient.html b/BaaSClient.html new file mode 100644 index 0000000..804799e --- /dev/null +++ b/BaaSClient.html @@ -0,0 +1,173 @@ + + + + +数瑞客户端 + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/js/bdwareclient.js b/js/bdwareclient.js index 969f652..70cff1d 100644 --- a/js/bdwareclient.js +++ b/js/bdwareclient.js @@ -248,14 +248,14 @@ function showContractResult(requestID) { result = data; $("#statusSpan")[0].innerHTML = result.status; $("#timeSpan")[0].innerHTML = "调用耗时:" + data.executeTime + "(ms)"; - if (result.result instanceof Object){ - $("#responseArea")[0].value = JSON.stringify(result.result); - $("#timeSpan")[0].innerHTML +="
JSON格式"; - }else{ - $("#timeSpan")[0].innerHTML +="
字符串格式"; - $("#responseArea")[0].value = result.result; + if (result.result instanceof Object) { + $("#responseArea")[0].value = JSON.stringify(result.result); + $("#timeSpan")[0].innerHTML += "
JSON格式"; + } else { + $("#timeSpan")[0].innerHTML += "
字符串格式"; + $("#responseArea")[0].value = result.result; } - if (global.responseCollector[requestID].hashCode!=undefined) + if (global.responseCollector[requestID].hashCode != undefined) $("#hashDisplayDiv").html("溯源指纹:" + global.responseCollector[requestID].hashCode); } @@ -344,7 +344,7 @@ function onGetNodeSessionID(data) { global.session = data.session; const loginParam = { pubKey: global.sm2Key.publicKey, - signature: sm2.doSignature(global.session, global.sm2Key.privateKey,{hash:true,der:true}), + signature: sm2.doSignature(global.session, global.sm2Key.privateKey, {hash: true, der: true}), action: "login" }; global.wssocket.send(JSON.stringify(loginParam)); @@ -450,8 +450,8 @@ function triggerExecuteCurrentContract() { return; } var funNode; - for(var i = 0;i < global.currentContract.exportedFunctions.length;i++){ - if(global.currentContract.exportedFunctions[i].functionName == funPos){ + for (var i = 0; i < global.currentContract.exportedFunctions.length; i++) { + if (global.currentContract.exportedFunctions[i].functionName == funPos) { funNode = global.currentContract.exportedFunctions[i]; break; } @@ -466,7 +466,7 @@ function triggerExecuteCurrentContract() { + "&pubkey=" + global.sm2Key.publicKey + "&signature="; const toSign = global.currentContract.name + "|" + funNode.functionName + "|" + argInput[0].value + "|" + global.sm2Key.publicKey; - const signature = sm2.doSignature(toSign, global.sm2Key.privateKey,{hash:true,der:true}); + const signature = sm2.doSignature(toSign, global.sm2Key.privateKey, {hash: true, der: true}); let urlPre = $("#urlInput")[0].value; if (urlPre.startsWith("ws")) { urlPre = urlPre.replace("ws", "http"); @@ -480,8 +480,8 @@ function showDescription() { console.log(funPos); console.log(global.currentContract.exportedFunctions); var funNode; - for(var i = 0;i < global.currentContract.exportedFunctions.length;i++){ - if(global.currentContract.exportedFunctions[i].functionName == funPos){ + for (var i = 0; i < global.currentContract.exportedFunctions.length; i++) { + if (global.currentContract.exportedFunctions[i].functionName == funPos) { funNode = global.currentContract.exportedFunctions[i]; break; } @@ -496,8 +496,8 @@ function showDescription() { } function fillResultInternal(result, data) { - if (global.responseCollector[data.responseID]==undefined){ - global.responseCollector[data.responseID]=[]; + if (global.responseCollector[data.responseID] == undefined) { + global.responseCollector[data.responseID] = []; const reqIDSpan = $("#reqIDSpan"); reqIDSpan.append(""); reqIDSpan[0].value = data.responseID; @@ -505,11 +505,11 @@ function fillResultInternal(result, data) { global.responseCollector[data.responseID].push(data); $("#statusSpan")[0].innerHTML = result.status; $("#timeSpan")[0].innerHTML = "调用耗时:" + data.executeTime + "(ms)"; - if (result.result instanceof Object){ - $("#responseArea")[0].value = JSON.stringify(result.result); - $("#timeSpan")[0].innerHTML +="
JSON格式"; - }else{ - $("#timeSpan")[0].innerHTML +="
字符串格式"; + if (result.result instanceof Object) { + $("#responseArea")[0].value = JSON.stringify(result.result); + $("#timeSpan")[0].innerHTML += "
JSON格式"; + } else { + $("#timeSpan")[0].innerHTML += "
字符串格式"; $("#responseArea")[0].value = result.result; } } @@ -531,7 +531,7 @@ function loadMain(data) { global.scriptList = []; global.scriptOrder = 0; console.log("listSize:" + scriptList.length); - for (var i=0;i"+order); - headerVue.shortName = this.sm2KeyList[order].title; - this.selectedSM2Key = order; - this.sm2KeyStr = this.sm2KeyList[order].sm2Key; - global.sm2Key = JSON.parse(this.sm2KeyStr); - localStorage.setItem("PrivKey", this.sm2KeyStr); - getSession(); - },deletePubkey:function(event){ - var order = this.selectedSM2Key; - var obj = this.sm2KeyList[order]; - if (this.sm2KeyList.length==1){ - alert("最后一对密钥不可以删除"); - return; - } - var newList = []; - for (var i=0;i=newList.length){ - order --; - } - console.log("after delete, size:"+newList.length+" order:"+order); - localStorage.setItem("PrivKeyList", JSON.stringify(newList)); - headerVue.shortName = this.sm2KeyList[order].title; - this.selectedSM2Key = order + ""; - this.sm2KeyStr = this.sm2KeyList[order].sm2Key; - global.sm2Key = JSON.parse(this.sm2KeyStr); - localStorage.setItem("PrivKey", this.sm2KeyStr); - getSession(); - },exportPubkey : function(event){ - var uri = "data:text/html,"; - uri+=localStorage.getItem("PrivKeyList"); - var link = document.createElement("a"); - link.download = "sm2keyList.json"; - link.href = uri; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - delete link; - - } + }, changeSM2Key: function (event) { + var order = event.target.value; // 获取option对应的value值 + if (order == undefined) + return; + console.log("changeSM2Key, -->" + order); + headerVue.shortName = this.sm2KeyList[order].title; + this.selectedSM2Key = order; + this.sm2KeyStr = this.sm2KeyList[order].sm2Key; + global.sm2Key = JSON.parse(this.sm2KeyStr); + localStorage.setItem("PrivKey", this.sm2KeyStr); + getSession(); + }, deletePubkey: function (event) { + var order = this.selectedSM2Key; + var obj = this.sm2KeyList[order]; + if (this.sm2KeyList.length == 1) { + alert("最后一对密钥不可以删除"); + return; + } + var newList = []; + for (var i = 0; i < order; i++) { + newList.push(this.sm2KeyList[i]); + } + ; + for (var i = order / 1 + 1; i < this.sm2KeyList.length; i++) { + newList.push(this.sm2KeyList[i]); + } + ; + this.sm2KeyList = newList; + for (var i = 0; i < newList.length; i++) { + newList[i].id = i; + } + if (order >= newList.length) { + order--; + } + console.log("after delete, size:" + newList.length + " order:" + order); + localStorage.setItem("PrivKeyList", JSON.stringify(newList)); + headerVue.shortName = this.sm2KeyList[order].title; + this.selectedSM2Key = order + ""; + this.sm2KeyStr = this.sm2KeyList[order].sm2Key; + global.sm2Key = JSON.parse(this.sm2KeyStr); + localStorage.setItem("PrivKey", this.sm2KeyStr); + getSession(); + }, exportPubkey: function (event) { + var uri = "data:text/html,"; + uri += localStorage.getItem("PrivKeyList"); + var link = document.createElement("a"); + link.download = "sm2keyList.json"; + link.href = uri; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + delete link; - } - }); + } - mainVue = new Vue({ - el : "#main", - data : { - licenceDueDate : "已过期", - licenceNodes : 0, - offlineLicence : undefined, - licenceRemark : undefined, - userCount:".", - contractCount:".", - nodeCount:".", - eventCount:".", - unitCount:".", - pubDialogVue:{}, - projects:[], - contracts:[], - contractFunctions:[], - openedFiles:[{ - isDir: false, - val: "Please Checkout code from left side!", - path: "Hello", - name: "Hello" - }] + } + }); + + mainVue = new Vue({ + el: "#main", + data: { + licenceDueDate: "已过期", + licenceNodes: 0, + offlineLicence: undefined, + licenceRemark: undefined, + userCount: ".", + contractCount: ".", + nodeCount: ".", + eventCount: ".", + unitCount: ".", + pubDialogVue: {}, + projects: [], + contracts: [], + contractFunctions: [], + openedFiles: [{ + isDir: false, + val: "Please Checkout code from left side!", + path: "Hello", + name: "Hello" + }] + + } + }); - } - }); - }; // ======Vue done -var initGlobal = function() { - if (window.global==undefined){ - window.global = {}; - } - global.sm2Key = localStorage.getItem("PrivKey"); - global.result = ""; - if (global.sm2Key == undefined || global.sm2Key == null - || global.sm2Key.length < 100) { - generate(); - } else { - global.sm2Key = JSON.parse(global.sm2Key); - } - headerVue.shortName = global.sm2Key.publicKey.substr(0, 5); - pubkeyDialogVue.sm2KeyStr = JSON.stringify(global.sm2Key); - mainVue.pubDialogVue = pubkeyDialogVue; - var keyListStr = localStorage.getItem("PrivKeyList"); - if (keyListStr==undefined){ - var keyObj = {}; - keyObj.id = 0; - keyObj.title = headerVue.shortName; - keyObj.sm2Key = pubkeyDialogVue.sm2KeyStr; - pubkeyDialogVue.sm2KeyList = []; - pubkeyDialogVue.sm2KeyList.push(keyObj); - pubkeyDialogVue.selectedSM2Key = 0; - // mainVue.sm2KeyList = pubkeyDialogVue.sm2KeyList; - // mainVue.selectedSM2Key = 0; - } else{ - pubkeyDialogVue.sm2KeyList = JSON.parse(keyListStr); - pubkeyDialogVue.selectedSM2Key = -1; - for (var i=0;i