var layer;// 定义全局变量
|
(function () {
|
layui.use(['layer', 'form'], function () {
|
layer = layui.layer;
|
|
if(TEST_TAG){
|
renderRegisterInfo(950);
|
renderSn("CDECyDOrNl59kFU+vJIy6qRsgAUTt+xlWyA00t0IZlY=");
|
}else{
|
queryRegister();
|
|
querySn();
|
}
|
|
//弹出框操作
|
$('.prompt_sure,.prompt_cancel').click(function () {
|
$('.mask').addClass('hide');
|
});
|
});
|
}).call(this);
|
|
|
//注册授权
|
function register() {
|
var obj = {};
|
obj.add = $("#zcm").val();
|
// console.log("注册码:" + obj.add);
|
$.post("./cgi-bin/register/add_register", JSON.stringify(obj), function (data, status) {
|
// window.parent.notify(data.msg);
|
showMsg(data.msg);
|
if ("success" == data.code) {
|
queryRegister();
|
window.location.href = "./index.html";
|
}
|
}, "json");
|
}
|
|
|
//查询授权信息
|
function queryRegister() {
|
$.get("./cgi-bin/register/query_register", function (data, status) {
|
if ("success" == data.code) {
|
renderRegisterInfo(data.msg);
|
} else {
|
showMsg(data.msg);
|
// window.parent.notify("获取授权信息出错,请重新操作!!");
|
}
|
}, "json");
|
}
|
|
//获取机器码
|
function querySn() {
|
$.get("./cgi-bin/register/query_sn", function (data, status) {
|
if ("success" == status) {
|
renderSn(data.msg);
|
|
} else {
|
showMsg(data.msg);
|
// window.parent.notify("获取机器码出错,请重新操作!!");
|
}
|
}, "json");
|
}
|
|
|
//渲染授权信息
|
function renderRegisterInfo(data) {
|
var text = "";
|
if(data == 36500){
|
text = "已授权成功,该授权为永久授权";
|
}else{
|
text = "已授权成功,还可以使用"+ data +"天!";
|
}
|
|
$("#licenseInfo").text(text);
|
}
|
|
//渲染机械码
|
function renderSn(data) {
|
$("#mechanicsCode").val(data);
|
renderSnQrcode(data);
|
}
|
//将机械码渲染成二维码
|
function renderSnQrcode(data) {
|
data = toUtf8(data);
|
$('#qrcode').html('');
|
// $('#qrcode').qrcode(data);
|
$('#qrcode').qrcode({
|
render: 'table',
|
width: 170,
|
height: 170,
|
text: data
|
})
|
}
|
|
|
function showMsg(msg) {
|
$('.prompt_text').text(msg);
|
$('.mask').removeClass('hide');
|
};
|
|
function toUtf8(str) {
|
var out, i, len, c;
|
out = "";
|
len = str.length;
|
for (i = 0; i < len; i++) {
|
c = str.charCodeAt(i);
|
if ((c >= 0x0001) && (c <= 0x007F)) {
|
out += str.charAt(i);
|
} else if (c > 0x07FF) {
|
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
|
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
|
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
|
} else {
|
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
|
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
|
}
|
}
|
return out;
|
}
|
|