let login = new Vue({
el: '#min',
data: {
loginData: {
"account": '',
"password": '',
"code": ''
},
Tips: {
"title": '',
"content": ''
},
Tips_open: false,
visibility: false,
// 主题 默认白色: white 黑色: black
theme: "white",
},
created() {
let theme = localStorage.getItem('theme')
if (theme) {
this.theme = theme
}
},
methods: {
login() {
const _this = this
account = this.loginData.account
password = this.loginData.password
code = this.loginData.code
if (!account) {
this.Tips.title = "请输入完整!"
this.Tips.content = "请输入账号!"
this.Tips_open = true
return false
} else if (!password) {
this.Tips.title = "请输入完整!"
this.Tips.content = "请输入密码!"
this.Tips_open = true
return false
} else if (!code) {
this.Tips.title = "请输入完整!"
this.Tips.content = "请输入验证码!"
this.Tips_open = true
return false
}
//ajax提交数据
$.ajax({
url: "/data/api/user/?type=login",
type: "POST",
data: {
"account": account,
"password": password,
"code": code,
},
dataType: "json",
error: function (error) {
_this.Tips.title = "登录失败"
_this.Tips.content = "网络异常"
_this.Tips_open = true
// 刷新验证码
$("#code_img").attr('src', src = '/data/api/code/?type=userLoginCode&' + Math.random());
_this.loginData.code = ''
console.log(error)
},
success: function (data) {
if (data.code == "0") {
_this.Tips.title = "登录成功"
_this.Tips.content = "登录成功,正在进行跳转..."
_this.Tips_open = true
setTimeout(function () {
location.href = "./";
}, 1e3)
} else {
_this.Tips.title = "登录失败"
_this.Tips.content = data.msg
_this.Tips_open = true
// 刷新验证码
$("#code_img").attr('src', src = '/data/api/code/?type=userLoginCode&' + Math.random());
_this.loginData.code = ''
}
}
})
},
// 切换主题
switch_theme() {
if (this.theme == 'white') {
this.theme = 'black'
localStorage.setItem('theme', 'black');
} else {
this.theme = 'white'
localStorage.setItem('theme', 'white');
}
}
},
mounted: function () {
//检测回车
const _this = this;
var isClick = true;
$(document).keypress(function (event) {
if (isClick) {
isClick = false;
var keynum = (event.keyCode ? event.keyCode : event.which);
if (keynum == '13') {
_this.login();
}
setTimeout(function () {
isClick = true;
}, 2000);
}
});
}
});