This repository has been archived on 2022-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
magic_box_server/html/static/js/user.js

74 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-09-25 14:57:35 +08:00
window.onload=function(){
$.post("/user/test.do", '', function(data, textStatus, req) {
var json=null;
console.log("登陆测试:"+data);
try {
json=JSON.parse(data);
} catch (e) {
// TODO: handle exception
console.log(e);
}
if(json==null||json.code!=100){
var title;
var content;
var url;
var reload=false;
switch (json.code) {
case 104:
title="请登录";
content="还没登陆哦~";
2020-01-10 17:59:09 +08:00
url="/index.html"
2018-09-25 14:57:35 +08:00
break;
case 105:
title="没有访问权限";
content="您无法访问当前页面";
2020-01-10 17:59:09 +08:00
url="home.html"
2018-09-25 14:57:35 +08:00
reload=true;
break;
default:
title="异常错误";
content="未知错误,请尝试重新登录";
2020-01-10 17:59:09 +08:00
url="/index.html"
2018-09-25 14:57:35 +08:00
break;
}
var layer = layui.layer;
layer.open({
title: title,
content: content,
cancel:function(index){
return false;
},
btn: ['知道了'],
btn1: function(data){
if(reload)
window.history.go(-1);
else
window.location.replace(url);
}
});
}else{
console.log('登陆成功');
}
})
$.post("/user/udata.do",function(data, textStatus, req){
var json=JSON.parse(data);
$("#uname").text(json.uname);
})
}
function logout(){
$.post("/user/logout.do", function(data, textStatus, req) {
var layer=layui.layer;
layer.open({
title: "退出",
content: "成功退出,欢迎下次光临",
cancel:function(index){
return false;
},
btn:['了解'],
btn1:function(){
2020-01-10 17:59:09 +08:00
window.location.replace("/index.html");
2018-09-25 14:57:35 +08:00
}
})
});
}