zoomla
Version:
16年专业研发|中文alexa排名第一的CMS品牌-基于dotNET core、功能强大,集成站群、微信开发、小程序与ERP及OA办公系统,支持国际语言和多民族语言,世界五百强与大型门户专用高端网站内核CMS系统
31 lines • 1.32 kB
JavaScript
var APIResult = {};
APIResult.Success = 1;
APIResult.Failed = -1;
APIResult.getModel = function (str) {
var failedMod = { "retcode": APIResult.Failed, "retmsg": "", "result": "{}", "addon": "", "action": "" };
if (!str || str == "" || str == "[]") { return failedMod; }
try {
var model = null;
if (typeof str == "string") { model = JSON.parse(str); }
else { model = str; }
if (model.result && model.result != "") {
if (model.result == "True") { model.result = true; }
else if (model.result == "False") { model.result = false; }
else if (model.result.indexOf("{") == 0 || model.result.indexOf("[") == 0) { model.result = JSON.parse(model.result); }
}
return model;
} catch (ex) { failedMod.retmsg = "Parse Error:" + str; return failedMod; }
}
//返回的结果是否成功
APIResult.isok = function (model) {
if (model && model.retcode == APIResult.Success) { return true; }
}
//返回数据,成功回调,失败回调
APIResult.ifok = function (data, ok,err) {
var model = APIResult.getModel(data);
if (APIResult.isok(model)) { if (ok) { ok(model.result); } }
else {
if (err) { err(data); }
console.log(model.action + " failed:", model.retmsg, data);
}
}