feat: 支持请求失败弹窗提示

This commit is contained in:
Anyon 2026-08-19 10:18:52 +08:00
parent 18382f0065
commit bf5ccf5a97

View File

@ -100,19 +100,29 @@ $(function () {
}; };
/*! 获取加载回调 */ /*! 获取加载回调 */
this.onConfirm.getLoadCallable = function (tabldId, callable) { this.onConfirm.getLoadCallable = function (tabldId, callable, options) {
typeof callable === 'function' && callable(); typeof callable === 'function' && callable();
return tabldId ? function (ret, time) { options = options || {};
let errorAlert = options.errorAlert === true || String(options.errorAlert) === 'true';
if (!tabldId && !errorAlert) return false;
return function (ret, time) {
// 单独处理 javascript: 返回内容处理 // 单独处理 javascript: 返回内容处理
if (typeof ret.data === 'string' && ret.data.indexOf('javascript:') === 0) { if (typeof ret.data === 'string' && ret.data.indexOf('javascript:') === 0) {
$.msg.goto(ret.data) $.msg.goto(ret.data)
} }
if (ret.code < 1) return true; if (parseInt(ret.code) < 1) {
if (errorAlert) {
$.msg.alert(ret.info || ret.msg || '操作失败');
return false;
}
return true;
}
if (!tabldId) return true;
time === 'false' ? $.layTable.reload(tabldId) : $.msg.success(ret.info, time, function () { time === 'false' ? $.layTable.reload(tabldId) : $.msg.success(ret.info, time, function () {
$.layTable.reload(tabldId); $.layTable.reload(tabldId);
}); });
return false; return false;
} : false; };
}; };
/*! 读取 data-value & data-rule 并应用到 callable */ /*! 读取 data-value & data-rule 并应用到 callable */
@ -877,7 +887,7 @@ $(function () {
/*! 注册 data-load 事件行为 */ /*! 注册 data-load 事件行为 */
$.base.onEvent('click', '[data-load]', function () { $.base.onEvent('click', '[data-load]', function () {
$.base.applyRuleValue(this, {}, function (data, elem, dset) { $.base.applyRuleValue(this, {}, function (data, elem, dset) {
$.form.load(dset.load, data, 'get', $.base.onConfirm.getLoadCallable(dset.tableId), true, dset.tips, dset.time); $.form.load(dset.load, data, 'get', $.base.onConfirm.getLoadCallable(dset.tableId, null, {errorAlert: dset.errorAlert}), true, dset.tips, dset.time);
}); });
}); });
@ -948,7 +958,7 @@ $(function () {
$.base.applyRuleValue(this, {}, function (data, elem, dset) { $.base.applyRuleValue(this, {}, function (data, elem, dset) {
Object.assign(data, {'_token_': dset.token || dset.csrf || '--'}) Object.assign(data, {'_token_': dset.token || dset.csrf || '--'})
let load = dset.loading !== 'false', tips = typeof load === 'string' ? load : undefined; let load = dset.loading !== 'false', tips = typeof load === 'string' ? load : undefined;
$.form.load(dset.action, data, dset.method || 'post', $.base.onConfirm.getLoadCallable(dset.tableId), load, tips, dset.time) $.form.load(dset.action, data, dset.method || 'post', $.base.onConfirm.getLoadCallable(dset.tableId, null, {errorAlert: dset.errorAlert}), load, tips, dset.time)
}); });
}); });