1
0
Files
helper/public/static/mobile/js/cjango.js
2023-11-16 13:41:09 +08:00

249 lines
7.6 KiB
JavaScript

/*使用js跳转*/
$('[data-href]').on('click', function(event) {
event.preventDefault();
location.href = $(this).data('href');
});
// ajax GET 请求
$('.ajax-get').on('click', function(event) {
event.preventDefault();
var target;
var $this = $(this);
var $callback = $this.attr('callback');
var $tips = $this.attr('tip') || '确认要执行该操作吗?';
if ( $this.hasClass('confirm') ) {
if(!confirm($tips)){
return false;
}
}
if ((target = $this.data('href')) || (target = $this.attr('href')) || (target = $this.attr('url'))) {
$.get(target, function(data) {
if (data.code == 1) {
updateAlert(data.msg, 'success');
setTimeout(function() {
if ($this.hasClass('no-refresh')) {
if ($callback != '') {
eval($callback);
}
} else if (data.url) {
location.href = data.url;
} else {
location.reload();
}
}, 1500);
} else {
updateAlert(data.msg, 'warning');
setTimeout(function() {
if (data.url) {
location.href = data.url;
} else {
}
}, 1500);
}
});
}
return false;
});
// ajax POST 请求
$(".ajax-post").on('click', function(event) {
if ($(this).hasClass('disabled') || $(this).attr('disabled')) {
return false;
};
event.preventDefault();
var $this = $(this);
var $form = $('form');
var $action = $form.attr("action");
var $tips = $this.attr('tip') || '确认要执行该操作吗?';
if ($this.hasClass('confirm')) {
if(!confirm($tips)){
return false;
}
}
$this.attr('disabled', 'disabled');
var query = $form.serialize();
$.post($action, query, function(data) {
if (data.code == 1) {
updateAlert(data.msg, true);
setTimeout(function(){
if (data.url) {
location.href = data.url;
} else if ($this.hasClass('no-refresh')) {
$this.removeAttr('disabled');
} else {
location.reload();
}
}, 1500);
} else {
updateAlert(data.msg, false);
setTimeout(function() {
if (data.url) {
location.href = data.url;
}
}, 1500);
$this.removeAttr('disabled');
}
});
});
/*顶部消息提示*/
window.updateAlert = function(text, type) {
var types = type ? 'success' : 'warning';
var myDisplay = new $.Display({
display: 'messager',
placement:'top',
content: text,
autoHide:2000,
type: types,
displayAuto:true,
});
}
$(".nextpage").on('click',function() {
var $this = $(this);
if ($this.data('end')==1) {
updateAlert('已经到最后一页', false);
return false;
}
$this.removeClass('primary');
$this.addClass('loading');
$this.addClass('loading-light');
$this.addClass('gray');
var page = $this.data('page');
var content = $this.data('content');
var href = $this.data('posturl');
var query = $this.data('qkey') + "&page=" + (page + 1);
$.get(href, query, function(data) {
if (data.code==1) {
$("#"+content).append(data.msg);
$this.data('page',(page+1));
$this.removeClass('loading');
$this.removeClass('loading-light');
$this.removeClass('gray');
$this.addClass('primary');
if ($this.hasClass('refjs')) {
refjs();
}
} else {
updateAlert(data.msg,false);
$this.data('end',1);
$this.removeClass('loading');
$this.removeClass('loading-light');
$this.text('已经到最后一页');
}
});
});
function refjs()
{
$('[data-href]').on('click', function(event) {
event.preventDefault();
if ($(this).hasClass('ajax-get') || $(this).hasClass('ajax-post')) {
return;
}
location.href = $(this).data('href');
});
$('.ajax-get').on('click', function(event){
event.preventDefault();
var target;
var $this = $(this);
var $callback = $this.attr('callback');
var $tips = $this.attr('tip') || '确认要执行该操作吗?';
if ( $this.hasClass('confirm') ) {
if(!confirm($tips)){
return false;
}
}
if ((target = $this.data('href')) || (target = $this.attr('href')) || (target = $this.attr('url'))) {
$.get(target, function(data) {
if (data.code == 1) {
upAlert(data.msg, 'success');
setTimeout(function() {
if ($this.hasClass('no-refresh')) {
if ($callback != '') {
eval($callback);
}
} else if (data.locate) {
location.href = data.locate;
} else {
location.reload();
}
}, 1500);
} else {
upAlert(data.msg, 'warning');
setTimeout(function() {
if (data.locate) {
location.href = data.locate;
} else {
}
}, 1500);
}
});
}
return false;
});
$(".ajax-post").on('click', function(event) {
if ($(this).hasClass('disabled') || $(this).attr('disabled')) {
return false;
};
event.preventDefault();
var $this = $(this);
var $form = $this.parents('form');
var $action = $form.attr("action");
var $tips = $this.attr('tip') || '确认要执行该操作吗?';
if ($this.hasClass('confirm')) {
if(!confirm($tips)){
return false;
}
}
$this.attr('disabled', 'disabled');
var query = $form.serialize();
$.post($action, query, function(data) {
if (data.code == 1) {
upAlert(data.msg, true);
setTimeout(function(){
if (data.url) {
location.href = data.url;
} else if ($this.hasClass('no-refresh')) {
$this.removeAttr('disabled');
} else {
location.reload();
}
}, 1500);
} else {
upAlert(data.msg, false);
setTimeout(function() {
if (data.url) {
location.href = data.url;
}
}, 1500);
$this.removeAttr('disabled');
}
});
});
}
$(".Qrcode").on('click', function(event) {
// $('.Qrcode').tap(function() {
var img = $(this).data('img');
var html = '<img src="'+ img +'">';
if (img=='') {
html='他还没有上传微信二维码';
};
layer.open({
type: 1,
title: false,
closeBtn: 0,
area: '516px',
skin: 'layui-layer-nobg', //没有背景色
shadeClose: true,
content:html
});
});