76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
function Login() {
|
|
this.captchaUrl = "/captcha"
|
|
this.userName = ""
|
|
this.password = ""
|
|
this.captcha = ""
|
|
}
|
|
|
|
Login.prototype.RefreshCaptcha = function () {
|
|
let self = this;
|
|
$("#captcha-img").click(function () {
|
|
let timestamp = new Date().getTime();
|
|
self.captchaUrl = "/captcha" + "?t=" + timestamp
|
|
$("#captcha-img").attr('src', self.captchaUrl); //显示图片
|
|
})
|
|
}
|
|
//
|
|
Login.prototype.LoginClick = function () {
|
|
let self = this;
|
|
let csrfToken = document.getElementsByName("gorilla.csrf.Token")[0].value
|
|
$("#login-btn").click(function (e) {
|
|
e.preventDefault();
|
|
// 获取参数
|
|
let username = $("#login-username").val()
|
|
let password = $("#login-password").val()
|
|
let captcha = $("#login-captcha").val()
|
|
|
|
$.ajax({
|
|
url: '/login',
|
|
method: 'POST',
|
|
data: JSON.stringify({
|
|
username: username,
|
|
password: password,
|
|
captcha: captcha
|
|
}),
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
"X-CSRF-Token": csrfToken
|
|
},
|
|
success: function (result) {
|
|
if (result.status === 200) {
|
|
Alert.AlertSuccessToast(result.message)
|
|
window.location.href = "/"
|
|
} else {
|
|
Alert.AlertError(result.message)
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
Alert.AlertError("服务器内部错误")
|
|
console.log('请求失败:', error);
|
|
}
|
|
});
|
|
})
|
|
}
|
|
|
|
|
|
Login.prototype.run = function () {
|
|
this.RefreshCaptcha()
|
|
this.LoginClick()
|
|
}
|
|
|
|
// 构造执行入口
|
|
$(function () {
|
|
feather.replace()
|
|
// 模板过滤方法
|
|
// if (window.template) {
|
|
// template.defaults.imports.domainSubstring = function (dateValue) {
|
|
// if (dateValue.length > 40 ) {
|
|
// return dateValue.substring(0, 37) + "..."
|
|
// } else {
|
|
// return dateValue
|
|
// }
|
|
// }
|
|
// }
|
|
let login = new Login()
|
|
login.run()
|
|
}) |