var imgurl = "http://192.168.0.21/file/";
function CheckLogin() {
$.post(baseurl + 'Account/CheckLogin', 'returnurl=' + location.href, function (res) {
$('#LoginArea').html(res);
});
}
//function Subcribe() {
// $.post(baseurl + 'Account/Subcribe', 'returnurl=' + location.href, function (res) {
// if (res == "-1") {
// //未登录
// } else if (res == "-2") {
// //未关注
// } else {
// //已关注 已登录
// }
// //$('#LoginArea').html(res);
// });
//}
function Logout() {
$.get('/Account/Logout', function () {
location.reload();
});
}
//搜索公共方法
var searcharea = $('#SearchArea');
function Search() {
var url = location.href;
var m = url.indexOf('?')
if (m > 0) {
url = url.substring(0, m)
}
searcharea.find('select[name],input[name]').each(function () {
var obj = $(this);
var val = obj.val();
var prompt = obj.attr('placeholder');
if (val != 0 && (!prompt || (prompt && prompt != val)))
url += (url.indexOf('?') > 0 ? '&' : '?') + obj.attr('name') + '=' + encodeURI(val);
});
searcharea.find('a.ac').each(function () {
var obj = $(this);
var con = obj.attr('url');
var con = obj.attr('url');
if (con && con.indexOf('=') > -1) {
url += (url.indexOf('?') > 0 ? '&' : '?') + con;
}
});
location.href = url;
}
$(function () {
if (searcharea.length > 0) {
$.Search();
if (typeof (layui) !== 'undefined') {
layui.use(["form"], function () {
var form = layui.form;
form.render();
form.on("select()", function () {
Search();
});
});
}
}
});
var returnurl = Request('returnurl');
var layerLogin = 0;
$.ajaxSetup({
error: function (jqXHR, textStatus, errorThrown) {
posting = false;
switch (jqXHR.status) {
case (404):
layer.msg('服务器请求地址不存在,请联系客服!');
break;
case (500):
layer.msg('服务器请求繁忙,请稍后再试!');
break;
case (401):
ShowLogin();
break;
case (403):
location.href = '../../../Account/AccessDenied';
break;
case (408):
if (iframe.html().length < 1) {
iframe.append('
连接请求超时,请稍后再试!
');
} else {
layer.msg('连接请求超时,请稍后再试!');
}
break;
case (0):
if (typeof (layer) != 'undefined') {
ShowLogin();
} else {
alert('会话已过期,请重新登录');
location.href = baseurl + 'Account/Login?returnurl=' + location.href;
}
}
}
});
//登录检测
var lkLogin = $('#lkLogin');
//$('body').on('click', 'a.loginlink', function (e) {
// e.preventDefault();
// var $this = $(this);
// $.get(baseurl + 'Account/IsLogin', 'n=' + Math.random(), function (res) {
// if (res) {
// var target = $this.attr('target');
// var href = $this.attr('href');
// switch (target) {
// case '_blank':
// lkLogin.attr('href', href).attr('_blank', target);
// document.getElementById('lkLogin').click();
// break;
// default:
// location.href = href;
// }
// } else {
// var fun = $this.attr('data-fun');
// ShowLogin(fun);
// }
// });
//});
$('body').on('click', 'a.loginlink', function (e) {
e.preventDefault();
var $this = $(this);
$.get(baseurl + 'Account/Subcribe', 'n=' + Math.random(), function (res) {
if (res) {
if (res == "-1") {
//未登录
var fun = $this.attr('data-fun');
ShowLogin(fun);
}
//else if (res == "-2") {
// //未关注
// var fun = $this.attr('data-fun');
// ShowSubcribe(fun);
//}
else {
//已关注 已登录
var target = $this.attr('target');
var href = $this.attr('href');
switch (target) {
case '_blank':
lkLogin.attr('href', href).attr('_blank', target);
document.getElementById('lkLogin').click();
break;
default:
location.href = href;
}
}
} else {
var fun = $this.attr('data-fun');
ShowLogin(fun);
}
});
});
//显示登录页面
function ShowLogin(fun) {
layer.confirm('当前操作需要登录,是否继续?', function (index, layero) {
layer.close(index);
layerLogin = layer.open({
type: 2,
title: '',
content: baseurl + 'Account/Login?ReturnUrl=' + location.href,
area: ['750px', '450px'],
end: function () {
loading = false;
if ($('#LoginArea').length > 0) {
CheckLogin();
if (fun) {
eval(fun);
}
}
},
resize: false,
skin: "login-style"
});
});
}
//显示关注页面
function ShowSubcribe(fun) {
layer.confirm('当前操作需要关注,是否继续?', function (index, layero) {
layer.close(index);
layerLogin = layer.open({
type: 2,
title: '',
content: baseurl + 'Account/Login?ReturnUrl=' + location.href + "&status=2",
area: ['400px', '450px'],
end: function () {
loading = false;
if ($('#LoginArea').length > 0) {
CheckLogin();
if (fun) {
eval(fun);
}
}
},
resize: false,
skin: "login-style"
});
});
}
var index = layerLogin;
//扫码登录
function ScanLogin(status) {
if (status == "2") {
layerLogin = layer.open({
type: 2,
title: '',
content: baseurl + 'Account/Login?ReturnUrl=' + location.href + "&status=" + status,
area: ['400px', '450px'],
end: function () {
//loading = false;
if ($('#LoginArea').length > 0) {
//CLogin();
if (fun) {
eval(fun);
}
}
},
resize: false,
skin: "login-style"
});
} else {
layerLogin = layer.open({
type: 2,
title: '',
content: baseurl + 'Account/Login?ReturnUrl=' + location.href + "&status=" + status,
area: ['750px', '450px'],
end: function () {
//loading = false;
if ($('#LoginArea').length > 0) {
//CLogin();
if (fun) {
eval(fun);
}
}
},
resize: false,
skin: "login-style"
});
}
//layer.confirm('当前操作需要登录,是否继续?', function (index, layero) {
// layer.close(index);
//var status = "2";
//status 2 表示已经进行登陆操作 但是未曾关注
//});
}
function Logout() {
layer.confirm("确定要退出吗?", { icon: 3, title: '提示' },
function (index) {//确定回调
layer.close(index);
$.get('/Account/Logout', function () {
location.reload();
});
}, function (index) {//取消回调
layer.close(index);
}
);
}