(function () {
|
function ajaxJson(options) {
|
$.ajax(options);
|
}
|
|
new Vue({
|
el: "#app",
|
data: function () {
|
return {
|
localeTick: 0,
|
localeOptions: [],
|
currentLocale: "zh-CN",
|
loginLoading: false,
|
toolsDialogVisible: false,
|
textDialogVisible: false,
|
uploadDialogVisible: false,
|
licenseBase64: "",
|
titleClickCount: 0,
|
titleClickTimer: null,
|
loginForm: {
|
mobile: "",
|
password: ""
|
},
|
textDialog: {
|
title: "",
|
label: "",
|
text: "",
|
tip: ""
|
},
|
loginRules: {
|
mobile: [
|
{ required: true, message: "请输入账号", trigger: "blur" }
|
],
|
password: [
|
{ required: true, message: "请输入密码", trigger: "blur" }
|
]
|
}
|
};
|
},
|
created: function () {
|
this.initLanguageSwitch();
|
},
|
methods: {
|
text: function (key, fallback) {
|
var localeTick = this.localeTick;
|
void localeTick;
|
if (window.WCS_I18N && typeof window.WCS_I18N.t === "function") {
|
return window.WCS_I18N.t(key);
|
}
|
return fallback || key;
|
},
|
initLanguageSwitch: function () {
|
var vm = this;
|
if (!window.WCS_I18N || typeof window.WCS_I18N.onReady !== "function") {
|
return;
|
}
|
window.WCS_I18N.onReady(function (i18n) {
|
vm.localeOptions = i18n.getLocaleOptions();
|
vm.currentLocale = i18n.getLocale();
|
document.title = i18n.t("login.title");
|
vm.localeTick++;
|
});
|
},
|
handleLocaleChange: function () {
|
var vm = this;
|
if (!window.WCS_I18N || typeof window.WCS_I18N.setLocale !== "function") {
|
return;
|
}
|
window.WCS_I18N.setLocale(vm.currentLocale);
|
setTimeout(function () {
|
document.title = vm.text("login.title", "系统登录");
|
vm.localeTick++;
|
}, 0);
|
},
|
handleTitleClick: function () {
|
var vm = this;
|
vm.titleClickCount++;
|
if (vm.titleClickTimer) {
|
clearTimeout(vm.titleClickTimer);
|
}
|
if (vm.titleClickCount >= 3) {
|
vm.titleClickCount = 0;
|
vm.toolsDialogVisible = true;
|
return;
|
}
|
vm.titleClickTimer = setTimeout(function () {
|
vm.titleClickCount = 0;
|
}, 500);
|
},
|
handleLogin: function () {
|
var vm = this;
|
vm.$refs.loginForm.validate(function (valid) {
|
if (!valid) {
|
return false;
|
}
|
vm.submitLogin();
|
return true;
|
});
|
},
|
submitLogin: function () {
|
var vm = this;
|
vm.loginLoading = true;
|
ajaxJson({
|
url: baseUrl + "/login.action",
|
data: {
|
mobile: vm.loginForm.mobile,
|
password: hex_md5(vm.loginForm.password)
|
},
|
method: "POST",
|
success: function (res) {
|
if (Number(res.code) === 200) {
|
localStorage.setItem("token", res.data.token);
|
localStorage.setItem("username", res.data.username);
|
window.location.href = "index.html";
|
return;
|
}
|
vm.$message.error(res.msg || "登录失败");
|
},
|
error: function () {
|
vm.$message.error("登录失败");
|
},
|
complete: function () {
|
vm.loginLoading = false;
|
}
|
});
|
},
|
openTextDialog: function (title, label, text, tip) {
|
var pretty = "";
|
try {
|
pretty = typeof text === "string" ? text : JSON.stringify(text, null, 2);
|
} catch (e) {
|
pretty = String(text || "");
|
}
|
this.textDialog = {
|
title: title,
|
label: label,
|
text: pretty,
|
tip: tip || ""
|
};
|
this.textDialogVisible = true;
|
},
|
fallbackCopy: function (text) {
|
try {
|
var textarea = document.createElement("textarea");
|
textarea.value = text;
|
textarea.style.position = "fixed";
|
textarea.style.opacity = "0";
|
document.body.appendChild(textarea);
|
textarea.select();
|
document.execCommand("copy");
|
document.body.removeChild(textarea);
|
this.$message.success("已复制到剪贴板");
|
} catch (err) {
|
this.$message.error("复制失败");
|
}
|
},
|
copyText: function () {
|
var vm = this;
|
var text = vm.textDialog.text || "";
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
navigator.clipboard.writeText(text).then(function () {
|
vm.$message.success("已复制到剪贴板");
|
}).catch(function () {
|
vm.fallbackCopy(text);
|
});
|
return;
|
}
|
vm.fallbackCopy(text);
|
},
|
requestCode: function () {
|
var vm = this;
|
ajaxJson({
|
url: baseUrl + "/license/getRequestCode",
|
method: "GET",
|
success: function (res) {
|
if (Number(res.code) === 200) {
|
vm.openTextDialog("获取请求码", "请求码", res.msg || "", "请求码中已包含项目名称,直接发给许可证服务端即可。");
|
return;
|
}
|
vm.$message.error(res.msg || "获取请求码失败");
|
},
|
error: function () {
|
vm.$message.error("获取请求码失败");
|
}
|
});
|
},
|
getServerInfo: function () {
|
var vm = this;
|
ajaxJson({
|
url: baseUrl + "/license/getServerInfos",
|
method: "GET",
|
success: function (res) {
|
vm.openTextDialog("获取系统配置", "系统配置信息", res, "老项目仍可继续使用这份硬件信息 JSON 申请许可证。");
|
},
|
error: function () {
|
vm.$message.error("获取系统配置信息失败");
|
}
|
});
|
},
|
submitLicense: function () {
|
var vm = this;
|
if (!vm.licenseBase64) {
|
vm.$message.warning("许可证内容不能为空");
|
return;
|
}
|
ajaxJson({
|
url: baseUrl + "/license/updateLicense",
|
method: "POST",
|
contentType: "application/json;charset=UTF-8",
|
data: JSON.stringify({ license: vm.licenseBase64 }),
|
success: function (res) {
|
if (Number(res.code) === 200) {
|
vm.uploadDialogVisible = false;
|
vm.licenseBase64 = "";
|
vm.$message.success("许可证更新成功");
|
return;
|
}
|
vm.$message.error(res.msg || "许可证更新失败");
|
},
|
error: function () {
|
vm.$message.error("许可证录入失败");
|
}
|
});
|
},
|
activateLicense: function () {
|
var vm = this;
|
vm.$confirm("确定执行一键激活吗?", "提示", {
|
type: "warning",
|
confirmButtonText: "确定",
|
cancelButtonText: "取消"
|
}).then(function () {
|
ajaxJson({
|
url: baseUrl + "/license/activate",
|
method: "POST",
|
success: function (res) {
|
if (Number(res.code) === 200) {
|
vm.$message.success("激活成功");
|
return;
|
}
|
vm.$message.error(res.msg || "激活失败");
|
},
|
error: function () {
|
vm.$message.error("激活失败");
|
}
|
});
|
}).catch(function () {
|
});
|
},
|
getProjectName: function () {
|
var vm = this;
|
ajaxJson({
|
url: baseUrl + "/license/getProjectName",
|
method: "GET",
|
success: function (res) {
|
if (Number(res.code) === 200) {
|
vm.$alert(res.msg || "", "项目名称", {
|
confirmButtonText: "确定"
|
});
|
return;
|
}
|
vm.$message.error(res.msg || "获取项目名称失败");
|
},
|
error: function () {
|
vm.$message.error("获取项目名称失败");
|
}
|
});
|
}
|
}
|
});
|
})();
|