gocron/public/resource/javascript/main.js

79 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-04-07 09:26:46 +00:00
/**
* Created by ouqiang on 2017/4/1.
*/
function Util() {
var util = {};
2017-04-20 01:36:42 +00:00
var SUCCESS = 0; // 操作成功
var FAILURE_MESSAGE = '操作失败';
util.ajaxSuccess = function(response, callback) {
if (response.code === undefined) {
swal(FAILURE_MESSAGE, '服务端返回值无法解析', 'error');
return;
}
if (response.code != SUCCESS) {
swal(FAILURE_MESSAGE, response.message ,'error');
return;
}
2017-04-21 05:36:45 +00:00
if (callback !== undefined) {
callback(response.code, response.message, response.data);
}
2017-04-20 01:36:42 +00:00
};
util.ajaxFailure = function() {
// todo 错误处理
swal(FAILURE_MESSAGE, '未知错误', 'error');
};
util.get = function(url, callback) {
var SUCCESS = 0; // 操作成功
2017-04-07 09:26:46 +00:00
var FAILURE_MESSAGE = '操作失败';
2017-04-20 01:36:42 +00:00
$.get(
url,
function(response) {
util.ajaxSuccess(response, callback);
},
'json'
).error(util.ajaxFailure);
};
util.post = function(url, params, callback) {
2017-04-07 09:26:46 +00:00
$.post(
url,
params,
function(response) {
2017-04-20 01:36:42 +00:00
util.ajaxSuccess(response, callback);
2017-04-07 09:26:46 +00:00
},
'json'
2017-04-20 01:36:42 +00:00
).error(util.ajaxFailure);
2017-04-07 09:26:46 +00:00
};
2017-04-13 09:35:59 +00:00
util.confirm = function(message, callback) {
swal({
title: '操作确认',
text: message,
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
confirmButtonText: '删除',
cancelButtonColor: '#d33',
cancelButtonText: "取消",
closeOnConfirm: false,
closeOnCancel: true
},
function(isConfirm) {
if (!isConfirm) {
return;
}
callback();
}
);
};
util.removeConfirm = function(url) {
util.confirm("确定要删除吗?", function () {
util.post(url, {}, function () {
location.reload();
});
});
};
2017-04-07 09:26:46 +00:00
return util;
2017-04-13 09:35:59 +00:00
}
var util = new Util();