2024-07-17 17:28:54 +08:00
|
|
|
$(window).ready(function () {
|
|
|
|
|
let token = localStorage.getItem("token");
|
|
|
|
|
let url_path = window.location.pathname;
|
2024-07-18 15:10:33 +08:00
|
|
|
//登录验证
|
2024-07-17 17:28:54 +08:00
|
|
|
if (url_path.indexOf("login.html") == -1) {
|
|
|
|
|
if (token) {
|
2024-07-18 15:10:33 +08:00
|
|
|
getAjaxRequst("/api/Check/GetUserProfile", {}, function (res) {
|
2024-07-17 17:28:54 +08:00
|
|
|
if (res.code != 200) {
|
|
|
|
|
toastr.error("登录信息已过期,请重新登录");
|
|
|
|
|
localStorage.removeItem("token");
|
|
|
|
|
window.location.href = "login.html";
|
|
|
|
|
} else {
|
|
|
|
|
localStorage.setItem("account", res.result.account);
|
|
|
|
|
localStorage.setItem("name", res.result.name);
|
2024-07-24 08:50:23 +08:00
|
|
|
localStorage.setItem("userid", res.result.id);
|
2024-07-18 15:10:33 +08:00
|
|
|
$("#user-account").text(res.result.account);
|
2024-07-17 17:28:54 +08:00
|
|
|
$("#user-name").text(res.result.name);
|
2024-07-18 15:10:33 +08:00
|
|
|
if (res.result.account == "System") {
|
|
|
|
|
$("#admin-auth").removeClass("hidden");
|
|
|
|
|
}
|
2024-07-17 17:28:54 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
toastr.error("请先登录");
|
|
|
|
|
window.location.href = "login.html";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-18 15:10:33 +08:00
|
|
|
// 登录提交
|
2024-07-17 15:42:30 +08:00
|
|
|
$("#login-btn").click(function () {
|
|
|
|
|
let account = $("#login-mobile").val();
|
|
|
|
|
let password = $("#login-pwd").val();
|
|
|
|
|
if (account && password) {
|
|
|
|
|
postAjaxRequst(
|
|
|
|
|
"/api/Check/Login",
|
|
|
|
|
{ account: account, password: password, appKey: "openauth" },
|
|
|
|
|
function (res) {
|
|
|
|
|
if (res.code == 200) {
|
|
|
|
|
toastr.success(res.message);
|
|
|
|
|
localStorage.setItem("token", res.token);
|
2024-07-24 08:50:23 +08:00
|
|
|
|
2024-07-17 15:42:30 +08:00
|
|
|
setTimeout(function () {
|
|
|
|
|
window.location.href = "index.html";
|
|
|
|
|
}, 1000);
|
|
|
|
|
} else {
|
|
|
|
|
toastr.error(res.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
alert("Please fill all the fields");
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-07-18 15:10:33 +08:00
|
|
|
$("#logout").click(function () {
|
|
|
|
|
localStorage.clear();
|
|
|
|
|
window.location.href = "login.html";
|
|
|
|
|
});
|
2024-07-17 15:42:30 +08:00
|
|
|
});
|
2024-07-24 08:50:23 +08:00
|
|
|
//将json对象转换为url参数
|
|
|
|
|
function jsonToUrlParam(json, ignoreFields) {
|
|
|
|
|
return Object.keys(json)
|
|
|
|
|
.filter((key) => ignoreFields.indexOf(key) === -1)
|
|
|
|
|
.map((key) => key + "=" + json[key])
|
|
|
|
|
.join("&");
|
|
|
|
|
}
|