调整新窗口打开

This commit is contained in:
2021-11-26 15:37:59 +08:00
parent f9f840b56b
commit a84417c167
13 changed files with 90 additions and 83 deletions

View File

@@ -1,32 +1,34 @@
$('[data-href]').on('click', function(event) {
$('[data-href]').on('click', function (event) {
event.preventDefault();
if ($(this).hasClass('ajax-get') || $(this).hasClass('ajax-post')) {
return;
}
location.href = $(this).data('href');
window.open($(this).data('href'));
// location.href = $(this).data('href');
});
// ajax GET 请求
$('body').on('click', '.ajax-get', function(event) {
$('body').on('click', '.ajax-get', function (event) {
event.preventDefault();
if ($(this).hasClass('disabled') || $(this).attr('disabled')) {
return false;
};
var $this = $(this);
var $tips = $this.attr('tip') || '确认要执行该操作吗?';
}
;
var $this = $(this);
var $tips = $this.attr('tip') || '确认要执行该操作吗?';
var $target = $this.data('href') || $this.attr('href') || $this.attr('url') || $this.data('url');
if ($this.hasClass('confirm')) {
if(!confirm($tips)){
if (!confirm($tips)) {
return false;
}
}
$.ajax({
type: "GET",
url: $target,
success: function(data){
if(data.code==1){
updateAlert(data.msg, 'success', function() {
success: function (data) {
if (data.code == 1) {
updateAlert(data.msg, 'success', function () {
if ($this.hasClass('no-refresh')) {
} else if (data.url == null) {
location.reload();
@@ -40,7 +42,7 @@ $('body').on('click', '.ajax-get', function(event) {
updateAlert(data.msg);
}
},
error: function(error){
error: function (error) {
if (error.responseJSON.message) {
updateAlert(error.responseJSON.message, 'warning');
} else {
@@ -51,18 +53,19 @@ $('body').on('click', '.ajax-get', function(event) {
});
// ajax POST 请求
$('body').on('click', '.ajax-post', function(event) {
$('body').on('click', '.ajax-post', function (event) {
if ($(this).hasClass('disabled') || $(this).attr('disabled')) {
return false;
};
}
;
event.preventDefault();
var $this = $(this);
var $form = $this.parents('form');
var $tips = $this.attr('tip') || '确认要执行该操作吗?';
var $this = $(this);
var $form = $this.parents('form');
var $tips = $this.attr('tip') || '确认要执行该操作吗?';
var $action = $form.attr("action");
if ($this.hasClass('confirm')) {
if(!confirm($tips)){
if (!confirm($tips)) {
return false;
}
}
@@ -73,12 +76,12 @@ $('body').on('click', '.ajax-post', function(event) {
type: "POST",
url: $action,
data: query,
success: function(data) {
success: function (data) {
if (data.code == 0) {
updateAlert(data.msg);
$this.removeAttr('disabled');
} else {
updateAlert(data.msg, 'success', function() {
updateAlert(data.msg, 'success', function () {
if (data.url) {
location.href = data.url;
} else if (data.url == null) {
@@ -89,11 +92,11 @@ $('body').on('click', '.ajax-post', function(event) {
});
}
},
error: function(error) {
error: function (error) {
$this.removeAttr('disabled');
if (error.responseJSON.errors) {
var err = '';
$.each(error.responseJSON.errors, function(i, n) {
$.each(error.responseJSON.errors, function (i, n) {
// err += n + "\r\n";
updateAlert(n[0], 'warning');
return false;
@@ -108,32 +111,33 @@ $('body').on('click', '.ajax-post', function(event) {
});
});
$('body').on('click', '.ajax-post-confirm', function(event) {
$('body').on('click', '.ajax-post-confirm', function (event) {
if ($(this).hasClass('disabled') || $(this).attr('disabled')) {
return false;
};
}
;
event.preventDefault();
var $this = $(this);
var $form = $this.parents('form');
var $this = $(this);
var $form = $this.parents('form');
var $action = $form.attr("action");
var $tips = $this.attr('tip') || '确认要执行该操作吗?';
var $tips = $this.attr('tip') || '确认要执行该操作吗?';
var query = $form.serialize();
$this.attr('disabled', 'disabled');
layer.open({
content: $tips
,btn: ['确定', '取消']
,yes: function(index){
, btn: ['确定', '取消']
, yes: function (index) {
$.ajax({
type: "POST",
url: $action,
data: query,
success: function(data) {
success: function (data) {
if (data.code == 0) {
updateAlert(data.msg);
$this.removeAttr('disabled');
} else {
updateAlert(data.msg, data.error, function() {
updateAlert(data.msg, data.error, function () {
if (data.url) {
location.href = data.url;
} else if (data.url == null) {
@@ -144,11 +148,11 @@ $('body').on('click', '.ajax-post-confirm', function(event) {
});
}
},
error: function(error) {
error: function (error) {
$this.removeAttr('disabled');
if (error.responseJSON.errors) {
var err = '';
$.each(error.responseJSON.errors, function(i, n) {
$.each(error.responseJSON.errors, function (i, n) {
// err += n + "\r\n";
updateAlert(n[0], 'warning');
return false;
@@ -166,7 +170,7 @@ $('body').on('click', '.ajax-post-confirm', function(event) {
});
});
window.updateAlert = function(text, type, callback) {
window.updateAlert = function (text, type, callback) {
if (typeof type != 'string') {
if (type) {
type = "success";
@@ -181,7 +185,7 @@ window.updateAlert = function(text, type, callback) {
showConfirmButton: false
});
if (typeof callback == "function") {
setTimeout(function() {
setTimeout(function () {
callback();
}, 1500)
}