agent-backend/contracts/LicenceManager/html/main.js

79 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-09-26 04:49:24 +00:00
var loadStatus = function(){
executeCurrentContract("isOwner","",onIsOwner);
};
var onIsOwner = function(data){
if (data.result=="true"){
console.log("isOnwer!");
flushApplylist();
flushAcceptlist();
$(".ownerDIV").css("display","block");
}
else {
$("#applyForm").css("display","block");
refreshMyLicence();
}
};
var flushApplylist = function(){
executeCurrentContract("queryApply","",onApplyList);
};
var flushAcceptlist = function(){
executeCurrentContract("queryAccept","",onAcceptList);
};
var onApplyList = function(data){
global.applyList = JSON.parse(data.result);
fillApplyData(global.applyList);
};
var onAcceptList = function(data){
global.acceptList = JSON.parse(data.result);
var list = [];
for (var k in global.acceptList){
list.push(global.acceptList[k]);
}
global.acceptList = list;
fillAcceptList(list);
};
var apply = function(){
var arg = {
};
arg.uuid = $("#uuidInput")[0].value;
arg.remark = $("#remarkInput")[0].value;
executeCurrentContract("apply",JSON.stringify(arg),onApplyResult);
};
var onApplyResult = function(data){
console.log("申请结果:"+data.result);
};
var refreshMyLicence = function(){
var arg = $("#uuidInput")[0].value;
executeCurrentContract("request",arg,onRequestLicence);
};
var onRequestLicence = function(data){
if (data.result=="null"){
$("#licenceInput")[0].value="暂无授权";
}
else {
global.licenceData = JSON.parse(data.result);
$("#licenceInput")[0].value = global.licenceData.sig.signature;
var date = global.licenceData.expiredDate;
$("#licenceExpriedInput")[0].value = new Date(date / 1).toLocaleString();
$("#licenceNodeCountInput")[0].value = global.licenceData.nodeCount;
}
};
var updateSM2 = function(){
executeCurrentContract("init",$("#sm2Input")[0].value,function(data){
alert("更新状态:"+data.result);
});
};
var downloadMyLicence = function(){
var data = global.licenceData.licence;
var uri = "data:text/html,";
uri+=data;
var link = document.createElement("a");
link.download = "licence.txt";
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
};
loadStatus();